terminal.h
Go to the documentation of this file.
1 // Encapsulates terminal control (colors, cursor, ...)
2 // Author: Max Schwarz <max.schwarz@uni-bonn.de>
3 
4 #ifndef TERMINAL_H
5 #define TERMINAL_H
6 
7 #include <stdint.h>
8 #include <string>
9 #include <map>
10 
11 namespace rosmon
12 {
13 
20 class Terminal
21 {
22 public:
30  {
32  Red,
47 
49  Grayscale = 0xe8
50  };
51 
58  class Parser
59  {
60  public:
61  Parser();
62 
64  void parse(char c);
65 
67  void parse(const std::string& str);
68 
70  void apply(Terminal* term);
71  private:
72  void parseSetAttributes(const std::string& str);
73 
74  enum State
75  {
79  };
80 
82  std::string m_buf;
83 
84  int m_fgColor;
85  int m_bgColor;
86  bool m_bold;
87  };
88 
89  Terminal();
90 
97  void setForegroundColor(uint32_t color);
98 
105  void setBackgroundColor(uint32_t color);
106 
108  void setCursorInvisible();
109 
111  void setCursorVisible();
112 
116  void setEcho(bool on);
117 
118  void setBold(bool on);
119 
121 
122  void setSimpleBackground(SimpleColor color);
123  void setSimpleForeground(SimpleColor color);
126 
128  void setStandardColors();
129 
131  void clearToEndOfLine();
132 
134  void moveCursorUp(int numLines);
135 
138 
144  bool getSize(int* columns, int* rows);
145 
151  bool has256Colors() const;
152 
156  bool interactive() const
157  { return m_valid; }
158 
159  void setWindowTitle(const std::string& title);
160  void clearWindowTitle(const std::string& backup);
161 
162 
164  {
165  SK_F1 = 0x100, SK_F2, SK_F3, SK_F4,
168  };
169 
170  int readKey();
171 
172 private:
173  bool m_valid;
176 
177  std::string m_bgColorStr;
178  std::string m_fgColorStr;
179  std::string m_opStr;
180  std::string m_sgr0Str;
181  std::string m_elStr;
182  std::string m_upStr;
183  std::string m_boldStr;
184 
185  std::map<std::string, SpecialKey> m_specialKeys;
186 
187  std::string m_currentEscapeStr;
188 };
189 
190 }
191 
192 #endif
24-step grayscale starts here
Definition: terminal.h:49
SimpleColor
Simple colors.
Definition: terminal.h:29
bool interactive() const
Definition: terminal.h:156
bool getSize(int *columns, int *rows)
Get current window size.
Definition: terminal.cpp:380
void parse(char c)
parse single character c
Definition: terminal.cpp:69
void setForegroundColor(uint32_t color)
Set 24-bit foreground color.
Definition: terminal.cpp:275
void setSimpleBackground(SimpleColor color)
Definition: terminal.cpp:332
std::map< std::string, SpecialKey > m_specialKeys
Definition: terminal.h:185
void moveCursorToStartOfLine()
Move cursor to start of the line.
Definition: terminal.cpp:375
void setBackgroundColor(uint32_t color)
Set 24-bit background color.
Definition: terminal.cpp:257
void parseSetAttributes(const std::string &str)
Definition: terminal.cpp:34
std::string m_fgColorStr
Definition: terminal.h:178
void setEcho(bool on)
Definition: terminal.cpp:293
void setSimplePair(SimpleColor fg, SimpleColor bg)
Definition: terminal.cpp:341
std::string m_currentEscapeStr
Definition: terminal.h:187
std::string m_opStr
Definition: terminal.h:179
std::string m_boldStr
Definition: terminal.h:183
void clearToEndOfLine()
Clear characters from cursor to end of line.
Definition: terminal.cpp:359
void setStandardColors()
Reset fg + bg to standard terminal colors.
Definition: terminal.cpp:350
std::string m_bgColorStr
Definition: terminal.h:177
std::string m_elStr
Definition: terminal.h:181
std::string m_upStr
Definition: terminal.h:182
void setCursorVisible()
restore cursor
Definition: terminal.cpp:236
void setSimpleForeground(SimpleColor color)
Definition: terminal.cpp:323
Encapsulates terminal control.
Definition: terminal.h:20
void moveCursorUp(int numLines)
Move cursor up by numLines.
Definition: terminal.cpp:367
bool has256Colors() const
Definition: terminal.cpp:223
void setWindowTitle(const std::string &title)
Definition: terminal.cpp:393
std::string m_sgr0Str
Definition: terminal.h:180
void setCursorInvisible()
hide cursor
Definition: terminal.cpp:228
Terminal escape sequence parser.
Definition: terminal.h:58
void apply(Terminal *term)
Apply the current internal state (colors) on the terminal.
Definition: terminal.cpp:108
void clearWindowTitle(const std::string &backup)
Definition: terminal.cpp:406
void setBold(bool on)
Definition: terminal.cpp:314


rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Jul 10 2019 03:10:12