diff --git a/cabal-install/src/Distribution/Client/Manpage.hs b/cabal-install/src/Distribution/Client/Manpage.hs index f93c711753ce8239bc4eb6b768eadbe8ac9ac0f9..19e80ba9f5f334e55fe9649e1d6bdb98b92825d8 100644 --- a/cabal-install/src/Distribution/Client/Manpage.hs +++ b/cabal-install/src/Distribution/Client/Manpage.hs @@ -31,10 +31,10 @@ import Distribution.Compat.Process (proc) import Distribution.Simple.Command import Distribution.Simple.Flag (fromFlag, fromFlagOrDefault) import Distribution.Simple.Utils - ( IOData(..), IODataMode(..), ignoreSigPipe, rawSystemStdInOut, rawSystemProcAction, fromCreatePipe ) + ( IOData(..), IODataMode(..), ignoreSigPipe, rawSystemStdInOut, rawSystemProcAction, + fromCreatePipe, die' ) import System.IO (hClose, hPutStr) import System.Environment (lookupEnv) -import System.FilePath (takeFileName) import qualified System.Process as Process data FileInfo = FileInfo String String -- ^ path, description @@ -78,9 +78,11 @@ manpageCmd pname commands flags unless (ec1 == ExitSuccess) $ exitWith ec1 - pager <- fromMaybe "less" <$> lookupEnv "PAGER" - -- 'less' is borked with color sequences otherwise - let pagerArgs = if takeFileName pager == "less" then ["-R"] else [] + pagerAndArgs <- fromMaybe "less -R" <$> lookupEnv "PAGER" + -- 'less' is borked with color sequences otherwise, hence -R + (pager, pagerArgs) <- case words pagerAndArgs of + [] -> die' verbosity "man: empty value of the PAGER environment variable" + (p:pa) -> pure (p, pa) -- Pipe output of @nroff@ into @less@ (ec2, _) <- rawSystemProcAction verbosity (proc pager pagerArgs) { Process.std_in = Process.CreatePipe } diff --git a/changelog.d/issue-8405 b/changelog.d/issue-8405 new file mode 100644 index 0000000000000000000000000000000000000000..5ed2759fec964e334fdd7ecce22a9a59d302ac60 --- /dev/null +++ b/changelog.d/issue-8405 @@ -0,0 +1,14 @@ +synopsis: `cabal man` handles $PAGER containing arguments now +packages: cabal-install +prs: #8353 +issues: #8405 + +description: { + +Things like `PAGER="less -FX" cabal man` work now. + +There's a slight change in the default behavior. We still use `less -R` as the default, +but if the user passes `PAGER=less`, we won't add -R to that, unlike before. This is +reasonable, as the user should be able to set the variable as they see fit. + +}