Encapsulates terminal control. More...
#include <terminal.h>
Classes | |
| class | Color |
| class | Parser |
| Terminal escape sequence parser. More... | |
| class | Style |
Public Types | |
| enum | SimpleColor { Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, IntenseBlack, IntenseRed, IntenseGreen, IntenseYellow, IntenseBlue, IntenseMagenta, IntenseCyan, IntenseWhite, Grayscale = 0xe8 } |
| Simple colors. More... | |
| enum | SpecialKey { SK_F1 = 0x100, SK_F2, SK_F3, SK_F4, SK_F5, SK_F6, SK_F7, SK_F8, SK_F9, SK_F10, SK_F11, SK_F12, SK_Backspace, SK_Up, SK_Down, SK_Left, SK_Right } |
Public Member Functions | |
| void | clearToEndOfLine () |
| Clear characters from cursor to end of line. More... | |
| void | clearWindowTitle (const std::string &backup) |
| Color | color (SimpleColor code) |
| Color | color (uint32_t truecolor, SimpleColor fallback) |
| bool | getSize (int *columns, int *rows) |
| Get current window size. More... | |
| bool | has256Colors () const |
| bool | interactive () const |
| void | moveCursorToStartOfLine () |
| Move cursor to start of the line. More... | |
| void | moveCursorUp (int numLines) |
| Move cursor up by numLines. More... | |
| int | readKey () |
| int | readLeftover () |
| void | setBackgroundColor (uint32_t color) |
| Set 24-bit background color. More... | |
| void | setBold (bool on) |
| void | setCursorInvisible () |
| hide cursor More... | |
| void | setCursorVisible () |
| restore cursor More... | |
| void | setEcho (bool on) |
| void | setForegroundColor (uint32_t color) |
| Set 24-bit foreground color. More... | |
| void | setLineWrap (bool on) |
| void | setStandardColors () |
| Reset fg + bg to standard terminal colors. More... | |
| void | setWindowTitle (const std::string &title) |
| std::string | standardColorCode () |
| Escape codes for standard colors. More... | |
| Terminal () | |
Set indexed foreground/background color | |
| void | setSimpleBackground (SimpleColor color) |
| void | setSimpleForeground (SimpleColor color) |
| void | setSimplePair (SimpleColor fg, SimpleColor bg) |
Private Attributes | |
| bool | m_256colors |
| std::string | m_bgColorStr |
| std::string | m_boldStr |
| bool | m_currentEscapeAborted = false |
| unsigned int | m_currentEscapeAbortIdx = 0 |
| std::string | m_currentEscapeStr |
| std::string | m_elStr |
| std::chrono::steady_clock::time_point | m_escapeStartTime |
| std::string | m_fgColorStr |
| std::string | m_lineWrapOffStr |
| std::string | m_lineWrapOnStr |
| std::string | m_opStr |
| std::string | m_sgr0Str |
| std::map< std::string, SpecialKey > | m_specialKeys |
| bool | m_truecolor |
| std::string | m_upStr |
| bool | m_valid |
Encapsulates terminal control.
This class enables low-level manipulation of the terminal. It uses the ncurses/terminfo library internally to stay somewhat portable.
Definition at line 22 of file terminal.h.
Simple colors.
These colors can be used with the setSimpleForeground(), setSimpleBackground(), setSimplePair() methods.
| Enumerator | |
|---|---|
| Black | |
| Red | |
| Green | |
| Yellow | |
| Blue | |
| Magenta | |
| Cyan | |
| White | |
| IntenseBlack | |
| IntenseRed | |
| IntenseGreen | |
| IntenseYellow | |
| IntenseBlue | |
| IntenseMagenta | |
| IntenseCyan | |
| IntenseWhite | |
| Grayscale |
24-step grayscale starts here |
Definition at line 31 of file terminal.h.
| Enumerator | |
|---|---|
| SK_F1 | |
| SK_F2 | |
| SK_F3 | |
| SK_F4 | |
| SK_F5 | |
| SK_F6 | |
| SK_F7 | |
| SK_F8 | |
| SK_F9 | |
| SK_F10 | |
| SK_F11 | |
| SK_F12 | |
| SK_Backspace | |
| SK_Up | |
| SK_Down | |
| SK_Left | |
| SK_Right | |
Definition at line 224 of file terminal.h.
| rosmon::Terminal::Terminal | ( | ) |
Definition at line 180 of file terminal.cpp.
| void rosmon::Terminal::clearToEndOfLine | ( | ) |
Clear characters from cursor to end of line.
Definition at line 451 of file terminal.cpp.
| void rosmon::Terminal::clearWindowTitle | ( | const std::string & | backup | ) |
Definition at line 506 of file terminal.cpp.
| Terminal::Color rosmon::Terminal::color | ( | SimpleColor | code | ) |
Definition at line 616 of file terminal.cpp.
| Terminal::Color rosmon::Terminal::color | ( | uint32_t | truecolor, |
| SimpleColor | fallback | ||
| ) |
Definition at line 624 of file terminal.cpp.
| bool rosmon::Terminal::getSize | ( | int * | columns, |
| int * | rows | ||
| ) |
| bool rosmon::Terminal::has256Colors | ( | ) | const |
Returns whether the terminal supports 256 colors. If it does not suppport 256 colors, you should not use the setForegroundColor() / setBackgroundColor() functions.
Definition at line 307 of file terminal.cpp.
|
inline |
Terminal supports escape codes
Definition at line 217 of file terminal.h.
| void rosmon::Terminal::moveCursorToStartOfLine | ( | ) |
Move cursor to start of the line.
Definition at line 467 of file terminal.cpp.
| void rosmon::Terminal::moveCursorUp | ( | int | numLines | ) |
Move cursor up by numLines.
Definition at line 459 of file terminal.cpp.
| int rosmon::Terminal::readKey | ( | ) |
Definition at line 544 of file terminal.cpp.
| int rosmon::Terminal::readLeftover | ( | ) |
Definition at line 514 of file terminal.cpp.
| void rosmon::Terminal::setBackgroundColor | ( | uint32_t | color | ) |
Set 24-bit background color.
This automatically falls back to 256 colors if the terminal does not support true color.
Definition at line 341 of file terminal.cpp.
| void rosmon::Terminal::setBold | ( | bool | on | ) |
Definition at line 398 of file terminal.cpp.
| void rosmon::Terminal::setCursorInvisible | ( | ) |
hide cursor
Definition at line 312 of file terminal.cpp.
| void rosmon::Terminal::setCursorVisible | ( | ) |
restore cursor
Definition at line 320 of file terminal.cpp.
| void rosmon::Terminal::setEcho | ( | bool | on | ) |
Enable/disable automatic echo of keypresses
Definition at line 377 of file terminal.cpp.
| void rosmon::Terminal::setForegroundColor | ( | uint32_t | color | ) |
Set 24-bit foreground color.
This automatically falls back to 256 colors if the terminal does not support true color.
Definition at line 359 of file terminal.cpp.
| void rosmon::Terminal::setLineWrap | ( | bool | on | ) |
Enable/disable terminal linewrap
Definition at line 472 of file terminal.cpp.
| void rosmon::Terminal::setSimpleBackground | ( | SimpleColor | color | ) |
Definition at line 416 of file terminal.cpp.
| void rosmon::Terminal::setSimpleForeground | ( | SimpleColor | color | ) |
Definition at line 407 of file terminal.cpp.
| void rosmon::Terminal::setSimplePair | ( | SimpleColor | fg, |
| SimpleColor | bg | ||
| ) |
Definition at line 425 of file terminal.cpp.
| void rosmon::Terminal::setStandardColors | ( | ) |
Reset fg + bg to standard terminal colors.
Definition at line 434 of file terminal.cpp.
| void rosmon::Terminal::setWindowTitle | ( | const std::string & | title | ) |
Definition at line 493 of file terminal.cpp.
| std::string rosmon::Terminal::standardColorCode | ( | ) |
Escape codes for standard colors.
Definition at line 443 of file terminal.cpp.
|
private |
Definition at line 245 of file terminal.h.
|
private |
Definition at line 248 of file terminal.h.
|
private |
Definition at line 254 of file terminal.h.
|
private |
Definition at line 262 of file terminal.h.
|
private |
Definition at line 263 of file terminal.h.
|
private |
Definition at line 260 of file terminal.h.
|
private |
Definition at line 252 of file terminal.h.
|
private |
Definition at line 261 of file terminal.h.
|
private |
Definition at line 249 of file terminal.h.
|
private |
Definition at line 255 of file terminal.h.
|
private |
Definition at line 256 of file terminal.h.
|
private |
Definition at line 250 of file terminal.h.
|
private |
Definition at line 251 of file terminal.h.
|
private |
Definition at line 258 of file terminal.h.
|
private |
Definition at line 246 of file terminal.h.
|
private |
Definition at line 253 of file terminal.h.
|
private |
Definition at line 244 of file terminal.h.