summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-01-01 23:53:30 +0100
committertv <tv@shackspace.de>2015-01-01 23:53:30 +0100
commit5d556b147a593f1b8c8127883055ad07ee347af9 (patch)
tree6697766faff1510492cb1c7f38c8fc1790838add
parent67aa6764bfafabda51eb270e01aaf0fc638f380f (diff)
colorize quoted lines
-rw-r--r--TreeView.hs20
-rw-r--r--TreeViewRaw.hs7
-rw-r--r--Utils.hs6
3 files changed, 32 insertions, 1 deletions
diff --git a/TreeView.hs b/TreeView.hs
index 4edf9b3..6397c4f 100644
--- a/TreeView.hs
+++ b/TreeView.hs
@@ -27,6 +27,7 @@ data TreeView
= TVMessage Message
| TVMessageHeaderField Message (CI.CI T.Text)
| TVMessagePart Message MessagePart
+ | TVMessageQuoteLine Message MessagePart LineNr String
| TVMessageLine Message MessagePart LineNr String
| TVSearch String
| TVSearchResult SearchResult
@@ -46,6 +47,9 @@ instance Eq TreeView where
TVMessageLine m1 mp1 ln1 _s1 == TVMessageLine m2 mp2 ln2 _s2 =
m1 == m2 && mp1 == mp2 && ln1 == ln2
+ TVMessageQuoteLine m1 mp1 ln1 _s1 == TVMessageQuoteLine m2 mp2 ln2 _s2 =
+ m1 == m2 && mp1 == mp2 && ln1 == ln2
+
TVSearch s1 == TVSearch s2 =
s1 == s2
@@ -60,6 +64,7 @@ getMessage = \case
TVMessage m -> Just m
TVMessageHeaderField m _ -> Just m
TVMessagePart m _ -> Just m
+ TVMessageQuoteLine m _ _ _ -> Just m
TVMessageLine m _ _ _ -> Just m
_ -> Nothing
@@ -127,4 +132,17 @@ xconvPart2 m p =
xconvLine
:: Message -> MessagePart -> (LineNr, T.Text) -> Tree TreeView
xconvLine m p (i, s) =
- Node (TVMessageLine m p i $ T.unpack s) []
+ Node (ctor m p i $ T.unpack s) []
+ where
+ ctor =
+ if isQuoteLine s
+ then TVMessageQuoteLine
+ else TVMessageLine
+
+
+isQuoteLine :: T.Text -> Bool
+isQuoteLine s0 = do
+ let s = T.stripStart s0
+
+ -- /^\s*>/
+ not (T.null s) && T.head s == '>'
diff --git a/TreeViewRaw.hs b/TreeViewRaw.hs
index ee3bd99..0ec747b 100644
--- a/TreeViewRaw.hs
+++ b/TreeViewRaw.hs
@@ -51,6 +51,7 @@ renderTreeView now cur _loc@(Node label children) =
searchSGR
, focusSGR
+ , quoteSGR
, boringSGR
, dateSGR
, tagsSGR
@@ -61,6 +62,7 @@ searchSGR
:: Trammel String -> Trammel String
searchSGR = SGR [38,5,162]
focusSGR = SGR [38,5,160]
+quoteSGR = SGR [38,5,242]
boringSGR = SGR [38,5,240]
dateSGR = SGR [38,5,071]
tagsSGR = SGR [38,5,036]
@@ -114,6 +116,11 @@ renderTreeView1 now hasFocus x = case x of
charset = maybe "" (Plain . (" "<>) . show) $ Notmuch.partContentCharset p
in c $ "part#" <> i <> " " <> t <> filename <> charset
+ TVMessageQuoteLine _ _ _ s ->
+ if hasFocus
+ then focusSGR $ Plain s
+ else quoteSGR $ Plain s
+
TVMessageLine _ _ _ s ->
if hasFocus
then focusSGR $ Plain s
diff --git a/Utils.hs b/Utils.hs
index 8d1f624..b0dcf87 100644
--- a/Utils.hs
+++ b/Utils.hs
@@ -21,3 +21,9 @@ padl n c s =
if length s < n
then padl n c (c:s)
else s
+
+padr :: Int -> a -> [a] -> [a]
+padr n c s =
+ if length s < n
+ then padr n c (s ++ [c])
+ else s