CARMA C++
XtermManip.h
Go to the documentation of this file.
1 // $Id: XtermManip.h,v 1.1 2010/12/13 21:06:33 eml Exp $
2 
3 #ifndef SZA_UTIL_XTERMMANIP_H
4 #define SZA_UTIL_XTERMMANIP_H
5 
16 #include <iostream>
17 #include <map>
18 #include <string>
19 
20 namespace sza {
21  namespace util {
22 
23  class XtermManip {
24  public:
25 
29  XtermManip();
30 
34  virtual ~XtermManip();
35 
36  struct Option {
37  unsigned key_;
38  std::string str_;
39 
40  Option(unsigned key, std::string str) {
41  key_ = key;
42  str_ = str;
43  }
44  };
45 
46  //------------------------------------------------------------
47  // Color manipulation
48  //------------------------------------------------------------
49 
50  enum ColorKey {
51  C_BLACK,
52  C_RED,
53  C_GREEN,
54  C_YELLOW,
55  C_BLUE,
56  C_MAGENTA,
57  C_CYAN,
58  C_WHITE,
59  C_DEFAULT
60  };
61 
62  std::map<ColorKey, std::string> fg_;
63  std::map<ColorKey, std::string> bg_;
64 
65  std::map<std::string, ColorKey> colorNames_;
66 
67 
68  void setFg(ColorKey key);
69  void setFg(std::string key);
70 
71  void setBg(ColorKey key);
72  void setBg(std::string key);
73 
74  std::string fg(ColorKey key);
75  std::string fg(std::string key);
76 
77  std::string bg(ColorKey key);
78  std::string bg(std::string key);
79 
80  ColorKey getColorKey(std::string name);
81 
82  //------------------------------------------------------------
83  // Text mode manipulation
84  //------------------------------------------------------------
85 
86  enum TextModeKey {
87  TEXT_DEFAULT,
88 
89  TEXT_BOLD,
90  TEXT_NORMAL,
91 
92  TEXT_UNDERLINED,
93  TEXT_NOT_UNDERLINED,
94 
95  TEXT_BLINK,
96  TEXT_STEADY,
97 
98  TEXT_INVERSE,
99  TEXT_POSITIVE,
100 
101  TEXT_INVISIBLE,
102  TEXT_VISIBLE,
103  };
104 
105  std::map<TextModeKey, std::string> textModes_;
106  std::map<std::string, TextModeKey> textModeNames_;
107 
108  void setTextMode(TextModeKey key);
109  void setTextMode(std::string name);
110 
111  std::string textMode(TextModeKey key);
112  std::string textMode(std::string name);
113 
114  TextModeKey getTextModeKey(std::string name);
115 
116  //------------------------------------------------------------
117  // Cursor modes
118  //------------------------------------------------------------
119 
120  enum CursorCntlKey {
121  CURS_GET_POSITION,
122  };
123 
124  void getCursorPosition();
125 
126  void saveCursor();
127  void restoreCursor();
128  void moveCursorUp(unsigned nline);
129  void moveCursorDown(unsigned nline);
130  void clearAbove();
131 
132  private:
133 
134  void initializeOptions();
135  void setRawMode();
136 
137  }; // End class XtermManip
138 
139  } // End namespace util
140 } // End namespace sza
141 
142 
143 
144 #endif // End #ifndef SZA_UTIL_XTERMMANIP_H