2023-02-06 16:36:05 +00:00
|
|
|
// This file is a derived works from Qt Creator.
|
|
|
|
// Licensed under GPL-3.0-only.
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ansi_escape.hpp"
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTextCharFormat>
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
|
|
|
class QPlainTextEdit;
|
|
|
|
|
|
|
|
class LogFormatter : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
LogFormatter(QPlainTextEdit *output, QObject *parent = nullptr);
|
|
|
|
~LogFormatter() override;
|
|
|
|
|
|
|
|
public:
|
2023-02-08 18:47:49 +00:00
|
|
|
void appendMessage(const QString &text);
|
2023-02-06 16:36:05 +00:00
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
2023-02-08 18:47:49 +00:00
|
|
|
void doAppendMessage(const QString &text);
|
2023-02-06 16:36:05 +00:00
|
|
|
void append(const QString &text, const QTextCharFormat &format);
|
|
|
|
void flushTrailingNewline();
|
|
|
|
QList<FormattedText> parseAnsi(const QString &text, const QTextCharFormat &format);
|
|
|
|
void scroll();
|
|
|
|
|
|
|
|
private:
|
|
|
|
AnsiEscape m_escapeCodeHandler;
|
|
|
|
QPlainTextEdit *m_output;
|
|
|
|
QTextCursor m_cursor;
|
|
|
|
bool m_prependLineFeed;
|
|
|
|
bool m_prependCarriageReturn;
|
|
|
|
};
|