Add support for italic and strikethrough ANSI escape codes (#8048)

\e[3m -> italic
    \e[9m -> strikethrough

On terminals not supporting italic text, the text is shown in reverse instead,
and on terminals not supporting strikethrough text, the text is shown as is.
This commit is contained in:
Kaushal Modi 2018-06-17 12:37:41 -04:00 • committed by Varriount
commit 4616b28c7b

View file

@ -470,13 +470,15 @@ type
Style* = enum ## different styles for text output Style* = enum ## different styles for text output
styleBright = 1, ## bright text styleBright = 1, ## bright text
styleDim, ## dim text styleDim, ## dim text
styleUnknown, ## unknown styleItalic, ## italic (or reverse on terminals not supporting)
styleUnderscore = 4, ## underscored text styleUnderscore = 4, ## underscored text
styleBlink, ## blinking/bold text styleBlink, ## blinking/bold text
styleReverse = 7, ## unknown styleReverse = 7, ## reverse
styleHidden ## hidden text styleHidden ## hidden text
styleStrikethrough, ## strikethrough
{.deprecated: [TStyle: Style].} {.deprecated: [TStyle: Style].}
{.deprecated: [styleUnknown: styleItalic].}
when not defined(windows): when not defined(windows):
var var
@ -843,6 +845,7 @@ when not defined(testing) and isMainModule:
write(stdout, "never mind") write(stdout, "never mind")
stdout.eraseLine() stdout.eraseLine()
stdout.styledWriteLine("styled text ", {styleBright, styleBlink, styleUnderscore}) stdout.styledWriteLine("styled text ", {styleBright, styleBlink, styleUnderscore})
stdout.styledWriteLine("italic text ", {styleItalic})
stdout.setBackGroundColor(bgCyan, true) stdout.setBackGroundColor(bgCyan, true)
stdout.setForeGroundColor(fgBlue) stdout.setForeGroundColor(fgBlue)
stdout.writeLine("ordinary text") stdout.writeLine("ordinary text")