This commit is contained in:
Dmitry Zuikov 2024-05-13 19:42:38 +03:00
parent 4e5e345cfb
commit 264b2f526e
2 changed files with 36 additions and 6 deletions

View File

@ -43,7 +43,16 @@ fixme-comments ";" "--"
(define-template short
(simple
(trim 10 $fixme-key) " "
(fg blue (align 6 $fixme-tag)) " "
(if (~ FIXME $fixme-tag)
(then (fgd red (align 6 $fixme-tag)) )
(else (if (~ TODO $fixme-tag)
(then (fgd green (align 6 $fixme-tag)))
(else (align 6 $fixme-tag)) ) )
)
" "
(align 8 ("[" $workflow "]")) " "
(align 12 $assigned) " "
(trim 50 ($fixme-title))
@ -52,7 +61,6 @@ fixme-comments ";" "--"
)
;update
update

View File

@ -315,18 +315,35 @@ instance FixmeRenderTemplate SimpleTemplate (Doc AnsiStyle) where
(acc, NL : rest) -> next (acc <> nl, rest)
(acc, ListVal [StringLike w] : rest) -> next (acc <> txt w, rest)
(acc, StringLike w : rest) -> next (acc <> txt w, rest)
(acc, ListVal [SymbolVal "trim", LitIntVal n, e] : rest) -> next (acc <> trim n (deep [e]), rest)
(acc, ListVal [SymbolVal "align", LitIntVal n, e] : rest) -> next (acc <> align n (deep [e]), rest)
(acc, ListVal [SymbolVal "trim", LitIntVal n, e] : rest) -> next (acc <> trim n (deep' [e]), rest)
(acc, ListVal [SymbolVal "align", LitIntVal n, e] : rest) -> next (acc <> align n (deep' [e]), rest)
(acc, ListVal [SymbolVal "fg", SymbolVal co, e] : rest) -> next (acc <> fmap (fg_ (color_ co)) (deep [e]), rest)
(acc, ListVal [SymbolVal "bg", SymbolVal co, e] : rest) -> next (acc <> fmap (bg_ (color_ co)) (deep [e]), rest)
(acc, ListVal [SymbolVal "fgd", SymbolVal co, e] : rest) -> next (acc <> fmap (fgd_ (color_ co)) (deep [e]), rest)
(acc, ListVal [SymbolVal "bgd", SymbolVal co, e] : rest) -> next (acc <> fmap (bgd_ (color_ co)) (deep [e]), rest)
(acc, ListVal [ SymbolVal "if", cond
, ListVal (SymbolVal "then" : then_)
, ListVal (SymbolVal "else" : else_)
] : rest) -> do
let r = case cond of
ListVal [SymbolVal "~", StringLike p, evaluated -> Just x] ->
Text.isPrefixOf (Text.pack p) x
_ -> False
next (acc <> if r then deep then_ else deep else_, rest)
(acc, ListVal es : rest) -> next (acc <> deep es, rest)
(acc, e : rest) -> next (acc <> p e, rest)
(acc, []) -> acc
where
evaluated :: (IsContext c, Data (Context c), Data c) => Syntax c -> Maybe Text
evaluated what = Just (deep' [what] & Text.concat)
color_ = \case
"black" -> Just Black
"red" -> Just Red
@ -360,9 +377,14 @@ instance FixmeRenderTemplate SimpleTemplate (Doc AnsiStyle) where
n = fromIntegral n0
s = mconcat s0
-- deep :: forall c . (IsContext c, Data (Context c), Data c) => [Syntax c] -> [Text]
deep :: forall c . (IsContext c, Data (Context c), Data c) => [Syntax c] -> [Doc AnsiStyle]
deep sy = either mempty List.singleton (render (SimpleTemplate sy))
deep' :: forall c . (IsContext c, Data (Context c), Data c) => [Syntax c] -> [Text]
deep' sy = do
let what = deep sy
[ Text.pack (show x) | x <- what]
nl = [ line ]
txt s = [fromString s]
p e = untxt [Text.pack (show $ pretty e)]