diff options
-rw-r--r-- | app/Main.hs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/app/Main.hs b/app/Main.hs index fb81f07..39eb048 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -453,7 +453,8 @@ import Prelude hiding (id) data Options = Options { command :: Command, internalTags :: Bool, - colorize :: Color + colorize :: Color, + noPager :: Bool } deriving (Show) @@ -469,6 +470,7 @@ options = <$> cmd <*> internalTagsFlag <*> colorOption + <*> noPagerFlag internalTagsFlag :: O.Parser Bool internalTagsFlag = @@ -492,6 +494,14 @@ colorOption = parse "never" = pure Never parse _ = Nothing +noPagerFlag :: O.Parser Bool +noPagerFlag = + O.switch + ( O.long "no-pager" + <> O.short 'P' + <> O.help "Don't pipe long output to $PAGER." + ) + data Command = List { files :: [String], @@ -559,9 +569,9 @@ die s = do main :: IO () main = do O.execParser (O.info (options <**> O.helper) O.idm) >>= \case - Options {colorize, command = List {sort, filters, files}} -> do + Options {colorize, noPager, command = List {sort, filters, files}} -> do issues <- listIssues sort filters files - putDoc colorize . P.vsep $ + putDoc colorize noPager . P.vsep $ map ( \issue -> let title = P.annotate P.bold $ P.pretty issue.title @@ -597,7 +607,11 @@ main = do case find ((==) (Just id) . I.id) issues of Nothing -> die (printf "no issue with id `%s'\n" id) Just issue -> do - putDoc colorize $ + -- TODO Make `show` page-able + -- + -- We have to set `noPager` unconditionally to `True` for now, as not + -- all output is `mdcat` compatible. + putDoc colorize True $ P.annotate (P.color P.Green) $ P.pretty $ issue.file @@ -629,7 +643,7 @@ main = do ) ) ) - putDoc colorize $ + putDoc colorize True $ P.pretty $ "\n@file " ++ issue.file @@ -637,8 +651,8 @@ main = do ++ show issue.start.row ++ "\n" -putDoc :: Color -> P.Doc P.AnsiStyle -> IO () -putDoc colorize doc = do +putDoc :: Color -> Bool -> P.Doc P.AnsiStyle -> IO () +putDoc colorize noPager doc = do isTty <- (== 1) <$> c_isatty 1 term <- Terminal.size let s = @@ -652,7 +666,7 @@ putDoc colorize doc = do else P.unAnnotate ) $ doc - if maybe False (length (LT.lines s) >) (Terminal.height <$> term) + if not noPager && maybe False (length (LT.lines s) >) (Terminal.height <$> term) then sh_ ( "${PAGER-less}" |