terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tgterminal.h
1 #pragma once
2 
3 #include <QPoint>
4 #include <QSize>
5 #include <QString>
6 #include <QObject>
7 
8 namespace Tg {
19 class Terminal : public QObject
20 {
21  Q_OBJECT
22 
26  Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
27 
28 public:
33  Terminal(QObject *parent = nullptr);
34 
38  ~Terminal();
39 
46  static Terminal *globalTerminal();
47 
51  QSize terminalWindowSize() const;
52 
56  QSize size() const;
57 
63  void setSize(const QSize &newSize);
64 
70  static QPoint cursorPosition();
71 
77  static int keyboardBufferSize();
78 
84  static int getChar();
85 
86 signals:
90  void sizeChanged(const QSize &size) const;
91 
92 private:
93  void registerSignalHandler();
94  void enableMouseTracking();
95  void disableMouseTracking();
96 
97  static Terminal *_globalTerminal;
98  static const int standardInputIndex = 0;
99  const QSize _defaultSize = QSize(80, 24);
100  bool _isMouseReporting = false;
101  QSize _size;
102 };
103 
111 public:
117 
122 };
123 }
124 
Tg::Terminal
Cross-platform representation of terminal window.
Definition: tgterminal.h:20
Tg::Terminal::globalTerminal
static Terminal * globalTerminal()
Returns Singleton Terminal instance.
Definition: tgterminal.cpp:20
Tg::RawTerminalLocker
Simple RAII class - sets proper echo mode in terminal for the duration of application run.
Definition: tgterminal.h:110
Tg::Terminal::keyboardBufferSize
static int keyboardBufferSize()
Returns number of characters available in keyboard buffer.
Definition: tgterminal_linux.cpp:49
Tg::Terminal::sizeChanged
void sizeChanged(const QSize &size) const
Emitted when terminal window changes size to size.
Tg
All Terminal GUI classes (both core and widgets) are defined within the Tg namespace.
Definition: tgcolor.h:6
Tg::Terminal::cursorPosition
static QPoint cursorPosition()
Returns current position of keyboard cursor.
Definition: tgterminal_linux.cpp:42
Tg::Terminal::terminalWindowSize
QSize terminalWindowSize() const
Reads the underlying terminal window size and returns it.
Definition: tgterminal_linux.cpp:35
Tg::Terminal::Terminal
Terminal(QObject *parent=nullptr)
Constructs a new Terminal object as a child of parent object.
Definition: tgterminal.cpp:5
Tg::RawTerminalLocker::~RawTerminalLocker
~RawTerminalLocker()
Enables echo mode in terminal.
Definition: tgterminal_linux.cpp:114
Tg::RawTerminalLocker::RawTerminalLocker
RawTerminalLocker()
Disables echo mode in terminal.
Definition: tgterminal_linux.cpp:100
Tg::Terminal::~Terminal
~Terminal()
Makes terminal go boom!
Definition: tgterminal.cpp:13
Tg::Terminal::setSize
void setSize(const QSize &newSize)
Resizes Terminal instance to newSize.
Definition: tgterminal.cpp:30
Tg::Terminal::getChar
static int getChar()
Retrieves a single character from the keyboard buffer.
Definition: tgterminal_linux.cpp:56
Tg::Terminal::size
QSize size
Size of the terminal window.
Definition: tgterminal.h:26