Add support for italicized output when terminfo supports it

This commit is contained in:
Jonathan Daugherty 2018-07-27 13:30:52 -07:00
parent bb68f7ae05
commit e23742907a
3 changed files with 23 additions and 3 deletions

View File

@ -38,6 +38,7 @@ module Graphics.Vty.Attributes
, Style , Style
, withStyle , withStyle
, standout , standout
, italic
, underline , underline
, reverseVideo , reverseVideo
, blink , blink
@ -103,14 +104,15 @@ data Attr = Attr
-- __ - unused -- __ - unused
-- --
-- Next is the style flags -- Next is the style flags
-- SURBDO__ -- SURBDOI_
-- S - standout -- S - standout
-- U - underline -- U - underline
-- R - reverse video -- R - reverse video
-- B - blink -- B - blink
-- D - dim -- D - dim
-- O - bold -- O - bold
-- __ - unused -- I - italic
-- _ - unused
-- --
-- Then the foreground color encoded into 8 bits. -- Then the foreground color encoded into 8 bits.
-- Then the background color encoded into 8 bits. -- Then the background color encoded into 8 bits.
@ -187,15 +189,18 @@ type Style = Word8
-- --
-- * bold/bright -- * bold/bright
-- --
-- * italic
--
-- (The invisible, protect, and altcharset display attributes some -- (The invisible, protect, and altcharset display attributes some
-- terminals support are not supported via VTY.) -- terminals support are not supported via VTY.)
standout, underline, reverseVideo, blink, dim, bold :: Style standout, underline, reverseVideo, blink, dim, bold, italic :: Style
standout = 0x01 standout = 0x01
underline = 0x02 underline = 0x02
reverseVideo = 0x04 reverseVideo = 0x04
blink = 0x08 blink = 0x08
dim = 0x10 dim = 0x10
bold = 0x20 bold = 0x20
italic = 0x40
defaultStyleMask :: Style defaultStyleMask :: Style
defaultStyleMask = 0x00 defaultStyleMask = 0x00

View File

