summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2022-01-06 14:41:42 +0100
committertv <tv@krebsco.de>2022-01-06 14:45:50 +0100
commit77357335a3a88a4b93f91a46ab939a1a9b192977 (patch)
tree4b69e0db30fe7c93c272bfaff7f54b24bf00e8d4
parent29749366052a8f6c05b314f1ff17201717855ad7 (diff)
RenderTreeView.renderFrom: admit <address>1.3.1
-rw-r--r--much.cabal2
-rw-r--r--src/Much/RenderTreeView.hs25
2 files changed, 20 insertions, 7 deletions
diff --git a/much.cabal b/much.cabal
index 352e8ff..75f633d 100644
--- a/much.cabal
+++ b/much.cabal
@@ -1,5 +1,5 @@
name: much
-version: 1.2.0
+version: 1.3.1
license: MIT
author: tv <tv@krebsco.de>
maintainer: tv@krebsco.de
diff --git a/src/Much/RenderTreeView.hs b/src/Much/RenderTreeView.hs
index 6babb29..ebed6e0 100644
--- a/src/Much/RenderTreeView.hs
+++ b/src/Much/RenderTreeView.hs
@@ -212,8 +212,13 @@ renderDate now = \case
renderFrom :: Maybe T.Text -> Blessings String
renderFrom = \case
- Just fromLine -> Plain $ dropAddress $ T.unpack fromLine
- Nothing -> SGR [35,1] "Anonymous"
+ Just fromLine ->
+ Plain $
+ case readFrom (T.unpack fromLine) of
+ ("", address) -> address
+ (name, _) -> name
+ Nothing ->
+ SGR [35,1] "Anonymous"
renderTags :: State -> [Tag] -> Blessings String
@@ -230,8 +235,16 @@ renderTag state tag = case M.lookup tag $ runIdentity $ tagMap $ colorConfig sta
plain = Plain $ T.unpack $ fromMaybe tag $ M.lookup tag (aliases state)
-dropAddress :: String -> String
-dropAddress xs =
+readFrom :: String -> (String, String)
+readFrom xs =
case L.elemIndices '<' xs of
- [] -> xs
- is -> L.dropWhileEnd isSpace $ take (last is) xs
+ [] ->
+ ("", xs)
+ is ->
+ readName *** readAddress $ splitAt (last is - 1) xs
+ where
+ readAddress :: String -> String
+ readAddress = L.takeWhile (/='>') . dropWhile (=='<')
+
+ readName :: String -> String
+ readName = L.dropWhileEnd isSpace