aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-04 11:56:31 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-04 11:56:31 +0200
commit3056117ee6a84ec0110f9ee6e1f9ef0f4d150183 (patch)
tree7725433104e9610196dd16e9c8b2704085514415
parentd12ee3bfa78699eab8f03d9b0d06ed2a9547ab37 (diff)
ansi style output, breaks tests
-rw-r--r--anissue.cabal2
-rw-r--r--app/Main.hs62
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