From bb5d47395519d4430a0ecf1cc641ba5e3e62b2cd Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 27 Jan 2023 06:01:49 -1000 Subject: [PATCH] fix: lib: don't use $PAGER when TERM=dumb --- hledger-lib/Hledger/Utils/IO.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Utils/IO.hs b/hledger-lib/Hledger/Utils/IO.hs index 2fd184a39..314034f93 100644 --- a/hledger-lib/Hledger/Utils/IO.hs +++ b/hledger-lib/Hledger/Utils/IO.hs @@ -126,9 +126,11 @@ pprint' = pPrintOpt CheckColorTty prettyopts' -- "Avoid using pshow, pprint, dbg* in the code below to prevent infinite loops." (?) -- | Display the given text on the terminal, using the user's $PAGER if the text is taller --- than the current terminal and stdout is interactive. +-- than the current terminal and stdout is interactive and TERM is not "dumb". pager :: String -> IO () -pager s = printOrPage $ pack s +pager s = do + dumbterm <- (== Just "dumb") <$> lookupEnv "TERM" + (if dumbterm then putStrLn else printOrPage . pack) s -- Command line arguments @@ -163,6 +165,7 @@ outputFileOption = -- with an argument other than "-", using unsafePerformIO. hasOutputFile :: Bool hasOutputFile = outputFileOption `notElem` [Nothing, Just "-"] +-- XXX shouldn't we check that stdout is interactive. instead ? -- ANSI colour