summaryrefslogtreecommitdiffstats
path: root/src/Blessings.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blessings.hs')
-rw-r--r--src/Blessings.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/Blessings.hs b/src/Blessings.hs
index 753b560..7565299 100644
--- a/src/Blessings.hs
+++ b/src/Blessings.hs
@@ -84,6 +84,22 @@ instance IsPm BColor where
. filterPm sgrFColor
+data Blink = Blink | NoBlink
+ deriving (Eq, Show)
+
+instance IsPm Blink where
+ toPm Blink = [5]
+ toPm NoBlink = [25]
+ fromPm = rec . filterPm sgrColor
+ where
+ rec xs = case filter (`elem` ([5,25] :: [Int])) xs of
+ [] -> Nothing
+ xs' -> case last xs' of
+ 5 -> Just Blink
+ 25 -> Just NoBlink
+ _ -> error "filter broken in fromPm :: Pm -> Maybe Blink"
+
+
data Bold = Bold | NoBold
deriving (Eq, Show)
@@ -167,30 +183,32 @@ sgrBColor (48:2:_) = Just 5
sgrBColor _ = Nothing
-type RenderState = [(FColor, BColor, Bold, Underline)]
+type RenderState = [(FColor, BColor, Blink, Bold, Underline)]
emptyRenderState :: RenderState
-emptyRenderState = [(ECMA48FColor 39, ECMA48BColor 49, NoBold, NoUnderline)]
+emptyRenderState = [(ECMA48FColor 39, ECMA48BColor 49, NoBlink, NoBold, NoUnderline)]
renderString :: RenderState -> Blessings String -> String -> String
renderString _ (Plain s) y = s ++ y
-- TODO merge successive sequences: \ESC[32m\ESC[1m -> \ESC[31;1m
-renderString rs@((fc, bc, b, u):_) (SGR c t) y =
+renderString rs@((fc, bc, bl, b, u):_) (SGR c t) y =
renderSGR bra ++ renderString rs' t (renderSGR ket ++ y)
where
fc' = maybe fc id $ fromPm c
bc' = maybe bc id $ fromPm c
+ bl' = maybe bl id $ fromPm c
b' = maybe b id $ fromPm c
u' = maybe u id $ fromPm c
- rs' = (fc', bc', b', u') : rs
+ rs' = (fc', bc', bl', b', u') : rs
bra = braket >>= fst
ket = braket >>= snd
braket =
(if fc' /= fc then (toPm fc', toPm fc) else ([],[])) :
(if bc' /= bc then (toPm bc', toPm bc) else ([],[])) :
+ (if bl' /= bl then (toPm bl', toPm bl) else ([],[])) :
(if b' /= b then (toPm b', toPm b) else ([],[])) :
(if u' /= u then (toPm u', toPm u) else ([],[])) : []