forked from qt-creator/qt-creator
ANSI: Simplify escape sequence
Change-Id: I0088a922af7723aabb6751ac80af39467d4cfb0b Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
f1f1f65f7c
commit
61eb23082b
@@ -77,7 +77,7 @@ QList<StringFormatPair> AnsiEscapeCodeHandler::parseText(const QString &text,
|
|||||||
|
|
||||||
QTextCharFormat charFormat = m_previousFormatClosed ? defaultFormat : m_previousFormat;
|
QTextCharFormat charFormat = m_previousFormatClosed ? defaultFormat : m_previousFormat;
|
||||||
|
|
||||||
const QString escape = QChar::fromLatin1(27) + QLatin1Char('[');
|
const QString escape = QLatin1String("\x1b[");
|
||||||
if (!text.contains(escape)) {
|
if (!text.contains(escape)) {
|
||||||
outputData << StringFormatPair(text, charFormat);
|
outputData << StringFormatPair(text, charFormat);
|
||||||
return outputData;
|
return outputData;
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ Q_DECLARE_METATYPE(QTextCharFormat);
|
|||||||
Q_DECLARE_METATYPE(StringFormatPair);
|
Q_DECLARE_METATYPE(StringFormatPair);
|
||||||
Q_DECLARE_METATYPE(ResultList);
|
Q_DECLARE_METATYPE(ResultList);
|
||||||
|
|
||||||
|
static QString ansiEscape(const QByteArray &sequence)
|
||||||
|
{
|
||||||
|
return QString::fromLatin1("\x1b[" + sequence);
|
||||||
|
}
|
||||||
|
|
||||||
class tst_AnsiEscapeCodeHandler : public QObject
|
class tst_AnsiEscapeCodeHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -52,18 +57,17 @@ private Q_SLOTS:
|
|||||||
void testCase1_data();
|
void testCase1_data();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const QString red;
|
const QString red;
|
||||||
static const QString bold;
|
const QString bold;
|
||||||
static const QString normal;
|
const QString normal;
|
||||||
static const QString normal1;
|
const QString normal1;
|
||||||
};
|
};
|
||||||
|
|
||||||
const QString tst_AnsiEscapeCodeHandler::red = QChar::fromLatin1(27) + "[31m";
|
tst_AnsiEscapeCodeHandler::tst_AnsiEscapeCodeHandler() :
|
||||||
const QString tst_AnsiEscapeCodeHandler::bold = QChar::fromLatin1(27) + "[1m";
|
red(ansiEscape("31m")),
|
||||||
const QString tst_AnsiEscapeCodeHandler::normal = QChar::fromLatin1(27) + "[0m";
|
bold(ansiEscape("1m")),
|
||||||
const QString tst_AnsiEscapeCodeHandler::normal1 = QChar::fromLatin1(27) + "[m";
|
normal(ansiEscape("0m")),
|
||||||
|
normal1(ansiEscape("m"))
|
||||||
tst_AnsiEscapeCodeHandler::tst_AnsiEscapeCodeHandler()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user