on master help sign in
Add support for strikethrough mode

This change adds a new 'strikethrough' Style value and uses the 'smxx' and 'rmxx' Terminfo capabilities to activate and deactivate strikethrough mode, respectively. If the terminfo does not report those capabilities, this style is ignored. For details, see https://invisible-island.net/xterm/terminfo-contents.html#tic-ecma_strikeout

commit1dc2379e3c5b973d4527747d92648662fd5f04d7 authorJonathan Daugherty <cygnus@foobox.com> dateWed 30 Sep 2020, 12:45 (6 years ago) parent90ea183
3 files changed+32−3
src/Graphics/Vty/Attributes.hs+6−2 src/Graphics/Vty/DisplayAttributes.hs+3 src/Graphics/Vty/Output/TerminfoBased.hs+23−1
src/Graphics/Vty/Attributes.hs+6−2
@@ -43,6 +43,7 @@ module Graphics.Vty.Attributes
4343 , withStyle
4444 , standout
4545 , italic
46+ , strikethrough
4647 , underline
4748 , reverseVideo
4849 , blink
@@ -181,7 +182,7 @@ instance Eq v => Monoid ( MaybeDefault v ) where
181182-- if the style attribute should not be applied.
182183type Style = Word8
183184
184−-- | The 7 possible style attributes:
185+-- | Valid style attributes include:
185186--
186187-- * standout
187188--
@@ -197,9 +198,11 @@ type Style = Word8
197198--
198199-- * italic
199200--
201+-- * strikethrough (via the smxx/rmxx terminfo capabilities)
202+--
200203-- (The invisible, protect, and altcharset display attributes some
201204-- terminals support are not supported via VTY.)
202−standout, underline, reverseVideo, blink, dim, bold, italic :: Style
205+standout, underline, reverseVideo, blink, dim, bold, italic, strikethrough :: Style
203206standout = 0x01
204207underline = 0x02
205208reverseVideo = 0x04
@@ -207,6 +210,7 @@ blink = 0x08
207210dim = 0x10
208211bold = 0x20
209212italic = 0x40
213+strikethrough = 0x80
210214
211215defaultStyleMask :: Style
212216defaultStyleMask = 0x00
src/Graphics/Vty/DisplayAttributes.hs+3
@@ -96,6 +96,8 @@ data StyleStateChange
9696 | RemoveStandout
9797 | ApplyItalic
9898 | RemoveItalic
99+ | ApplyStrikethrough
100+ | RemoveStrikethrough
99101 | ApplyUnderline
100102 | RemoveUnderline
101103 | ApplyReverseVideo
@@ -144,6 +146,7 @@ diffStyles prev cur
144146 [ styleDiff standout ApplyStandout RemoveStandout
145147 , styleDiff underline ApplyUnderline RemoveUnderline
146148 , styleDiff italic ApplyItalic RemoveItalic
149+ , styleDiff strikethrough ApplyStrikethrough RemoveStrikethrough
147150 , styleDiff reverseVideo ApplyReverseVideo RemoveReverseVideo
148151 , styleDiff blink ApplyBlink RemoveBlink
149152 , styleDiff dim ApplyDim RemoveDim
src/Graphics/Vty/Output/TerminfoBased.hs+23−1
@@ -68,6 +68,8 @@ data DisplayAttrCaps = DisplayAttrCaps
6868 , exitStandout :: Maybe CapExpression
6969 , enterItalic :: Maybe CapExpression
7070 , exitItalic :: Maybe CapExpression
71+ , enterStrikethrough :: Maybe CapExpression
72+ , exitStrikethrough :: Maybe CapExpression
7173 , enterUnderline :: Maybe CapExpression
7274 , exitUnderline :: Maybe CapExpression
7375 , enterReverseVideo :: Maybe CapExpression
@@ -235,6 +237,8 @@ currentDisplayAttrCaps ti
235237 <*> probeCap ti "rmso"
236238 <*> probeCap ti "sitm"
237239 <*> probeCap ti "ritm"
240+ <*> probeCap ti "smxx"
241+ <*> probeCap ti "rmxx"
238242 <*> probeCap ti "smul"
239243 <*> probeCap ti "rmul"
240244 <*> probeCap ti "rev"
@@ -270,7 +274,11 @@ terminfoDisplayContext tActual terminfoCaps r = return dc
270274 , writeSetAttr = terminfoWriteSetAttr dc terminfoCaps
271275 , writeDefaultAttr = \urlsEnabled ->
272276 writeCapExpr (setDefaultAttr terminfoCaps) [] `mappend`
273− (if urlsEnabled then writeURLEscapes EndLink else mempty)
277+ (if urlsEnabled then writeURLEscapes EndLink else mempty) `mappend`
278+ (case exitStrikethrough $ displayAttrCaps terminfoCaps of
279+ Just cap -> writeCapExpr cap []
280+ Nothing -> mempty
281+ )
274282 , writeRowEnd = writeCapExpr (clearEol terminfoCaps) []
275283 , inlineHack = return ()
276284 }
@@ -348,6 +356,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
348356 )
349357 (sgrArgsForState state)
350358 `mappend` setItalics
359+ `mappend` setStrikethrough
351360 `mappend` setColors
352361 -- Otherwise the display colors are not changing or changing
353362 -- between two non-default points.
@@ -375,6 +384,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
375384 )
376385 (sgrArgsForState state)
377386 `mappend` setItalics
387+ `mappend` setStrikethrough
378388 `mappend` setColors
379389 where
380390 urlAttrs True = writeURLEscapes (urlDiff diffs)
@@ -392,6 +402,11 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
392402 , Just sitm <- enterItalic (displayAttrCaps terminfoCaps)
393403 = writeCapExpr sitm []
394404 | otherwise = mempty
405+ setStrikethrough
406+ | hasStyle (fixedStyle attr) strikethrough
407+ , Just smxx <- enterStrikethrough (displayAttrCaps terminfoCaps)
408+ = writeCapExpr smxx []
409+ | otherwise = mempty
395410 setColors =
396411 (case fixedForeColor attr of
397412 Just c -> writeCapExpr (setForeColor terminfoCaps)
@@ -460,6 +475,7 @@ data DisplayAttrState = DisplayAttrState
460475 { applyStandout :: Bool
461476 , applyUnderline :: Bool
462477 , applyItalic :: Bool
478+ , applyStrikethrough :: Bool
463479 , applyReverseVideo :: Bool
464480 , applyBlink :: Bool
465481 , applyDim :: Bool
@@ -496,6 +512,8 @@ reqDisplayCapSeqFor caps s diffs
496512 -- set state cap then just use the set state cap.
497513 ( True, True ) -> SetState $ stateForStyle s
498514 where
515+ noEnterExitCap ApplyStrikethrough = isNothing $ enterStrikethrough caps
516+ noEnterExitCap RemoveStrikethrough = isNothing $ exitStrikethrough caps
499517 noEnterExitCap ApplyItalic = isNothing $ enterItalic caps
500518 noEnterExitCap RemoveItalic = isNothing $ exitItalic caps
501519 noEnterExitCap ApplyStandout = isNothing $ enterStandout caps
@@ -510,6 +528,8 @@ reqDisplayCapSeqFor caps s diffs
510528 noEnterExitCap RemoveDim = True
511529 noEnterExitCap ApplyBold = isNothing $ enterBoldMode caps
512530 noEnterExitCap RemoveBold = True
531+ enterExitCap ApplyStrikethrough = fromJust $ enterStrikethrough caps
532+ enterExitCap RemoveStrikethrough = fromJust $ exitStrikethrough caps
513533 enterExitCap ApplyItalic = fromJust $ enterItalic caps
514534 enterExitCap RemoveItalic = fromJust $ exitItalic caps
515535 enterExitCap ApplyStandout = fromJust $ enterStandout caps
@@ -526,6 +546,7 @@ stateForStyle s = DisplayAttrState
526546 { applyStandout = isStyleSet standout
527547 , applyUnderline = isStyleSet underline
528548 , applyItalic = isStyleSet italic
549+ , applyStrikethrough = isStyleSet strikethrough
529550 , applyReverseVideo = isStyleSet reverseVideo
530551 , applyBlink = isStyleSet blink
531552 , applyDim = isStyleSet dim
@@ -538,6 +559,7 @@ styleToApplySeq s = concat
538559 [ applyIfRequired ApplyStandout standout
539560 , applyIfRequired ApplyUnderline underline
540561 , applyIfRequired ApplyItalic italic
562+ , applyIfRequired ApplyStrikethrough strikethrough
541563 , applyIfRequired ApplyReverseVideo reverseVideo
542564 , applyIfRequired ApplyBlink blink
543565 , applyIfRequired ApplyDim dim