fix: add, ui: better fix for add's [#2410], also fixes ui's [#2512]

By using newer haskeline fixing https://github.com/haskell/haskeline/issues/130.
This commit is contained in:
Simon Michael 2025-12-26 17:03:00 -10:00
parent 91d019741e
commit 1a0a81d9e7
7 changed files with 18 additions and 11 deletions

View File

@ -284,7 +284,7 @@ transactionWizard previnput state@AddState{..} stack@(currentStage : _) = case c
retryMsg "Please enter y or n." $ retryMsg "Please enter y or n." $
parser ((fmap (\c -> if c == '<' then Nothing else Just c)) . headMay . map toLower . strip) $ parser ((fmap (\c -> if c == '<' then Nothing else Just c)) . headMay . map toLower . strip) $
defaultTo' def $ nonEmpty $ defaultTo' def $ nonEmpty $
line' $ green' $ printf "Save this transaction to the journal ?%s: " (showDefault def) line $ green' $ printf "Save this transaction to the journal ?%s: " (showDefault def)
case y of case y of
Just 'y' -> return t Just 'y' -> return t
Just _ -> throw RestartTransactionException Just _ -> throw RestartTransactionException
@ -303,7 +303,7 @@ dateWizard PrevInput{..} AddState{..} = do
defaultTo' def $ nonEmpty $ defaultTo' def $ nonEmpty $
maybeExit $ maybeExit $
-- maybeShowHelp $ -- maybeShowHelp $
linePrewritten' (green' $ printf "Date%s: " (showDefault def)) (fromMaybe "" prevDateAndCode) "" linePrewritten (green' $ printf "Date%s: " (showDefault def)) (fromMaybe "" prevDateAndCode) ""
where where
parseSmartDateAndCode refdate s = if s == "<" then return Nothing else either (const Nothing) (\(d,c) -> return $ Just (fixSmartDate refdate d, c)) edc parseSmartDateAndCode refdate s = if s == "<" then return Nothing else either (const Nothing) (\(d,c) -> return $ Just (fixSmartDate refdate d, c)) edc
where where
@ -325,7 +325,7 @@ descriptionWizard PrevInput{..} AddState{..} = do
let def = headDef "" asArgs let def = headDef "" asArgs
s <- withCompletion (descriptionCompleter asJournal def) $ s <- withCompletion (descriptionCompleter asJournal def) $
defaultTo' def $ nonEmpty $ defaultTo' def $ nonEmpty $
linePrewritten' (green' $ printf "Description%s: " (showDefault def)) (fromMaybe "" prevDescAndCmnt) "" linePrewritten (green' $ printf "Description%s: " (showDefault def)) (fromMaybe "" prevDescAndCmnt) ""
if s == "<" if s == "<"
then return Nothing then return Nothing
else do else do
@ -348,7 +348,7 @@ accountWizard PrevInput{..} AddState{..} = do
parser (parseAccountOrDotOrNull def canfinish) $ parser (parseAccountOrDotOrNull def canfinish) $
withCompletion (accountCompleter asJournal def) $ withCompletion (accountCompleter asJournal def) $
defaultTo' def $ -- nonEmpty $ defaultTo' def $ -- nonEmpty $
linePrewritten' (green' $ printf "Account %d%s%s: " pnum (endmsg::String) (showDefault def)) (fromMaybe "" $ prevAccount `atMay` length asPostings) "" linePrewritten (green' $ printf "Account %d%s%s: " pnum (endmsg::String) (showDefault def)) (fromMaybe "" $ prevAccount `atMay` length asPostings) ""
where where
canfinish = not (null asPostings) && postingsAreBalanced asPostings canfinish = not (null asPostings) && postingsAreBalanced asPostings
parseAccountOrDotOrNull :: String -> Bool -> String -> Maybe (Maybe String) parseAccountOrDotOrNull :: String -> Bool -> String -> Maybe (Maybe String)
@ -388,7 +388,7 @@ amountWizard previnput@PrevInput{..} state@AddState{..} = do
withCompletion (amountCompleter def) $ withCompletion (amountCompleter def) $
defaultTo' def $ defaultTo' def $
nonEmpty $ nonEmpty $
linePrewritten' (green' $ printf "Amount %d%s: " pnum (showDefault def)) (fromMaybe "" $ prevAmountAndCmnt `atMay` length asPostings) "" linePrewritten (green' $ printf "Amount %d%s: " pnum (showDefault def)) (fromMaybe "" $ prevAmountAndCmnt `atMay` length asPostings) ""
where where
-- Custom parser that combines with Wizard to use IO via outputLn -- Custom parser that combines with Wizard to use IO via outputLn
parser' f a = a >>= \input -> parser' f a = a >>= \input ->
@ -475,11 +475,6 @@ maybeExit = parser (\s -> if s == "." then throw UnexpectedEOF else Just s)
-- maybeShowHelp wizard = maybe (liftIO showHelp >> wizard) return $ -- maybeShowHelp wizard = maybe (liftIO showHelp >> wizard) return $
-- parser (\s -> if s=="?" then Nothing else Just s) wizard -- parser (\s -> if s=="?" then Nothing else Just s) wizard
-- | A workaround we seem to need for #2410 right now: wizards' input-reading functions disrupt ANSI codes
-- somehow, so these variants first print the ANSI coded prompt as ordinary output, then do the input with no prompt.
line' prompt = output prompt >> line ""
linePrewritten' prompt beforetxt aftertxt = output prompt >> linePrewritten "" beforetxt aftertxt
defaultTo' = flip defaultTo defaultTo' = flip defaultTo
withCompletion f = withSettings (setComplete f defaultSettings) withCompletion f = withSettings (setComplete f defaultSettings)

View File

@ -114,7 +114,7 @@ dependencies:
- extra >=1.7.11 - extra >=1.7.11
- filepath - filepath
- githash >=0.1.6.2 - githash >=0.1.6.2
- haskeline >=0.6 - haskeline >=0.8.4.0
- http-client - http-client
- http-types - http-types
- megaparsec >=7.0.0 && <9.8 - megaparsec >=7.0.0 && <9.8

View File

@ -15,6 +15,8 @@ notify-if-ghc-untested: false
notify-if-cabal-untested: false notify-if-cabal-untested: false
extra-deps: extra-deps:
# for #2410, #2512:
- haskeline-0.8.4.1
# currently out of stackage: # currently out of stackage:
- yesod-static-1.6.1.0 - yesod-static-1.6.1.0
- yesod-test-1.6.19 - yesod-test-1.6.19

View File

@ -10,6 +10,10 @@ packages:
- hledger-ui - hledger-ui
- hledger-web - hledger-web
extra-deps:
# for #2410, #2512:
- haskeline-0.8.4.1
nix: nix:
pure: false pure: false
packages: [perl gmp ncurses zlib] packages: [perl gmp ncurses zlib]

View File

@ -14,6 +14,8 @@ packages:
- hledger-web - hledger-web
extra-deps: extra-deps:
# for #2410, #2512:
- haskeline-0.8.4.1
# currently out of stackage: # currently out of stackage:
- yesod-static-1.6.1.0 - yesod-static-1.6.1.0
- yesod-test-1.6.19 - yesod-test-1.6.19

View File

@ -12,6 +12,8 @@ extra-deps:
- encoding-0.10 - encoding-0.10
- hashtables-1.4.2 - hashtables-1.4.2
- vty-windows-0.2.0.1 - vty-windows-0.2.0.1
# for #2410, #2512:
- haskeline-0.8.4.1
nix: nix:
pure: false pure: false

View File

@ -11,6 +11,8 @@ packages:
extra-deps: extra-deps:
- encoding-0.10 - encoding-0.10
- hashtables-1.4.2 - hashtables-1.4.2
# for #2410, #2512:
- haskeline-0.8.4.1
nix: nix:
pure: false pure: false