Skip to content

Commit 71522bd

Browse files
hasufellandreasabel
authored andcommitted
Lookup PAGER env var (#1)
Also: Fix color formatting when PAGER is 'less'
1 parent 9c30a1c commit 71522bd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cabal-install/src/Distribution/Client/Manpage.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import Distribution.Simple.Utils
3434
( IOData(..), IODataMode(..), createProcessWithEnv, ignoreSigPipe, rawSystemStdInOut )
3535
import qualified Distribution.Verbosity as Verbosity
3636
import System.IO (hClose, hPutStr)
37+
import System.Environment (lookupEnv)
38+
import System.FilePath (takeFileName)
3739

3840
import qualified System.Process as Process
3941

@@ -78,11 +80,14 @@ manpageCmd pname commands flags
7880

7981
unless (ec1 == ExitSuccess) $ exitWith ec1
8082

83+
pager <- fromMaybe "less" <$> lookupEnv "PAGER"
84+
-- 'less' is borked with color sequences otherwise
85+
let pagerArgs = if takeFileName pager == "less" then ["-R"] else []
8186
-- Pipe output of @nroff@ into @less@
8287
(Just inLess, _, _, procLess) <- createProcessWithEnv
8388
Verbosity.normal
84-
"less"
85-
[]
89+
pager
90+
pagerArgs
8691
Nothing -- Inherit working directory
8792
Nothing -- Inherit environment
8893
Process.CreatePipe -- in

0 commit comments

Comments
 (0)