on master help sign in
Fix SGR command after italics change

SGR doesn't control italics. If we're updating the terminal style using SGR and italics are needed the enter sequence will have to be added after the SGR command.

commit7a38067b38ab961600e5186a070578f856f3379c authorEric Mertens <emertens@gmail.com> dateFri 27 Jul 2018, 21:11 (8 years ago) parent181a5d7
2 files changed+16−7
src/Graphics/Vty/Attributes.hs+2−2 src/Graphics/Vty/Output/TerminfoBased.hs+14−5
src/Graphics/Vty/Attributes.hs+2−2
@@ -175,7 +175,7 @@ instance Eq v => Monoid ( MaybeDefault v ) where
175175-- if the style attribute should not be applied.
176176type Style = Word8
177177
178−-- | The 6 possible style attributes:
178+-- | The 7 possible style attributes:
179179--
180180-- * standout
181181--
@@ -196,7 +196,7 @@ type Style = Word8
196196standout, underline, reverseVideo, blink, dim, bold, italic :: Style
197197standout = 0x01
198198underline = 0x02
199−reverseVideo = 0x04
199+reverseVideo = 0x04
200200blink = 0x08
201201dim = 0x10
202202bold = 0x20
src/Graphics/Vty/Output/TerminfoBased.hs+14−5
@@ -315,7 +315,7 @@ writeURLEscapes NoLinkChange =
315315-- Note that this optimizes for fewer state changes followed by fewer
316316-- bytes.
317317terminfoWriteSetAttr :: DisplayContext -> TerminfoCaps -> Bool -> FixedAttr -> Attr -> DisplayAttrDiff -> Write
318−terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs = do
318+terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs =
319319 urlAttrs urlsEnabled `mappend` case (foreColorDiff diffs == ColorToDefault) || (backColorDiff diffs == ColorToDefault) of
320320 -- The only way to reset either color, portably, to the default
321321 -- is to use either the set state capability or the set default
@@ -336,8 +336,8 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs = do
336336 $ terminfoCaps
337337 )
338338 (sgrArgsForState state)
339− `mappend`
340− setColors
339+ `mappend` setItalics
340+ `mappend` setColors
341341 -- Otherwise the display colors are not changing or changing
342342 -- between two non-default points.
343343 False -> do
@@ -363,6 +363,7 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs = do
363363 $ displayAttrCaps terminfoCaps
364364 )
365365 (sgrArgsForState state)
366+ `mappend` setItalics
366367 `mappend` setColors
367368 where
368369 urlAttrs True = writeURLEscapes (urlDiff diffs)
@@ -371,6 +372,15 @@ terminfoWriteSetAttr dc terminfoCaps urlsEnabled prevAttr reqAttr diffs = do
371372 False -> ansiColorIndex
372373 True -> altColorIndex
373374 attr = fixDisplayAttr prevAttr reqAttr
375+
376+ -- italics can't be set via SGR, so here we manually
377+ -- apply the enter and exit sequences as needed after
378+ -- changing the SGR
379+ setItalics
380+ | hasStyle (fixedStyle attr) italic
381+ , Just sitm <- enterItalic (displayAttrCaps terminfoCaps)
382+ = writeCapExpr sitm []
383+ | otherwise = mempty
374384 setColors =
375385 (case fixedForeColor attr of
376386 Just c -> writeCapExpr (setForeColor terminfoCaps)
@@ -449,7 +459,6 @@ sgrArgsForState :: DisplayAttrState -> [CapParam]
449459sgrArgsForState attrState = map (\b -> if b then 1 else 0)
450460 [ applyStandout attrState
451461 , applyUnderline attrState
452− , applyItalic attrState
453462 , applyReverseVideo attrState
454463 , applyBlink attrState
455464 , applyDim attrState
@@ -521,7 +530,7 @@ styleToApplySeq s = concat
521530 , applyIfRequired ApplyReverseVideo reverseVideo
522531 , applyIfRequired ApplyBlink blink
523532 , applyIfRequired ApplyDim dim
524− , applyIfRequired ApplyBlink bold
533+ , applyIfRequired ApplyBold bold
525534 ]
526535 where
527536 applyIfRequired op flag