xterm: draw strikethrough, concealed text, overline and underline styles
SGR 9 (strikethrough) and 53 (overline) were stored but never drawn, and SGR 8 (conceal) still showed the text. They are drawn now, and underline styles use the matching line style: double (21, 4:2), curly (4:3, wavy), dotted (4:4) and dashed (4:5). Concealed cells keep their background. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,4 +6,6 @@ abstract class CellFlags {
|
||||
static const blink = 1 << 4;
|
||||
static const inverse = 1 << 5;
|
||||
static const invisible = 1 << 6;
|
||||
static const strikethrough = 1 << 7;
|
||||
static const overline = 1 << 11;
|
||||
}
|
||||
|
||||
+27
-5
@@ -206,6 +206,9 @@ class TerminalPainter {
|
||||
final charCode = cellData.content & CellContent.codepointMask;
|
||||
if (charCode == 0) return;
|
||||
|
||||
// SGR 8 (conceal): the cell keeps its background, the text is hidden.
|
||||
if (cellData.flags & CellFlags.invisible != 0) return;
|
||||
|
||||
final cacheKey = cellData.getHash() ^ _textScaler.hashCode;
|
||||
var paragraph = _paragraphCache.getLayoutFromCache(cacheKey);
|
||||
|
||||
@@ -220,21 +223,27 @@ class TerminalPainter {
|
||||
color = color.withOpacity(0.5);
|
||||
}
|
||||
|
||||
final underline = cellFlags & CellFlags.underline != 0;
|
||||
const decorated =
|
||||
CellFlags.underline | CellFlags.strikethrough | CellFlags.overline;
|
||||
final style = _textStyle.toTextStyle(
|
||||
color: color,
|
||||
bold: cellFlags & CellFlags.bold != 0,
|
||||
italic: cellFlags & CellFlags.italic != 0,
|
||||
underline: cellFlags & CellFlags.underline != 0,
|
||||
underline: underline,
|
||||
strikethrough: cellFlags & CellFlags.strikethrough != 0,
|
||||
overline: cellFlags & CellFlags.overline != 0,
|
||||
decorationStyle: underline ? _underlineStyle(cellFlags) : null,
|
||||
);
|
||||
|
||||
// Flutter does not draw an underline below a space which is not between
|
||||
// Flutter does not draw a decoration on a space which is not between
|
||||
// other regular characters. As only single characters are drawn, this
|
||||
// will never produce an underline below a space in the terminal. As a
|
||||
// workaround the regular space CodePoint 0x20 is replaced with
|
||||
// the CodePoint 0xA0. This is a non breaking space and a underline can be
|
||||
// drawn below it.
|
||||
// the CodePoint 0xA0. This is a non breaking space and a decoration can
|
||||
// be drawn on it.
|
||||
var char = String.fromCharCode(charCode);
|
||||
if (cellFlags & CellFlags.underline != 0 && charCode == 0x20) {
|
||||
if (cellFlags & decorated != 0 && charCode == 0x20) {
|
||||
char = String.fromCharCode(0xA0);
|
||||
}
|
||||
|
||||
@@ -249,6 +258,19 @@ class TerminalPainter {
|
||||
canvas.drawParagraph(paragraph, offset);
|
||||
}
|
||||
|
||||
/// The line style of the underline in [flags] (SGR 4:1-4:5, 21).
|
||||
static TextDecorationStyle _underlineStyle(int flags) {
|
||||
final style =
|
||||
(flags & CellAttr.underlineStyleMask) >> CellAttr.underlineStyleShift;
|
||||
return switch (style) {
|
||||
2 => TextDecorationStyle.double,
|
||||
3 => TextDecorationStyle.wavy,
|
||||
4 => TextDecorationStyle.dotted,
|
||||
5 => TextDecorationStyle.dashed,
|
||||
_ => TextDecorationStyle.solid,
|
||||
};
|
||||
}
|
||||
|
||||
/// Paints the background of a cell represented by [cellData] to [canvas] at
|
||||
/// [offset].
|
||||
@pragma('vm:prefer-inline')
|
||||
|
||||
@@ -57,8 +57,12 @@ class TerminalStyle {
|
||||
bool bold = false,
|
||||
bool italic = false,
|
||||
bool underline = false,
|
||||
bool strikethrough = false,
|
||||
bool overline = false,
|
||||
TextDecorationStyle? decorationStyle,
|
||||
}) {
|
||||
return TextStyle(
|
||||
decorationStyle: decorationStyle,
|
||||
fontSize: fontSize,
|
||||
height: height,
|
||||
fontFamily: fontFamily,
|
||||
@@ -67,7 +71,11 @@ class TerminalStyle {
|
||||
backgroundColor: backgroundColor,
|
||||
fontWeight: bold ? FontWeight.bold : FontWeight.normal,
|
||||
fontStyle: italic ? FontStyle.italic : FontStyle.normal,
|
||||
decoration: underline ? TextDecoration.underline : TextDecoration.none,
|
||||
decoration: TextDecoration.combine([
|
||||
if (underline) TextDecoration.underline,
|
||||
if (strikethrough) TextDecoration.lineThrough,
|
||||
if (overline) TextDecoration.overline,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user