From c0c0789cbb0c02b5d0f54034db42d3880fd36ae2 Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Fri, 13 Oct 2023 17:42:00 +0200 Subject: pretty print issues using mdcat --- app/Main.hs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index b5d927b..bf8db29 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -82,7 +82,7 @@ import Data.Aeson qualified as A import Data.ByteString.Lazy qualified as L import Data.ByteString.Lazy.Char8 qualified as L8 import Data.List (find, intercalate) -import Data.Maybe (catMaybes) +import Data.Maybe (catMaybes, fromMaybe) import Data.String qualified as String import Data.Text qualified as T import Issue (Issue (..)) @@ -188,19 +188,19 @@ main = do case find ((==) (Just id) . I.id) issues of Nothing -> die (printf "no issue with id `%s'\n" id) Just issue -> - putDoc $ - P.vsep - ( concat - [ [P.annotate P.bold (P.pretty issue.title)], - maybe [] ((: []) . P.pretty) issue.description, - map - ( \(I.Tag k v) -> - P.annotate (P.colorDull P.Yellow) $ - P.pretty ("@" `T.append` k `T.append` " " `T.append` v) - ) - issue.tags - ] - ) + sh_ + ( P.setStdin + ( String.fromString + ( T.unpack issue.title + ++ "\n\n" + ++ fromMaybe "" (fmap T.unpack issue.description) + ) + ) + -- TODO Make columns configurable + -- + -- @topic formatting + "mdcat --columns 80 --local" + ) putDoc :: P.Doc P.AnsiStyle -> IO () putDoc doc = do @@ -287,6 +287,13 @@ sh proc = do then pure out else throwIO $ ProcessException (show proc) exitCode err +sh_ :: P.ProcessConfig stdin stdoutIgnored stderr -> IO () +sh_ proc = do + (exitCode, err) <- P.readProcessStderr proc + if exitCode == P.ExitSuccess + then pure () + else throwIO $ ProcessException (show proc) exitCode err + fixTreeGrepper :: G.Result -> G.Result fixTreeGrepper treeGrepperResult = treeGrepperResult {G.matches = G.merge treeGrepperResult.matches} -- cgit v1.2.3