summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Blessings.hs30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/Blessings.hs b/src/Blessings.hs
index e8dfa82..b942565 100644
--- a/src/Blessings.hs
+++ b/src/Blessings.hs
@@ -309,6 +309,31 @@ normalize = \case
Empty -> Empty
+normalizeHead :: (Eq a, Monoid a) => Blessings a -> Blessings a
+normalizeHead = \case
+ Append Empty t -> normalizeHead t
+ Append t1 t2 ->
+ let
+ t1' = normalizeHead t1
+ in
+ if t1' == Empty
+ then normalizeHead t2
+ else Append t1' t2
+ SGR _ Empty -> Empty
+ SGR [] t -> normalizeHead t
+ SGR pm t ->
+ let
+ pm' = normalizePm pm
+ t' = normalizeHead t
+ in
+ if pm' == []
+ then t'
+ else SGR pm' t'
+ Plain x | x == mempty -> Empty
+ t@(Plain _) -> t
+ Empty -> Empty
+
+
data NormalizedPm
= NormalizedPm
{ foregroundColor :: [Word8]
@@ -366,11 +391,8 @@ instance (Eq a, Blessable a) => Blessable (Blessings a) where
n2 = n - n1
t1' = Bless.drop n1 t1
t2' = Bless.drop n2 t2
- isEmpty = (==0) . Bless.length . Bless.take 1
in
- if n1 /= n || isEmpty t1'
- then t2'
- else Append t1' t2'
+ normalizeHead $ Append t1' t2'
Plain s ->
normalize $ Plain (Bless.drop n s)
SGR pm t ->