From 6eeca69c56e7ee27d5a0489968751006fc2d8ce3 Mon Sep 17 00:00:00 2001 From: zeph Date: Fri, 9 Jan 2026 18:56:15 +0100 Subject: [PATCH] UI: ANSI colors, further fix-ups --- rpcs3/rpcs3qt/log_frame.cpp | 4 ++-- rpcs3/rpcs3qt/log_frame.h | 1 - rpcs3/rpcs3qt/log_viewer.h | 1 - rpcs3/rpcs3qt/syntax_highlighter.cpp | 15 +++++---------- rpcs3/rpcs3qt/syntax_highlighter.h | 4 ++++ 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/rpcs3/rpcs3qt/log_frame.cpp b/rpcs3/rpcs3qt/log_frame.cpp index e77a847c78..a97e2b6231 100644 --- a/rpcs3/rpcs3qt/log_frame.cpp +++ b/rpcs3/rpcs3qt/log_frame.cpp @@ -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; } }); diff --git a/rpcs3/rpcs3qt/log_frame.h b/rpcs3/rpcs3qt/log_frame.h index 35ee672ffc..35bd3a7ab1 100644 --- a/rpcs3/rpcs3qt/log_frame.h +++ b/rpcs3/rpcs3qt/log_frame.h @@ -1,7 +1,6 @@ #pragma once #include "Utilities/File.h" -#include "rpcs3qt/syntax_highlighter.h" #include "util/logs.hpp" #include "custom_dock_widget.h" diff --git a/rpcs3/rpcs3qt/log_viewer.h b/rpcs3/rpcs3qt/log_viewer.h index a2e8242f89..85ece2688b 100644 --- a/rpcs3/rpcs3qt/log_viewer.h +++ b/rpcs3/rpcs3qt/log_viewer.h @@ -9,7 +9,6 @@ #include class LogHighlighter; -class AnsiHighlighter; class gui_settings; class log_viewer : public QWidget diff --git a/rpcs3/rpcs3qt/syntax_highlighter.cpp b/rpcs3/rpcs3qt/syntax_highlighter.cpp index 4cc44b6d8b..2fd43033d5 100644 --- a/rpcs3/rpcs3qt/syntax_highlighter.cpp +++ b/rpcs3/rpcs3qt/syntax_highlighter.cpp @@ -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()); diff --git a/rpcs3/rpcs3qt/syntax_highlighter.h b/rpcs3/rpcs3qt/syntax_highlighter.h index f8577333dd..82745ed36f 100644 --- a/rpcs3/rpcs3qt/syntax_highlighter.h +++ b/rpcs3/rpcs3qt/syntax_highlighter.h @@ -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;