@ -94,6 +94,8 @@ data DisplayColorDiff
data StyleStateChange data StyleStateChange
= ApplyStandout = ApplyStandout
| RemoveStandout | RemoveStandout
| ApplyItalic
| RemoveItalic
| ApplyUnderline | ApplyUnderline
| RemoveUnderline | RemoveUnderline
| ApplyReverseVideo | ApplyReverseVideo
@ -141,6 +143,7 @@ diffStyles prev cur
= mconcat = mconcat
[ styleDiff standout ApplyStandout RemoveStandout [ styleDiff standout ApplyStandout RemoveStandout
, styleDiff underline ApplyUnderline RemoveUnderline , styleDiff underline ApplyUnderline RemoveUnderline
, styleDiff italic ApplyItalic RemoveItalic
, styleDiff reverseVideo ApplyReverseVideo RemoveReverseVideo , styleDiff reverseVideo ApplyReverseVideo RemoveReverseVideo
, styleDiff blink ApplyBlink RemoveBlink , styleDiff blink ApplyBlink RemoveBlink
, styleDiff dim ApplyDim RemoveDim , styleDiff dim ApplyDim RemoveDim

View File

@ -62,6 +62,8 @@ data DisplayAttrCaps = DisplayAttrCaps
{ setAttrStates :: Maybe CapExpression { setAttrStates :: Maybe CapExpression
, enterStandout :: Maybe CapExpression , enterStandout :: Maybe CapExpression
, exitStandout :: Maybe CapExpression , exitStandout :: Maybe CapExpression
, enterItalic :: Maybe CapExpression
, exitItalic :: Maybe CapExpression
, enterUnderline :: Maybe CapExpression , enterUnderline :: Maybe CapExpression
, exitUnderline :: Maybe CapExpression , exitUnderline :: Maybe CapExpression
, enterReverseVideo :: Maybe CapExpression , enterReverseVideo :: Maybe CapExpression
@ -227,6 +229,8 @@ currentDisplayAttrCaps ti
<*> probeCap ti "sgr" <*> probeCap ti "sgr"
<*> probeCap ti "smso" <*> probeCap ti "smso"
<*> probeCap ti "rmso" <*> probeCap ti "rmso"
<*> probeCap ti "sitm"
<*> probeCap ti "ritm"
<*> probeCap ti "smul" <*> probeCap ti "smul"
<*> probeCap ti "rmul" <*> probeCap ti "rmul"
<*> probeCap ti "rev" <*> probeCap ti "rev"
@ -434,6 +438,7 @@ data DisplayAttrSeq
data DisplayAttrState = DisplayAttrState data DisplayAttrState = DisplayAttrState
{ applyStandout :: Bool { applyStandout :: Bool
, applyUnderline :: Bool , applyUnderline :: Bool
, applyItalic :: Bool
, applyReverseVideo :: Bool , applyReverseVideo :: Bool
, applyBlink :: Bool , applyBlink :: Bool
, applyDim :: Bool , applyDim :: Bool
@ -444,6 +449,7 @@ sgrArgsForState :: DisplayAttrState -> [CapParam]
sgrArgsForState attrState = map (\b -> if b then 1 else 0) sgrArgsForState attrState = map (\b -> if b then 1 else 0)
[ applyStandout attrState [ applyStandout attrState
, applyUnderline attrState , applyUnderline attrState
, applyItalic attrState
, applyReverseVideo attrState , applyReverseVideo attrState
, applyBlink attrState , applyBlink attrState
, applyDim attrState , applyDim attrState
@ -470,6 +476,8 @@ reqDisplayCapSeqFor caps s diffs
-- set state cap then just use the set state cap. -- set state cap then just use the set state cap.
( True, True ) -> SetState $ stateForStyle s ( True, True ) -> SetState $ stateForStyle s
where where
noEnterExitCap ApplyItalic = isNothing $ enterItalic caps
noEnterExitCap RemoveItalic = isNothing $ exitItalic caps
noEnterExitCap ApplyStandout = isNothing $ enterStandout caps noEnterExitCap ApplyStandout = isNothing $ enterStandout caps
noEnterExitCap RemoveStandout = isNothing $ exitStandout caps noEnterExitCap RemoveStandout = isNothing $ exitStandout caps
noEnterExitCap ApplyUnderline = isNothing $ enterUnderline caps noEnterExitCap ApplyUnderline = isNothing $ enterUnderline caps
@ -482,6 +490,8 @@ reqDisplayCapSeqFor caps s diffs
noEnterExitCap RemoveDim = True noEnterExitCap RemoveDim = True
noEnterExitCap ApplyBold = isNothing $ enterBoldMode caps noEnterExitCap ApplyBold = isNothing $ enterBoldMode caps
noEnterExitCap RemoveBold = True noEnterExitCap RemoveBold = True
enterExitCap ApplyItalic = fromJust $ enterItalic caps
enterExitCap RemoveItalic = fromJust $ exitItalic caps
enterExitCap ApplyStandout = fromJust $ enterStandout caps enterExitCap ApplyStandout = fromJust $ enterStandout caps
enterExitCap RemoveStandout = fromJust $ exitStandout caps enterExitCap RemoveStandout = fromJust $ exitStandout caps
enterExitCap ApplyUnderline = fromJust $ enterUnderline caps enterExitCap ApplyUnderline = fromJust $ enterUnderline caps
@ -495,6 +505,7 @@ stateForStyle :: Style -> DisplayAttrState
stateForStyle s = DisplayAttrState stateForStyle s = DisplayAttrState
{ applyStandout = isStyleSet standout { applyStandout = isStyleSet standout
, applyUnderline = isStyleSet underline , applyUnderline = isStyleSet underline
, applyItalic = isStyleSet italic
, applyReverseVideo = isStyleSet reverseVideo , applyReverseVideo = isStyleSet reverseVideo
, applyBlink = isStyleSet blink , applyBlink = isStyleSet blink
, applyDim = isStyleSet dim , applyDim = isStyleSet dim
@ -506,6 +517,7 @@ styleToApplySeq :: Style -> [StyleStateChange]
styleToApplySeq s = concat styleToApplySeq s = concat
[ applyIfRequired ApplyStandout standout [ applyIfRequired ApplyStandout standout
, applyIfRequired ApplyUnderline underline , applyIfRequired ApplyUnderline underline
, applyIfRequired ApplyItalic italic
, applyIfRequired ApplyReverseVideo reverseVideo , applyIfRequired ApplyReverseVideo reverseVideo
, applyIfRequired ApplyBlink blink , applyIfRequired ApplyBlink blink
, applyIfRequired ApplyDim dim , applyIfRequired ApplyDim dim