-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement syntax highlighting with QTextLayout
Using QTextDocument was a little bit overkill since we don't need rich text support. This replaces it with a simple QTextLayout implementation. closed: #522, #505
- Loading branch information
Showing
15 changed files
with
451 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
SPDX-FileCopyrightText: Lieven Hey <[email protected]> | ||
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "formattingutils.h" | ||
|
||
QString Util::removeAnsi(const QString& stringWithAnsi) | ||
{ | ||
const static QChar escapeChar = QLatin1Char('\u001B'); | ||
if (!stringWithAnsi.contains(escapeChar)) { | ||
return stringWithAnsi; | ||
} | ||
|
||
QString ansiFreeString = stringWithAnsi; | ||
while (ansiFreeString.contains(escapeChar)) { | ||
const auto escapeStart = ansiFreeString.indexOf(escapeChar); | ||
const auto escapeEnd = ansiFreeString.indexOf(QLatin1Char('m'), escapeStart); | ||
ansiFreeString.remove(escapeStart, escapeEnd - escapeStart + 1); | ||
} | ||
return ansiFreeString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
SPDX-FileCopyrightText: Lieven Hey <[email protected]> | ||
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QString> | ||
|
||
namespace Util { | ||
// escape character also known as \033 and \e it signals the start of an ansi escape sequence | ||
constexpr auto escapeChar = QLatin1Char('\u001B'); | ||
|
||
QString removeAnsi(const QString& stringWithAnsi); | ||
} |
Oops, something went wrong.