diff --git a/hledger-ui/Hledger/UI/Editor.hs b/hledger-ui/Hledger/UI/Editor.hs index 188ea7e825c..b4bf40c422f 100644 --- a/hledger-ui/Hledger/UI/Editor.hs +++ b/hledger-ui/Hledger/UI/Editor.hs @@ -16,6 +16,7 @@ import Safe import System.Environment import System.Exit import System.FilePath +import System.Info (os) import System.Process import Hledger @@ -123,13 +124,17 @@ editFileAtPositionCommand mpos f = do return $ unwords $ cmd:args -- | Get the user's preferred edit command. This is the value of the --- $HLEDGER_UI_EDITOR environment variable, or of $EDITOR, or a --- default ("emacsclient -a '' -nw", which starts/connects to an emacs --- daemon in terminal mode). +-- $HLEDGER_UI_EDITOR environment variable, or of $EDITOR, or an OS-specific default. +-- +-- For non-windows machines that would be "emacsclient -a '' -nw", +-- which starts/connects to an emacs daemon in terminal mode. +-- +-- For windows the default is a plain "notepad.exe" getEditCommand :: IO String getEditCommand = do hledger_ui_editor_env <- lookupEnv "HLEDGER_UI_EDITOR" editor_env <- lookupEnv "EDITOR" - let Just cmd = hledger_ui_editor_env <|> editor_env <|> Just "emacsclient -a '' -nw" + let defaultEditor = Just $ if os == "mingw32" then "notepad.exe" else "emacsclient -a '' -nw" + let Just cmd = hledger_ui_editor_env <|> editor_env <|> defaultEditor return cmd diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index 8dd9d7f369f..628815cc6f2 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -20,7 +20,8 @@ import Data.List (find) import Data.List.Extra (nubSort) import Data.Maybe (fromMaybe) import qualified Data.Text as T -import Graphics.Vty (mkVty, Mode (Mouse), Vty (outputIface), Output (setMode)) +import Graphics.Vty (Mode (Mouse), Vty (outputIface), Output (setMode)) +import Graphics.Vty.CrossPlatform (mkVty) import Lens.Micro ((^.)) import System.Directory (canonicalizePath) import System.Environment (withProgName) diff --git a/hledger-ui/hledger-ui.cabal b/hledger-ui/hledger-ui.cabal index 30b46e597fd..7bf5c958b98 100644 --- a/hledger-ui/hledger-ui.cabal +++ b/hledger-ui/hledger-ui.cabal @@ -73,7 +73,7 @@ library ansi-terminal >=0.9 , async , base >=4.14 && <4.19 - , brick >=1.5 && <2 + , brick >=2.1.1 && <2.2 , cmdargs >=0.8 , containers >=0.5.9 , data-default @@ -95,14 +95,16 @@ library , text-zipper >=0.4 , time >=1.5 , transformers - , unix , vector - , vty >=5.15 && <6 + , vty ==6.1.* + , vty-crossplatform >=0.4.0.0 && <0.5.0.0 default-language: Haskell2010 if os(windows) - buildable: False + build-depends: + vty-windows >=0.2.0.1 && <0.3.0.0 else - buildable: True + build-depends: + unix executable hledger-ui main-is: hledger-ui.hs @@ -116,9 +118,5 @@ executable hledger-ui base >=4.14 && <4.19 , hledger-ui default-language: Haskell2010 - if os(windows) - buildable: False - else - buildable: True if flag(threaded) ghc-options: -threaded diff --git a/hledger-ui/package.yaml b/hledger-ui/package.yaml index c2243ead9dc..0ba59b685e7 100644 --- a/hledger-ui/package.yaml +++ b/hledger-ui/package.yaml @@ -51,7 +51,6 @@ ghc-options: dependencies: - base >=4.14 && <4.19 -when: # curses is required to build terminfo for vty for hledger-ui. # On POSIX systems it might be not present. # On windows it's very likely not present, but possibly it could be. @@ -61,12 +60,10 @@ when: # curses # default: True # description: - # For now, just don't build hledger-ui on windows - - condition: os(windows) - then: - buildable: false - else: - buildable: true + # + # note on windows: the vty-windows (and hence hledger-ui) will reliably work only on the newer backends + # like Windows Terminal. + # mintty-based backends (default for cygwin/gitbash/msys2) are not supported (yet) library: source-dirs: . @@ -101,10 +98,16 @@ library: - time >=1.5 - transformers - vector - # not installable on windows, cf buildable flag below - - brick >=1.5 && <2 - - vty >=5.15 && <6 - - unix + - brick >=2.1.1 && <2.2 + - vty >=6.1 && <6.2 + - vty-crossplatform >= 0.4.0.0 && < 0.5.0.0 + when: + - condition: os(windows) + then: + dependencies: vty-windows >= 0.2.0.1 && < 0.3.0.0 + else: + dependencies: unix + executables: hledger-ui: diff --git a/stack.yaml b/stack.yaml index 2058862ebd2..54d645999dd 100644 --- a/stack.yaml +++ b/stack.yaml @@ -31,3 +31,10 @@ nix: # # "$targets": -Werror # # "$everything": -O2 # # some-package: -DSOME_CPP_FLAG +extra-deps: + - vty-windows-0.2.0.1 + - vty-crossplatform-0.4.0.0 + - brick-2.1.1 + - vty-6.1 + - vty-unix-0.2.0.0 + diff --git a/stack9.4.yaml b/stack9.4.yaml index 63f490401eb..b6b1888cb6d 100644 --- a/stack9.4.yaml +++ b/stack9.4.yaml @@ -8,8 +8,12 @@ packages: - hledger-ui - hledger-web -# extra-deps: - +extra-deps: + - vty-windows-0.2.0.1 + - vty-crossplatform-0.4.0.0 + - brick-2.1.1 + - vty-6.1 + - vty-unix-0.2.0.0 nix: pure: false packages: [perl gmp ncurses zlib]