]> granicus.if.org Git - icinga2/blob - lib/base/console.hpp
Remove unused includes
[icinga2] / lib / base / console.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef CONSOLE_H
21 #define CONSOLE_H
22
23 #include "base/i2-base.hpp"
24 #include <iosfwd>
25
26 namespace icinga
27 {
28
29 enum ConsoleColor
30 {
31         Console_Normal,
32
33         // bit 0-7: foreground
34         Console_ForegroundBlack = 1,
35         Console_ForegroundRed = 2,
36         Console_ForegroundGreen = 3,
37         Console_ForegroundYellow = 4,
38         Console_ForegroundBlue = 5,
39         Console_ForegroundMagenta = 6,
40         Console_ForegroundCyan = 7,
41         Console_ForegroundWhite = 8,
42
43         // bit 8-15: background
44         Console_BackgroundBlack = 256,
45         Console_BackgroundRed = 266,
46         Console_BackgroundGreen = 267,
47         Console_BackgroundYellow = 268,
48         Console_BackgroundBlue = 269,
49         Console_BackgroundMagenta = 270,
50         Console_BackgroundCyan = 271,
51         Console_BackgroundWhite = 272,
52
53         // bit 16-23: flags
54         Console_Bold = 65536
55 };
56
57 enum ConsoleType
58 {
59         Console_Autodetect = -1,
60
61         Console_Dumb,
62 #ifndef _WIN32
63         Console_VT100,
64 #else /* _WIN32 */
65         Console_Windows,
66 #endif /* _WIN32 */
67 };
68
69 class ConsoleColorTag
70 {
71 public:
72         ConsoleColorTag(int color, ConsoleType consoleType = Console_Autodetect);
73
74         friend std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
75
76 private:
77         int m_Color;
78         int m_ConsoleType;
79 };
80
81 std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
82
83 /**
84  * Console utilities.
85  *
86  * @ingroup base
87  */
88 class Console
89 {
90 public:
91         static void DetectType();
92
93         static void SetType(std::ostream& fp, ConsoleType type);
94         static ConsoleType GetType(std::ostream& fp);
95
96 #ifndef _WIN32
97         static void PrintVT100ColorCode(std::ostream& fp, int color);
98 #else /* _WIN32 */
99         static void SetWindowsConsoleColor(std::ostream& fp, int color);
100 #endif /* _WIN32 */
101
102 private:
103         Console();
104 };
105
106 }
107
108 #endif /* CONSOLE_H */