From c0ba5044d9f36ad91d0ef8a11a5cb5adabcea33f Mon Sep 17 00:00:00 2001
From: Fabian Kirchner <kirchner@posteo.de>
Date: Fri, 13 Oct 2023 20:32:44 +0200
Subject: make width of output configurable

---
 app/Main.hs | 32 +++++++++++++++++++++++++-------
 1 file 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 $
-- 
cgit v1.2.3