libcommonc++  0.7
Console.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Console_hxx
24 #define __ccxx_Console_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/String.h++>
28 
29 #include <cstdio>
30 
31 namespace ccxx {
32 
40 {
41  public:
42 
44  enum TextColor { ColorBlack, ColorRed, ColorGreen, ColorYellow, ColorBlue,
45  ColorMagenta, ColorCyan, ColorWhite };
46 
48  enum TextStyle { StyleBold, StyleUnderline, StyleInverse };
49 
51  Console();
52 
54  ~Console();
55 
64  size_t read(char* text, size_t maxlen);
65 
73  void write(const char* text, size_t len = 0);
74 
80  bool setEcho(bool on);
81 
89  void moveCursor(uint_t row, uint_t column);
90 
92  void clear();
93 
99  void setTextForeground(TextColor color);
100 
106  void setTextBackground(TextColor color);
107 
113  void beginTextStyle(TextStyle style);
114 
120  void endTextStyle(TextStyle style);
121 
123  void resetTextStyle();
124 
130  void setTitle(const String& title);
131 
142  bool getSize(uint_t* columns, uint_t* rows);
143 
144  private:
145 
146 #ifdef CCXX_OS_WINDOWS
147  HANDLE _console;
148  DWORD _attributes;
149  bool _intense;
150 #else
151  FILE* _console;
152  bool _underline;
153  bool _inverse;
154 #endif
155  bool _bold;
156 };
157 
158 } // namespace ccxx
159 
160 #endif // __ccxx_Console_hxx
A class that provides basic control of the console, such as changing text attributes, clearing the screen, and moving the cursor.
Definition: Console.h++:39
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
TextStyle
Text styles.
Definition: Console.h++:48
TextColor
Text colors.
Definition: Console.h++:44
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
Definition: AllocationMap.c++:25