aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs62
1 files changed, 39 insertions, 23 deletions
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