Skip to content

Commit e5de789

Browse files
committed
Add strikeout support
1 parent ca04fa2 commit e5de789

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/Text/DocLayout.hs

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module Text.DocLayout (
5959
, bold
6060
, italic
6161
, underlined
62+
, strikeout
6263
, fg
6364
, bg
6465
, Color
@@ -786,6 +787,9 @@ italic = styled (RShape Italic)
786787
underlined :: HasChars a => Doc a -> Doc a
787788
underlined = styled (RUnderline ULSingle)
788789

790+
strikeout :: HasChars a => Doc a -> Doc a
791+
strikeout = styled (RStrikeout Struck)
792+
789793
-- The Color type is here as an opaque alias to Color8 for the public interface
790794
-- and there's trivial smart constructors for the individual colors to
791795
-- hopefully allow for easier extension to supporting indexed and rgb colors in

src/Text/DocLayout/ANSIFont.hs

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Text.DocLayout.ANSIFont
88
, Shape(..)
99
, Color8(..)
1010
, Underline(..)
11+
, Strikeout(..)
1112
, Foreground(..)
1213
, Background(..)
1314
, (~>)
@@ -23,24 +24,31 @@ data Font = Font
2324
{ ftWeight :: Weight,
2425
ftShape :: Shape,
2526
ftUnderline :: Underline,
27+
ftStrikeout :: Strikeout,
2628
ftForeground :: Foreground,
2729
ftBackground :: Background,
2830
ftLink :: Maybe Text
2931
}
3032
deriving (Show, Eq, Read, Data, Ord)
3133

3234
baseFont :: Font
33-
baseFont = Font Normal Roman ULNone FGDefault BGDefault Nothing
35+
baseFont = Font Normal Roman ULNone Unstruck FGDefault BGDefault Nothing
3436

3537
data Weight = Normal | Bold deriving (Show, Eq, Read, Data, Ord)
3638
data Shape = Roman | Italic deriving (Show, Eq, Read, Data, Ord)
3739
data Color8 = Black | Red | Green | Yellow | Blue | Magenta | Cyan | White deriving (Show, Eq, Enum, Read, Data, Ord)
3840
data Underline = ULNone | ULSingle | ULDouble | ULCurly deriving (Show, Eq, Read, Data, Ord)
41+
data Strikeout = Unstruck | Struck deriving (Show, Eq, Read, Data, Ord)
3942
data Foreground = FGDefault | FG Color8 deriving (Show, Eq, Read, Data, Ord)
4043
data Background = BGDefault | BG Color8 deriving (Show, Eq, Read, Data, Ord)
4144

42-
data StyleReq =
43-
RWeight Weight | RShape Shape | RForeground Foreground | RBackground Background | RUnderline Underline
45+
data StyleReq
46+
= RWeight Weight
47+
| RShape Shape
48+
| RForeground Foreground
49+
| RBackground Background
50+
| RUnderline Underline
51+
| RStrikeout Strikeout
4452
deriving (Show, Eq, Read, Data, Ord)
4553

4654
(~>) :: Font -> StyleReq -> Font
@@ -49,6 +57,7 @@ data StyleReq =
4957
(~>) f (RForeground c) = f{ftForeground = c}
5058
(~>) f (RBackground c) = f{ftBackground = c}
5159
(~>) f (RUnderline u) = f{ftUnderline = u}
60+
(~>) f (RStrikeout u) = f{ftStrikeout = u}
5261

5362
rawSGR :: (Semigroup a, IsString a) => a -> a
5463
rawSGR n = "\ESC[" <> n <> "m"
@@ -78,6 +87,10 @@ instance SGR Underline where
7887
renderSGR ULDouble = rawSGR "21"
7988
renderSGR ULCurly = rawSGR "4:3"
8089

90+
instance SGR Strikeout where
91+
renderSGR Unstruck = rawSGR "29"
92+
renderSGR Struck = rawSGR "9"
93+
8194
renderFont :: (Semigroup a, IsString a) => Font -> a
8295
renderFont f
8396
| f == baseFont = rawSGR "0"
@@ -87,6 +100,7 @@ renderFont f
87100
<> renderSGR (ftForeground f)
88101
<> renderSGR (ftBackground f)
89102
<> renderSGR (ftUnderline f)
103+
<> renderSGR (ftStrikeout f)
90104

91105
renderOSC8 :: (Semigroup a, IsString a) => Maybe a -> a
92106
renderOSC8 Nothing = "\ESC]8;;\ESC\\"

0 commit comments

Comments
 (0)