imp: simplify pager setup: just customise LESS, not MORE

[#2272]-related
This commit is contained in:
Simon Michael 2024-11-01 06:53:31 -10:00
parent 1011029356
commit 5bab9600e4

View File

@ -195,13 +195,10 @@ getTerminalWidth = fmap snd <$> getTerminalHeightWidth
-- Pager helpers, somewhat hledger-specific. -- Pager helpers, somewhat hledger-specific.
-- Configure some preferred options for the `less` pager or its `more` emulation mode, -- Configure some preferred options for the `less` pager,
-- by setting the LESS and MORE environment variables in this program's environment. -- by modifying the LESS environment variable in this program's environment.
-- If PAGER is set to something else, this probably will have no effect. -- If you are using some other pager, this will have no effect.
-- This is intended to be called at program startup. -- By default, this sets the following options, appending them to LESS's current value:
--
-- 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).
-- --
-- --chop-long-lines -- --chop-long-lines
-- --hilite-unread -- --hilite-unread
@ -220,7 +217,7 @@ setupPager :: IO ()
setupPager = do setupPager = do
let let
-- keep synced with doc above -- keep synced with doc above
lessopts = unwords [ deflessopts = unwords [
"--chop-long-lines" "--chop-long-lines"
,"--hilite-unread" ,"--hilite-unread"
,"--ignore-case" ,"--ignore-case"
@ -234,14 +231,11 @@ setupPager = do
,"--use-backslash" ,"--use-backslash"
,"--use-color" ,"--use-color"
] ]
addToEnvVar var = do mless <- lookupEnv "LESS"
mv <- lookupEnv var setEnv "LESS" $
setEnv var $ case mless of
case mv of Just less -> unwords [less, deflessopts]
Just v -> unwords [v, lessopts] _ -> deflessopts
Nothing -> lessopts
addToEnvVar "LESS"
addToEnvVar "MORE"
-- | Display the given text on the terminal, trying to use a pager ($PAGER, less, or more) -- | Display the given text on the terminal, trying to use a pager ($PAGER, less, or more)
-- when appropriate, otherwise printing to standard output. Uses maybePagerFor. -- when appropriate, otherwise printing to standard output. Uses maybePagerFor.