From 3056117ee6a84ec0110f9ee6e1f9ef0f4d150183 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 4 Oct 2023 11:56:31 +0200 Subject: ansi style output, breaks tests --- anissue.cabal | 2 ++ app/Main.hs | 62 +++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/anissue.cabal b/anissue.cabal index 84c3eb3..54a1669 100644 --- a/anissue.cabal +++ b/anissue.cabal @@ -81,6 +81,8 @@ executable anissue bytestring, filepath, optparse-applicative, + prettyprinter, + prettyprinter-ansi-terminal, text, typed-process diff --git a/app/Main.hs b/app/Main.hs index 2e36d4c..60c81e4 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -44,7 +44,6 @@ module Main where import Control.Exception (Exception, catch, throw, throwIO) -import Control.Monad (when) import Data.Aeson qualified as A import Data.ByteString.Lazy qualified as L import Data.ByteString.Lazy.Char8 qualified as L8 @@ -53,12 +52,13 @@ import Data.Maybe (catMaybes) import Data.Maybe qualified as Maybe import Data.String qualified as String import Data.Text qualified as T -import Data.Text.IO qualified as T import Issue (Issue (..)) import Issue qualified as I import Issue.Tag qualified as I import Options.Applicative ((<**>)) import Options.Applicative qualified as O +import Prettyprinter qualified as P +import Prettyprinter.Render.Terminal as P import System.Exit (ExitCode (ExitFailure), exitWith) import System.FilePath qualified as F import System.IO (hPutStrLn, stderr) @@ -120,27 +120,43 @@ main = do exitWith (ExitFailure 1) ) case options of - List _ -> mapM_ listMatches $ concat issues - Show _ -> mapM_ showMatches $ concat issues - -showMatches :: Issue -> IO () -showMatches issue = do - T.putStrLn issue.title - when (not (T.null issue.description)) do - T.putStrLn "" - T.putStrLn issue.description - -listMatches :: Issue -> IO () -listMatches issue = - printf - "%s%s\n" - issue.title - ( if null issue.tags - then "" - else - T.append " " . T.intercalate " " $ - map (\(I.Tag k v) -> T.intercalate ":" [k, v]) issue.tags - ) + List _ -> listMatches $ concat issues + Show _ -> showMatches $ concat issues + +showMatches :: [Issue] -> IO () +showMatches issues = do + P.putDoc . P.vsep $ + map + ( \issue -> + P.vsep + ( concat + [ [P.annotate P.bold (P.pretty issue.title)], + if not (T.null issue.description) + then [P.pretty issue.description] + else [] + ] + ) + ) + issues + +listMatches :: [Issue] -> IO () +listMatches issues = + P.putDoc . P.vsep $ + map + ( \issue -> + P.hsep + ( concat + [ [P.annotate P.bold (P.pretty issue.title)], + map + ( \(I.Tag k v) -> + P.annotate (P.colorDull P.Yellow) $ + P.pretty ("@" `T.append` k `T.append` ":" `T.append` v) + ) + issue.tags + ] + ) + ) + issues data UnknownFileExtension = UnknownFileExtension { extension :: String -- cgit v1.2.3