imp: pager set extra LESS options for a nice experience when using less
Currently this sets a rather ambitious set of options, and overrides the existing LESS: --chop-long-lines --hilite-unread --ignore-case --mouse --no-init --QUIT-AT-EOF --quit-if-one-screen --RAW-CONTROL-CHARS --squeeze-blank-lines --use-backslash --use-color
This commit is contained in:
parent
30086ae249
commit
1011029356
@ -195,33 +195,44 @@ getTerminalWidth = fmap snd <$> getTerminalHeightWidth
|
|||||||
|
|
||||||
-- Pager helpers, somewhat hledger-specific.
|
-- Pager helpers, somewhat hledger-specific.
|
||||||
|
|
||||||
-- Configure some preferred options when viewing output with the `less` pager
|
-- Configure some preferred options for the `less` pager or its `more` emulation mode,
|
||||||
-- or its `more` emulation mode.
|
-- by setting the LESS and MORE environment variables in this program's environment.
|
||||||
-- If PAGER is configured to something else, this probably will have no effect.
|
-- If PAGER is set to something else, this probably will have no effect.
|
||||||
-- The options are:
|
-- This is intended to be called at program startup.
|
||||||
--
|
--
|
||||||
-- * squash excess vertical whitespace (-s),
|
-- Currently this sets a rather ambitious set of options, and overrides the user's
|
||||||
|
-- LESS or MORE settings (appending to those variables if they are already set).
|
||||||
--
|
--
|
||||||
-- * search case insensitively (-i),
|
-- --chop-long-lines
|
||||||
--
|
-- --hilite-unread
|
||||||
-- * allow search for dollar sign and other regex metacharacters by backslash-quoting (--use-backslash),
|
-- --ignore-case
|
||||||
--
|
-- --mouse
|
||||||
-- * intepret ANSI style/colour codes (-R).
|
-- --no-init
|
||||||
-- hledger output may contain these, if the terminal seems to support them,
|
-- --quit-at-eof
|
||||||
-- so if a pager other than less is used, it should be configured to display them.
|
-- --quit-if-one-screen
|
||||||
-- (Or they can be disabled by --color=no or NO_COLOR.)
|
-- --RAW-CONTROL-CHARS
|
||||||
--
|
-- --shift=8
|
||||||
-- The options are appended to the LESS and MORE environment variables in this program's environment,
|
-- --squeeze-blank-lines
|
||||||
-- overriding rather than replacing whatever the user may have configured there.
|
-- --use-backslash
|
||||||
|
-- --use-color
|
||||||
--
|
--
|
||||||
setupPager :: IO ()
|
setupPager :: IO ()
|
||||||
setupPager = do
|
setupPager = do
|
||||||
let
|
let
|
||||||
lessopts = unwords [ -- keep synced with doc above:
|
-- keep synced with doc above
|
||||||
"-R"
|
lessopts = unwords [
|
||||||
,"-s"
|
"--chop-long-lines"
|
||||||
,"-i"
|
,"--hilite-unread"
|
||||||
|
,"--ignore-case"
|
||||||
|
,"--mouse"
|
||||||
|
,"--no-init"
|
||||||
|
,"--quit-at-eof"
|
||||||
|
,"--quit-if-one-screen"
|
||||||
|
,"--RAW-CONTROL-CHARS"
|
||||||
|
,"--shift=8"
|
||||||
|
,"--squeeze-blank-lines"
|
||||||
,"--use-backslash"
|
,"--use-backslash"
|
||||||
|
,"--use-color"
|
||||||
]
|
]
|
||||||
addToEnvVar var = do
|
addToEnvVar var = do
|
||||||
mv <- lookupEnv var
|
mv <- lookupEnv var
|
||||||
@ -232,8 +243,14 @@ setupPager = do
|
|||||||
addToEnvVar "LESS"
|
addToEnvVar "LESS"
|
||||||
addToEnvVar "MORE"
|
addToEnvVar "MORE"
|
||||||
|
|
||||||
-- | Display the given text on the terminal, trying to use a pager when appropriate,
|
-- | Display the given text on the terminal, trying to use a pager ($PAGER, less, or more)
|
||||||
-- otherwise printing to standard output. Uses maybePagerFor.
|
-- when appropriate, otherwise printing to standard output. Uses maybePagerFor.
|
||||||
|
--
|
||||||
|
-- hledger's output may contain ANSI style/color codes
|
||||||
|
-- (if the terminal supports them and they are not disabled by --color=no or NO_COLOR),
|
||||||
|
-- so the pager should be configured to handle these.
|
||||||
|
-- setupPager tries to configure that automatically when using the `less` pager.
|
||||||
|
--
|
||||||
runPager :: String -> IO ()
|
runPager :: String -> IO ()
|
||||||
runPager s = do
|
runPager s = do
|
||||||
mpager <- maybePagerFor s
|
mpager <- maybePagerFor s
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user