diff options
author | Steve Mokris <smokris@softpixel.com> | 2014-07-04 15:40:16 -0400 |
---|---|---|
committer | Steve Mokris <smokris@softpixel.com> | 2014-07-08 15:21:39 +0200 |
commit | e5ae8f0062344cb3463d609276812a3d8c29c297 (patch) | |
tree | b22f0322911eb967b920870a7aae29c793bc14f1 /src/libs | |
parent | ca59e8b53af771a4f9900afedf7d2656f22c0f11 (diff) | |
download | qt-creator-e5ae8f0062344cb3463d609276812a3d8c29c297.tar.gz |
ANSI: Add 256-color escape sequences support
Task-number: QTCREATORBUG-12623
Change-Id: If2f3168a77b366aae570b48f5070e85087fe76a6
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/utils/ansiescapecodehandler.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/libs/utils/ansiescapecodehandler.cpp b/src/libs/utils/ansiescapecodehandler.cpp index 14d5dd8f8e..f2db87cc95 100644 --- a/src/libs/utils/ansiescapecodehandler.cpp +++ b/src/libs/utils/ansiescapecodehandler.cpp @@ -168,9 +168,11 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input break; case RgbTextColor: case RgbBackgroundColor: + // See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors if (++i >= numbers.size()) break; - if (numbers.at(i).toInt() == 2) { + switch (numbers.at(i).toInt()) { + case 2: // RGB set with format: 38;2;<r>;<g>;<b> if ((i + 3) < numbers.size()) { (code == RgbTextColor) ? @@ -183,10 +185,36 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input setFormatScope(charFormat); } i += 3; - } else if (numbers.at(i).toInt() == 5) { - // rgb set with format: 38;5;<i> - // unsupported because of unclear documentation, so we just skip <i> + break; + case 5: + // 256 color mode with format: 38;5;<i> + uint index = numbers.at(i + 1).toInt(); + + QColor color; + if (index < 8) { + // The first 8 colors are standard low-intensity ANSI colors. + color = ansiColor(index); + } else if (index < 16) { + // The next 8 colors are standard high-intensity ANSI colors. + color = ansiColor(index - 8).lighter(150); + } else if (index < 232) { + // The next 216 colors are a 6x6x6 RGB cube. + uint o = index - 16; + color = QColor((o / 36) * 51, ((o / 6) % 6) * 51, (o % 6) * 51); + } else { + // The last 24 colors are a greyscale gradient. + uint grey = (index - 232) * 11; + color = QColor(grey, grey, grey); + } + + if (code == RgbTextColor) + charFormat.setForeground(color); + else + charFormat.setBackground(color); + + setFormatScope(charFormat); ++i; + break; } break; default: |