aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Issue/Render.hs18
-rw-r--r--app/Main.hs6
-rw-r--r--app/Render.hs19
3 files changed, 26 insertions, 17 deletions
diff --git a/app/Issue/Render.hs b/app/Issue/Render.hs
index 39249ae..c8a913b 100644
--- a/app/Issue/Render.hs
+++ b/app/Issue/Render.hs
@@ -18,25 +18,15 @@ import Data.Time.Clock (UTCTime (utctDay))
import Git (Author (..), Commit (..))
import Issue (Issue (..))
import Issue.Provenance (Provenance (..))
-import Render ((<<<))
+import Render ((<<<), (===))
import Render qualified as P
--- TODO Easily separate renderables by newlines
---
--- For convenience, the (<<<) combinator adds spaces between renderable entities, **if** those renderables are non-empty.
---
--- We should similarly allow for a combinator that similarly adds empty lines between renderable entities.
---
--- @topic rendering
instance P.Render (P.Detailed Issue) where
render (P.Detailed issue) =
IssueTitle issue
- <<< P.hardline @P.AnsiStyle
- <<< IssueDescription issue
- <<< P.hardline @P.AnsiStyle
- <<< IssueTags issue
- <<< P.hardline @P.AnsiStyle
- <<< IssueComments issue
+ === IssueDescription issue
+ === IssueTags issue
+ === IssueComments issue
instance P.Render Issue where
render = P.render . P.Detailed
diff --git a/app/Main.hs b/app/Main.hs
index da4ea6a..46f6e77 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -573,10 +573,10 @@ main = do
map (if detailed then (P.render . P.Detailed) else (P.render . P.Summarized)) issues
Options {colorize, noPager, width, command = Log {patch}} -> do
es <- reverse . (.issueEvents) <$> getHistory
- putDoc colorize noPager width . P.vsep $
+ putDoc colorize noPager width $
if patch
- then map (P.render . P.Detailed) es
- else map (P.render . P.Summarized) es
+ then P.vsep . intersperse P.emptyDoc $ map (P.render . P.Detailed) es
+ else P.vsep $ map (P.render . P.Summarized) es
Options {colorize, noPager, width, command = Show {id, edit}} -> do
issues <- (.issues) <$> getHistory
issue <-
diff --git a/app/Render.hs b/app/Render.hs
index f63a3bc..964581f 100644
--- a/app/Render.hs
+++ b/app/Render.hs
@@ -10,6 +10,7 @@ module Render
-- * Render
Render (..),
(<<<),
+ (===),
styled,
-- * Reporting styles
@@ -72,6 +73,24 @@ instance Render Day where
startsWithNL = ("\n" `isPrefixOf`) . show . render
endsWithNL = ("\n" `isSuffixOf`) . show . render
+(===) :: (Render a, Render b) => a -> b -> Doc AnsiStyle
+(===) a' b' =
+ case (nonEmpty a', nonEmpty b') of
+ (Nothing, Nothing) -> emptyDoc
+ (Just a, Nothing) -> a
+ (Nothing, Just b) -> b
+ (Just a, Just b) ->
+ if
+ | endsWithNL a && startsWithNL b -> a <> b
+ | endsWithNL a || startsWithNL b -> a <> hardline <> b
+ | otherwise -> a <> hardline <> hardline <> b
+ where
+ nonEmpty x' =
+ let x = render x'
+ in if not (null (show x)) then Just (render x) else Nothing
+ startsWithNL = ("\n" `isPrefixOf`) . show . render
+ endsWithNL = ("\n" `isSuffixOf`) . show . render
+
-- | `styled` allows to annotate a document with multiple annotations. It obsoletes prettyprinter's `annotate`.
styled :: [AnsiStyle] -> Doc AnsiStyle -> Doc AnsiStyle
styled [] doc = doc