fix📟 when the $PAGER is not in PATH, print instead of failing
This commit is contained in:
parent
4441680d7b
commit
db748465a8
@ -114,7 +114,7 @@ import String.ANSI
|
||||
import System.Console.ANSI (Color(..),ColorIntensity(..),
|
||||
ConsoleLayer(..), SGR(..), hSupportsANSIColor, setSGRCode, getLayerColor)
|
||||
import System.Console.Terminal.Size (Window (Window), size)
|
||||
import System.Directory (getHomeDirectory, getModificationTime)
|
||||
import System.Directory (getHomeDirectory, getModificationTime, findExecutable)
|
||||
import System.Environment (getArgs, lookupEnv, setEnv)
|
||||
import System.FilePath (isRelative, (</>))
|
||||
import "Glob" System.FilePath.Glob (glob)
|
||||
@ -202,6 +202,7 @@ setupPager = do
|
||||
addR "LESS"
|
||||
addR "MORE"
|
||||
|
||||
-- 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";
|
||||
-- except on Windows, where currently we don't attempt to use a pager.
|
||||
@ -220,7 +221,18 @@ printOrPage' s = do
|
||||
dumbterm <- (== Just "dumb") <$> lookupEnv "TERM"
|
||||
-- avoid a pager crash with single-line output, https://github.com/pharpend/pager/issues/2
|
||||
let singleline = not $ '\n' `elem` s
|
||||
(if dumbterm || singleline
|
||||
-- avoid a pager crash when PAGER is set to something not in PATH
|
||||
mpagervar <- lookupEnv "PAGER"
|
||||
badpager <-
|
||||
case mpagervar of
|
||||
Nothing -> return False
|
||||
Just p -> do
|
||||
mexe <- findExecutable p
|
||||
case mexe of
|
||||
Just _ -> return False
|
||||
Nothing -> return True
|
||||
|
||||
(if dumbterm || singleline || badpager
|
||||
then putStr
|
||||
else printOrPage . T.pack)
|
||||
s
|
||||
|
||||
@ -138,7 +138,7 @@ library
|
||||
, containers >=0.5.9
|
||||
, data-default >=0.5
|
||||
, deepseq
|
||||
, directory
|
||||
, directory >=1.2.6.1
|
||||
, doclayout >=0.3 && <0.6
|
||||
, extra >=1.6.3
|
||||
, file-embed >=0.0.10
|
||||
@ -202,7 +202,7 @@ test-suite doctest
|
||||
, containers >=0.5.9
|
||||
, data-default >=0.5
|
||||
, deepseq
|
||||
, directory
|
||||
, directory >=1.2.6.1
|
||||
, doclayout >=0.3 && <0.6
|
||||
, doctest >=0.18.1
|
||||
, extra >=1.6.3
|
||||
@ -269,7 +269,7 @@ test-suite unittest
|
||||
, containers >=0.5.9
|
||||
, data-default >=0.5
|
||||
, deepseq
|
||||
, directory
|
||||
, directory >=1.2.6.1
|
||||
, doclayout >=0.3 && <0.6
|
||||
, extra >=1.6.3
|
||||
, file-embed >=0.0.10
|
||||
|
||||
@ -57,7 +57,7 @@ dependencies:
|
||||
- data-default >=0.5
|
||||
- deepseq
|
||||
- Decimal >=0.5.1
|
||||
- directory
|
||||
- directory >=1.2.6.1
|
||||
- doclayout >=0.3 && <0.6
|
||||
- file-embed >=0.0.10
|
||||
- filepath
|
||||
|
||||
@ -109,6 +109,7 @@ runInfoForTopic tool mtopic =
|
||||
-- less with any vertical whitespace squashed, case-insensitive searching, the $ regex metacharacter accessible as \$.
|
||||
less = "less -s -i --use-backslash"
|
||||
|
||||
-- related: Hledger.Utils.IO.pager
|
||||
-- | Display plain text help for this tool, scrolled to the given topic if any, using the users $PAGER or "less".
|
||||
-- When a topic is provided we always use less, ignoring $PAGER.
|
||||
runPagerForTopic :: Tool -> Maybe Topic -> IO ()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user