aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-16 15:51:24 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-16 15:51:24 +0200
commitbd576cb210a8c03a32c60f1b3ca769450bde3d04 (patch)
treebb68617c64ec6d5c92c4eaa98afe074eb5c975c8 /app
parent82737c98e809bb3e970aa16750aa70f1adcfa03a (diff)
update `list` output
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs53
1 files changed, 38 insertions, 15 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 183e976..1617c86 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -354,6 +354,7 @@ import Data.List (find)
import Data.Maybe (catMaybes, fromMaybe)
import Data.String qualified as String
import Data.Text qualified as T
+import Data.Time.Clock (UTCTime (utctDay))
import History (listIssues)
import Issue (Issue (..))
import Issue qualified as I
@@ -361,13 +362,15 @@ import Issue.Filter (Filter)
import Issue.Filter qualified as I
import Issue.Sort (Sort)
import Issue.Sort qualified as I
-import Issue.Tag qualified as I
import Options.Applicative ((<**>))
import Options.Applicative qualified as O
+import Prettyprinter ((<+>))
import Prettyprinter qualified as P
import Prettyprinter.Render.Terminal qualified as P
import Process (sh_)
+import System.Console.Terminal.Size qualified as Terminal
import System.Exit (ExitCode (ExitFailure), exitWith)
+import System.IO (stdout)
import System.Process.Typed qualified as P
import Text.Printf
import TreeGrepper.Match qualified as G
@@ -459,24 +462,37 @@ die s = do
main :: IO ()
main = do
O.execParser (O.info (options <**> O.helper) O.idm) >>= \case
- Options {internalTags, command = List {sort, filters, files}} -> do
+ Options {command = List {sort, filters, files}} -> do
issues <- listIssues sort filters files
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
- ++ if internalTags then issue.internalTags else []
- )
+ let title = P.annotate P.bold $ P.pretty issue.title
+ fileAndRow =
+ keyword "in"
+ <+> value (T.pack issue.file <> ":" <> T.pack (show issue.start.row))
+ commit = fromProvenanceDef (keyword "via" <+> value (T.pack "HEAD")) $
+ \I.Provenance {firstCommit} -> keyword "via" <+> value (T.take 7 firstCommit)
+ author = fromProvenance $
+ \I.Provenance {authorName, authorEmail} ->
+ ( keyword "by" <+> value (authorName <> " <" <> authorEmail <> ">")
+ )
+ date' = fromProvenance $
+ \I.Provenance {date} -> keyword "on" <+> value (show (utctDay date))
+
+ fromProvenanceDef def = flip (maybe def) issue.provenance
+ fromProvenance = flip fmap issue.provenance
+ keyword :: T.Text -> P.Doc P.AnsiStyle
+ keyword = P.annotate (P.colorDull P.Green) . P.pretty
+ value :: P.Pretty a => a -> P.Doc P.AnsiStyle
+ value = P.annotate (P.color P.Green) . P.pretty
+ in P.nest 4 . P.vsep . catMaybes $
+ [ Just title,
+ Just fileAndRow,
+ Just commit,
+ author,
+ date'
]
- )
)
issues
Options {command = Show {id, width}} -> do
@@ -531,6 +547,13 @@ main = do
putDoc :: P.Doc P.AnsiStyle -> IO ()
putDoc doc = do
isTty <- (== 1) <$> c_isatty 1
- P.putDoc . (if isTty then (\x -> x) else P.unAnnotate) $ doc
+ columns <- fmap Terminal.width <$> Terminal.size
+ P.renderIO stdout
+ $ P.layoutSmart
+ P.defaultLayoutOptions
+ { P.layoutPageWidth = maybe P.Unbounded (\n -> P.AvailablePerLine n 1) columns
+ }
+ $ (if isTty then (\x -> x) else P.unAnnotate)
+ $ doc
foreign import ccall "unistd.h isatty" c_isatty :: Int -> IO Int