From 77357335a3a88a4b93f91a46ab939a1a9b192977 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 6 Jan 2022 14:41:42 +0100 Subject: RenderTreeView.renderFrom: admit
--- much.cabal | 2 +- src/Much/RenderTreeView.hs | 25 +++++++++++++++++++------ 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 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 -- cgit v1.2.3