diff options
author | Fabian Kirchner <kirchner@posteo.de> | 2023-10-13 20:32:44 +0200 |
---|---|---|
committer | Fabian Kirchner <kirchner@posteo.de> | 2023-10-13 20:32:44 +0200 |
commit | c0ba5044d9f36ad91d0ef8a11a5cb5adabcea33f (patch) | |
tree | dbe37cbd021bb5115c5c8a90823941bbc6c86f2c /app/Main.hs | |
parent | 7fcaeb29bfb87c82468df2ec1cea1c70f96aedff (diff) |
make width of output configurable
Diffstat (limited to 'app/Main.hs')
-rw-r--r-- | app/Main.hs | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/app/Main.hs b/app/Main.hs index d69530f..0faff19 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -109,7 +109,8 @@ data Command internalTags :: Bool } | Show - { id :: String + { id :: String, + width :: Maybe Int } deriving (Show) @@ -130,7 +131,10 @@ listCmd = <*> internalTagsFlag showCmd :: O.Parser Command -showCmd = Show <$> idArg +showCmd = + Show + <$> idArg + <*> widthOption filesArg :: O.Parser [String] filesArg = O.many (O.strArgument (O.metavar "FILE" <> O.action "file")) @@ -152,6 +156,18 @@ idArg = ) ) +widthOption :: O.Parser (Maybe Int) +widthOption = + O.optional + ( O.option + O.auto + ( O.long "width" + <> O.short 'w' + <> O.metavar "INT" + <> O.help "Wheather to insert line breaks after at most that many characters." + ) + ) + die :: String -> IO a die s = do printf "error: %s\n" s @@ -180,7 +196,7 @@ main = do ) ) issues - Show {id} -> do + Show {id, width} -> do issues <- listIssues [] [] case find ((==) (Just id) . I.id) issues of Nothing -> die (printf "no issue with id `%s'\n" id) @@ -201,10 +217,12 @@ main = do ++ fromMaybe "" (fmap T.unpack issue.description) ) ) - -- TODO Make columns configurable - -- - -- @topic formatting - "mdcat --columns 80 --local" + ( case width of + Nothing -> + "mdcat --local" + Just width' -> + String.fromString (printf "mdcat --columns %d --local" width') + ) ) putDoc $ P.pretty $ |