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,
|
||||
-- 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.
|
||||
ansiWrapUnsafe :: SGRString -> SGRString -> String -> String
|
||||
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." $
|
||||
parser ((fmap (\c -> if c == '<' then Nothing else Just c)) . headMay . map toLower . strip) $
|
||||
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
|
||||
Just 'y' -> return t
|
||||
Just _ -> throw RestartTransactionException
|
||||
@ -272,6 +272,11 @@ confirmedTransactionWizard prevInput es@EntryState{..} stack@(currentStage : _)
|
||||
where
|
||||
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
|
||||
let def = headDef (T.unpack $ showDate esDefDate) esArgs
|
||||
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 $
|
||||
maybeExit $
|
||||
-- maybeShowHelp $
|
||||
linePrewritten (green' $ printf "Date%s: " (showDefault def)) (fromMaybe "" prevDateAndCode) ""
|
||||
linePrewritten' (green' $ printf "Date%s: " (showDefault def)) (fromMaybe "" prevDateAndCode) ""
|
||||
where
|
||||
parseSmartDateAndCode refdate s = if s == "<" then return Nothing else either (const Nothing) (\(d,c) -> return $ Just (fixSmartDate refdate d, c)) edc
|
||||
where
|
||||
@ -299,7 +304,7 @@ descriptionAndCommentWizard PrevInput{..} EntryState{..} = do
|
||||
let def = headDef "" esArgs
|
||||
s <- withCompletion (descriptionCompleter esJournal def) $
|
||||
defaultTo' def $ nonEmpty $
|
||||
linePrewritten (green' $ printf "Description%s: " (showDefault def)) (fromMaybe "" prevDescAndCmnt) ""
|
||||
linePrewritten' (green' $ printf "Description%s: " (showDefault def)) (fromMaybe "" prevDescAndCmnt) ""
|
||||
if s == "<"
|
||||
then return Nothing
|
||||
else do
|
||||
@ -322,7 +327,7 @@ accountWizard PrevInput{..} EntryState{..} = do
|
||||
parser (parseAccountOrDotOrNull def canfinish) $
|
||||
withCompletion (accountCompleter esJournal def) $
|
||||
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
|
||||
canfinish = not (null esPostings) && postingsBalanced esPostings
|
||||
parseAccountOrDotOrNull :: String -> Bool -> String -> Maybe (Maybe String)
|
||||
@ -362,7 +367,7 @@ amountAndCommentWizard previnput@PrevInput{..} entrystate@EntryState{..} = do
|
||||
withCompletion (amountCompleter def) $
|
||||
defaultTo' def $
|
||||
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
|
||||
-- Custom parser that combines with Wizard to use IO via outputLn
|
||||
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.
|
||||
(See Text encoding, Troubleshooting.)
|
||||
|
||||
On Microsoft Windows, depending whether you are running in a CMD window or a Cygwin/MSYS/Mintty window
|
||||
and how you installed hledger,
|
||||
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.)
|
||||
On Microsoft Windows, depending what kind of terminal window you use,
|
||||
non-ascii characters, ANSI text formatting, and/or the add command's TAB key for completion, may not be supported.
|
||||
|
||||
When processing large data files, hledger uses more memory than Ledger.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user