@@ -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