Add ANSI color rendering and terminal themes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user