Add ANSI color rendering and terminal themes

This commit is contained in:
Keith Smith
2026-03-01 10:08:04 -07:00
parent 2b4f498259
commit 20ee48db32
4 changed files with 444 additions and 11 deletions

View File

@@ -1,20 +1,56 @@
#ifndef ORBITHUB_TERMINAL_VIEW_H
#define ORBITHUB_TERMINAL_VIEW_H
#include <QPlainTextEdit>
#include <QTextEdit>
class TerminalView : public QPlainTextEdit
#include <array>
class QKeyEvent;
class TerminalView : public QTextEdit
{
Q_OBJECT
public:
explicit TerminalView(QWidget* parent = nullptr);
static QStringList themeNames();
void setThemeName(const QString& themeName);
void appendTerminalData(const QString& data);
signals:
void inputGenerated(const QString& input);
protected:
void keyPressEvent(QKeyEvent* event) override;
private:
struct ThemePalette {
QString name;
QColor background;
QColor foreground;
std::array<QColor, 8> normal;
std::array<QColor, 8> bright;
};
ThemePalette m_palette;
QString m_pendingEscape;
bool m_bold;
bool m_hasFgColor;
bool m_hasBgColor;
QColor m_fgColor;
QColor m_bgColor;
QTextCharFormat m_currentFormat;
static ThemePalette paletteByName(const QString& themeName);
static QColor colorFrom256Index(int index);
void applyThemePalette(const ThemePalette& palette);
void applyCurrentFormat();
void resetSgrState();
void handleSgrSequence(const QString& params);
void appendTextChunk(const QString& text);
QColor paletteColor(bool background, int index, bool bright) const;
};
#endif