imp📟 add a --no-pager general flag
This commit is contained in:
parent
db748465a8
commit
ba786752d1
@ -202,6 +202,10 @@ setupPager = do
|
||||
addR "LESS"
|
||||
addR "MORE"
|
||||
|
||||
-- | Check if the --no-pager command line flag was provided at program startup, using unsafePerformIO.
|
||||
noPagerFlag :: Bool
|
||||
noPagerFlag = "--no-pager" `elem` progArgs
|
||||
|
||||
-- related: Hledger.Cli.DocFiles.runPagerForTopic
|
||||
-- | 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 and TERM is not "dumb";
|
||||
@ -214,14 +218,14 @@ pager :: String -> IO ()
|
||||
#ifdef mingw32_HOST_OS
|
||||
pager = putStr
|
||||
#else
|
||||
pager = printOrPage'
|
||||
|
||||
printOrPage' s = do
|
||||
-- disable pager if TERM=dumb (for Emacs shell users)
|
||||
pager s = do
|
||||
-- disable pager when --no-pager is specified
|
||||
let nopager = noPagerFlag
|
||||
-- disable pager when TERM=dumb (for Emacs shell users)
|
||||
dumbterm <- (== Just "dumb") <$> lookupEnv "TERM"
|
||||
-- avoid a pager crash with single-line output, https://github.com/pharpend/pager/issues/2
|
||||
-- disable pager with single-line output (https://github.com/pharpend/pager/issues/2)
|
||||
let singleline = not $ '\n' `elem` s
|
||||
-- avoid a pager crash when PAGER is set to something not in PATH
|
||||
-- disable pager when PAGER is set to something bad (https://github.com/pharpend/pager/issues/3)
|
||||
mpagervar <- lookupEnv "PAGER"
|
||||
badpager <-
|
||||
case mpagervar of
|
||||
@ -232,7 +236,7 @@ printOrPage' s = do
|
||||
Just _ -> return False
|
||||
Nothing -> return True
|
||||
|
||||
(if dumbterm || singleline || badpager
|
||||
(if nopager || dumbterm || singleline || badpager
|
||||
then putStr
|
||||
else printOrPage . T.pack)
|
||||
s
|
||||
|
||||
@ -228,6 +228,7 @@ reportflags = [
|
||||
,flagReq ["commodity-style", "c"] (\s opts -> Right $ setopt "commodity-style" s opts) "S"
|
||||
"Override a commodity's display style.\nEg: -c '$1000.' or -c '1.000,00 EUR'"
|
||||
-- This has special support in hledger-lib:colorOption, keep synced
|
||||
,flagNone ["no-pager"] (setboolopt "no-pager") "don't use a pager for long output"
|
||||
,flagReq ["color","colour"] (\s opts -> Right $ setopt "color" s opts) "YN"
|
||||
(unlines
|
||||
["Use ANSI color codes in text output? Can be"
|
||||
|
||||
@ -736,6 +736,9 @@ in `less` (and in its `more` compatibility mode).
|
||||
If you use a different pager, you might need to configure it similarly, to avoid seeing junk on screen.
|
||||
Or you can set the `NO_COLOR` environment variable described below.
|
||||
|
||||
You can prevent the use of a pager by using the `--no-pager` flag,
|
||||
eg in your hledger config file.
|
||||
|
||||
Here are some notes about the various output formats.
|
||||
|
||||
### Text output
|
||||
|
||||
Loading…
Reference in New Issue
Block a user