UI: ANSI colors, further fix-ups

This commit is contained in:
zeph 2026-01-09 18:56:15 +01:00 committed by Megamouse
parent 484d97caf1
commit 6eeca69c56
5 changed files with 11 additions and 14 deletions

View file

@ -295,13 +295,13 @@ void log_frame::CreateAndConnectActions()
m_gui_settings->SetValue(gui::l_ansi_code, checked);
m_ansi_tty = checked;
if (!m_tty_ansi_highlighter)
if (m_ansi_tty)
{
m_tty_ansi_highlighter = new AnsiHighlighter(m_tty->document());
}
else
{
delete m_tty_ansi_highlighter;
m_tty_ansi_highlighter->deleteLater();
m_tty_ansi_highlighter = nullptr;
}
});

View file

@ -1,7 +1,6 @@
#pragma once
#include "Utilities/File.h"
#include "rpcs3qt/syntax_highlighter.h"
#include "util/logs.hpp"
#include "custom_dock_widget.h"

View file

@ -9,7 +9,6 @@
#include <memory>
class LogHighlighter;
class AnsiHighlighter;
class gui_settings;
class log_viewer : public QWidget

View file

@ -186,20 +186,15 @@ GlslHighlighter::GlslHighlighter(QTextDocument* parent) : Highlighter(parent)
AnsiHighlighter::AnsiHighlighter(QTextDocument* parent) : Highlighter(parent)
{
m_escape_format.setForeground(Qt::darkGray);
m_escape_format.setFontItalic(true);
m_foreground_color = gui::utils::get_foreground_color();
}
void AnsiHighlighter::highlightBlock(const QString& text)
{
// Match ANSI SGR sequences, e.g. "\x1b[31m" or "\x1b[1;32m"
static const QRegularExpression ansi_re("\x1b\\[[0-9;]*m");
static const QRegularExpression param_re("\x1b\\[([0-9;]*)m");
static QTextCharFormat escape_format;
escape_format.setForeground(Qt::darkGray);
escape_format.setFontItalic(true);
static QTextCharFormat current_format;
QTextCharFormat current_format;
current_format.setForeground(m_foreground_color);
int pos = 0;
@ -217,7 +212,7 @@ void AnsiHighlighter::highlightBlock(const QString& text)
}
// Highlight the escape sequence itself
setFormat(start, length, escape_format);
setFormat(start, length, m_escape_format);
// Parse SGR parameters and update currentFormat
const QRegularExpressionMatch pm = param_re.match(match.captured());

View file

@ -62,6 +62,10 @@ public:
explicit AnsiHighlighter(QTextDocument* parent = nullptr);
protected:
const QRegularExpression ansi_re = QRegularExpression("\x1b\\[[0-9;]*m");
const QRegularExpression param_re = QRegularExpression("\x1b\\[([0-9;]*)m");
QTextCharFormat m_escape_format;
QColor m_foreground_color;
void highlightBlock(const QString& text) override;