fix:add: show green prompts properly instead of ANSI codes [#2410]
This commit is contained in:
parent
cd904e80d5
commit
fc93a4c644
@ -763,7 +763,7 @@ useColorOnStderrUnsafe = unsafePerformIO useColorOnStderr
|
|||||||
|
|
||||||
-- | Detect whether ANSI should be used on stdout using useColorOnStdoutUnsafe,
|
-- | Detect whether ANSI should be used on stdout using useColorOnStdoutUnsafe,
|
||||||
-- and if so prepend and append the given SGR codes to a string.
|
-- and if so prepend and append the given SGR codes to a string.
|
||||||
-- Currently used in a few places (the commands list, the demo command, the recentassertions error message);
|
-- Currently used in a few places (the commands list, the recentassertions error message, add, demo);
|
||||||
-- see useColorOnStdoutUnsafe's limitations.
|
-- see useColorOnStdoutUnsafe's limitations.
|
||||||
ansiWrapUnsafe :: SGRString -> SGRString -> String -> String
|
ansiWrapUnsafe :: SGRString -> SGRString -> String -> String
|
||||||
ansiWrapUnsafe pre post s = if useColorOnStdoutUnsafe then pre<>s<>post else s
|
ansiWrapUnsafe pre post s = if useColorOnStdoutUnsafe then pre<>s<>post else s
|
||||||
|
|||||||
@ -264,7 +264,7 @@ confirmedTransactionWizard prevInput es@EntryState{..} stack@(currentStage : _)
|
|||||||
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
|
||||||
@ -272,6 +272,11 @@ confirmedTransactionWizard prevInput es@EntryState{..} stack@(currentStage : _)
|
|||||||
where
|
where
|
||||||
replaceNthOrAppend n newElem xs = take n xs ++ [newElem] ++ drop (n + 1) xs
|
replaceNthOrAppend n newElem xs = take n xs ++ [newElem] ++ drop (n + 1) xs
|
||||||
|
|
||||||
|
-- | 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
|
||||||
|
|
||||||
dateAndCodeWizard PrevInput{..} EntryState{..} = do
|
dateAndCodeWizard PrevInput{..} EntryState{..} = do
|
||||||
let def = headDef (T.unpack $ showDate esDefDate) esArgs
|
let def = headDef (T.unpack $ showDate esDefDate) esArgs
|
||||||
retryMsg "A valid hledger smart date is required. Eg: 2022-08-30, 8/30, 30, yesterday." $
|
retryMsg "A valid hledger smart date is required. Eg: 2022-08-30, 8/30, 30, yesterday." $
|
||||||
@ -280,7 +285,7 @@ dateAndCodeWizard PrevInput{..} EntryState{..} = 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
|
||||||
@ -299,7 +304,7 @@ descriptionAndCommentWizard PrevInput{..} EntryState{..} = do
|
|||||||
let def = headDef "" esArgs
|
let def = headDef "" esArgs
|
||||||
s <- withCompletion (descriptionCompleter esJournal def) $
|
s <- withCompletion (descriptionCompleter esJournal 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
|
||||||
@ -322,7 +327,7 @@ accountWizard PrevInput{..} EntryState{..} = do
|
|||||||
parser (parseAccountOrDotOrNull def canfinish) $
|
parser (parseAccountOrDotOrNull def canfinish) $
|
||||||
withCompletion (accountCompleter esJournal def) $
|
withCompletion (accountCompleter esJournal def) $
|
||||||
defaultTo' def $ -- nonEmpty $
|
defaultTo' def $ -- nonEmpty $
|
||||||
linePrewritten (green' $ printf "Account %d%s%s: " pnum (endmsg::String) (showDefault def)) (fromMaybe "" $ prevAccount `atMay` length esPostings) ""
|
linePrewritten' (green' $ printf "Account %d%s%s: " pnum (endmsg::String) (showDefault def)) (fromMaybe "" $ prevAccount `atMay` length esPostings) ""
|
||||||
where
|
where
|
||||||
canfinish = not (null esPostings) && postingsBalanced esPostings
|
canfinish = not (null esPostings) && postingsBalanced esPostings
|
||||||
parseAccountOrDotOrNull :: String -> Bool -> String -> Maybe (Maybe String)
|
parseAccountOrDotOrNull :: String -> Bool -> String -> Maybe (Maybe String)
|
||||||
@ -362,7 +367,7 @@ amountAndCommentWizard previnput@PrevInput{..} entrystate@EntryState{..} = 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 esPostings) ""
|
linePrewritten' (green' $ printf "Amount %d%s: " pnum (showDefault def)) (fromMaybe "" $ prevAmountAndCmnt `atMay` length esPostings) ""
|
||||||
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 ->
|
||||||
|
|||||||
@ -7026,11 +7026,8 @@ Some known issues and limitations:
|
|||||||
A system locale with a suitable text encoding must be configured to work with non-ascii data.
|
A system locale with a suitable text encoding must be configured to work with non-ascii data.
|
||||||
(See Text encoding, Troubleshooting.)
|
(See Text encoding, Troubleshooting.)
|
||||||
|
|
||||||
On Microsoft Windows, depending whether you are running in a CMD window or a Cygwin/MSYS/Mintty window
|
On Microsoft Windows, depending what kind of terminal window you use,
|
||||||
and how you installed hledger,
|
non-ascii characters, ANSI text formatting, and/or the add command's TAB key for completion, may not be supported.
|
||||||
non-ascii characters and colours may not be supported,
|
|
||||||
and the tab key may not be supported by `hledger add`.
|
|
||||||
(Running in a WSL window should resolve these.)
|
|
||||||
|
|
||||||
When processing large data files, hledger uses more memory than Ledger.
|
When processing large data files, hledger uses more memory than Ledger.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user