https://github.com/mguludag/qt_ansicolor_handler
ansi color code parser class from qt-creator's source code and modified and added new features (italic and underline) then aims easy to use with current QTextEdit and QPlainTextEdit without creating custom classes
https://github.com/mguludag/qt_ansicolor_handler
ansi-colors cpp log-viewer qt qt5 qt5-gui qt5-widgets spdlog widget
Last synced: about 2 months ago
JSON representation
ansi color code parser class from qt-creator's source code and modified and added new features (italic and underline) then aims easy to use with current QTextEdit and QPlainTextEdit without creating custom classes
- Host: GitHub
- URL: https://github.com/mguludag/qt_ansicolor_handler
- Owner: mguludag
- License: other
- Created: 2022-03-18T16:59:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-28T21:11:12.000Z (over 4 years ago)
- Last Synced: 2025-01-03T08:19:39.048Z (over 1 year ago)
- Topics: ansi-colors, cpp, log-viewer, qt, qt5, qt5-gui, qt5-widgets, spdlog, widget
- Language: C++
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# qt_ansicolor_handler
ansi color code parser class from qt-creator's source code and modified and added new features (italic and underline) then aims easy to use with current QTextEdit and QPlainTextEdit without creating custom classes
## Usage
### mainwindow.h
```C++
#include "ui_mainwindow.h"
#include "ansiescapecodehandler.hpp"
#include
#include
#include
#include
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void log();
private:
Ui::MainWindow ui;
Utils::AnsiEscapeCodeHandler handler;
};
```
### mainwindow.cpp
```C++
#include "mainwindow.h"
#include
#include
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
// give the plainTextEdit's textCursor and verticalScrollBar to AnsiEscapeCodeHandler class
// appendAnsiText(const QString&) slot will parse and append styled plain text into plainTextEdit
handler = Utils::AnsiEscapeCodeHandler(ui.plainTextEdit->textCursor(), ui.plainTextEdit->verticalScrollBar());
mLogger = spdlog::qt_logger_color_mt("qt_logger", &handler, true, "appendAnsiText");
spdlog::set_pattern("%^[%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v%$");
...
}
```
