aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/Main.hs125
1 files changed, 65 insertions, 60 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 8d785be..bf90a05 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -492,7 +492,7 @@ data Command
{ patch :: Bool
}
| Show
- { id :: String,
+ { id :: Maybe String,
edit :: Bool
}
| Tags
@@ -528,7 +528,7 @@ logCmd =
showCmd :: O.Parser Command
showCmd =
Show
- <$> idArg
+ <$> O.optional idArg
<*> editFlag
tagsCmd :: O.Parser Command
@@ -678,77 +678,31 @@ main = do
es'
)
(reverse ess')
- Options {colorize, width, command = Show {id, edit}} -> do
+ Options {colorize, width, command = Show {id = Nothing}} -> do
+ issues <-
+ applySorts []
+ . applyFilters []
+ . applyClosed False
+ . (._3)
+ . last
+ <$> getHistory
+ mapM_ (\issue -> showIssue colorize width issues issue) issues
+ Options {colorize, width, command = Show {id = Just id, edit}} -> do
issues <- (._3) . last <$> getHistory
issue <-
case find ((==) id . T.unpack . I.id) issues of
Nothing -> die (printf "no issue with id `%s'\n" id)
Just issue -> pure issue
- let meta = I.getMeta issues issue
- let s =
- ( (if issue.closed then "**(CLOSED)** " else "")
- <> LT.fromStrict (T.intercalate " " issue.markers)
- <> " "
- <> LT.fromStrict issue.title
- )
- <> maybe "" (("\n\n" <>) . LT.fromStrict) issue.description
- <> LT.intercalate "\n" (map ((("***\n" :: LT.Text) <>) . LT.fromStrict) issue.comments)
if edit
then do
withSystemTempFile (printf "%s.md" id) $ \fp h -> do
- LT.hPutStr h s
+ LT.hPutStr h (LT.fromStrict issue.rawText)
hFlush h
hClose h
sh_ (proc "${EDITOR-vi} -- %" fp)
I.replaceText issue =<< T.readFile fp
else do
- -- TODO Make `show` page-able
- --
- -- We have to set `noPager` unconditionally to `True` for now, as not
- -- all output is `mdcat` compatible.
- --
- -- @topic markdown
- putDoc colorize True width $
- P.annotate (P.color P.Green) $
- P.pretty $
- issue.file
- ++ ":"
- ++ show issue.start.row
- ++ "\nvia "
- ++ T.unpack (C.toText issue.provenance.first.hash)
- ++ "\nby "
- ++ T.unpack issue.provenance.first.author.name
- ++ " <"
- ++ T.unpack issue.provenance.first.author.email
- ++ ">\nat "
- ++ show issue.provenance.first.date
- ++ "\n\n"
- sh_
- ( ( case width of
- Nothing -> "mdcat --local"
- Just width' -> proc "mdcat --columns % --local" width'
- )
- & P.setStdin (textInput s)
- )
- putDoc colorize True width $
- P.pretty $
- "\n@file "
- ++ issue.file
- ++ "\n@row "
- ++ show issue.start.row
- ++ "\n"
- when (not $ null meta.referencedBy) $
- putDoc colorize True width . P.annotate (P.color P.Black) . P.vsep $
- P.pretty ("" :: T.Text)
- : map
- ( \(otherIssue, tag) ->
- P.pretty ("This commit was referenced by issue " :: T.Text)
- <> P.annotate P.bold (P.pretty otherIssue.id)
- <> P.pretty (" (" :: T.Text)
- <> P.annotate P.bold (P.pretty ("@" <> I.tagKey tag))
- <> P.pretty (")." :: T.Text)
- )
- meta.referencedBy
+ showIssue colorize width issues issue
Options {colorize, noPager, width, internalTags, command = Tags} -> do
issues <- (._3) . last <$> getHistory
let tags =
@@ -781,6 +735,57 @@ main = do
)
tagsAndValues
+showIssue :: Color -> Maybe Int -> [Issue] -> Issue -> IO ()
+showIssue colorize width issues issue = do
+ let meta = I.getMeta issues issue
+ -- TODO Make `show` page-able
+ --
+ -- We have to set `noPager` unconditionally to `True` for now, as not
+ -- all output is `mdcat` compatible.
+ --
+ -- @topic markdown
+ putDoc colorize True width $
+ P.annotate (P.color P.Green) $
+ P.pretty $
+ issue.file
+ ++ ":"
+ ++ show issue.start.row
+ ++ "\nvia "
+ ++ T.unpack (C.toText issue.provenance.first.hash)
+ ++ "\nby "
+ ++ T.unpack issue.provenance.first.author.name
+ ++ " <"
+ ++ T.unpack issue.provenance.first.author.email
+ ++ ">\nat "
+ ++ show issue.provenance.first.date
+ ++ "\n\n"
+ sh_
+ ( ( case width of
+ Nothing -> "mdcat --local"
+ Just width' -> proc "mdcat --columns % --local" width'
+ )
+ & P.setStdin (textInput (LT.fromStrict issue.rawText))
+ )
+ putDoc colorize True width $
+ P.pretty $
+ "\n@file "
+ ++ issue.file
+ ++ "\n@row "
+ ++ show issue.start.row
+ ++ "\n"
+ when (not $ null meta.referencedBy) $
+ putDoc colorize True width . P.annotate (P.color P.Black) . P.vsep $
+ P.pretty ("" :: T.Text)
+ : map
+ ( \(otherIssue, tag) ->
+ P.pretty ("This commit was referenced by issue " :: T.Text)
+ <> P.annotate P.bold (P.pretty otherIssue.id)
+ <> P.pretty (" (" :: T.Text)
+ <> P.annotate P.bold (P.pretty ("@" <> I.tagKey tag))
+ <> P.pretty (")." :: T.Text)
+ )
+ meta.referencedBy
+
applyClosed :: Bool -> [Issue] -> [Issue]
applyClosed closed = filter (\issue -> closed || not issue.closed)