]> granicus.if.org Git - icinga2/blob - lib/base/console.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / console.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef CONSOLE_H
4 #define CONSOLE_H
5
6 #include "base/i2-base.hpp"
7 #include <iosfwd>
8
9 namespace icinga
10 {
11
12 enum ConsoleColor
13 {
14         Console_Normal,
15
16         // bit 0-7: foreground
17         Console_ForegroundBlack = 1,
18         Console_ForegroundRed = 2,
19         Console_ForegroundGreen = 3,
20         Console_ForegroundYellow = 4,
21         Console_ForegroundBlue = 5,
22         Console_ForegroundMagenta = 6,
23         Console_ForegroundCyan = 7,
24         Console_ForegroundWhite = 8,
25
26         // bit 8-15: background
27         Console_BackgroundBlack = 256,
28         Console_BackgroundRed = 266,
29         Console_BackgroundGreen = 267,
30         Console_BackgroundYellow = 268,
31         Console_BackgroundBlue = 269,
32         Console_BackgroundMagenta = 270,
33         Console_BackgroundCyan = 271,
34         Console_BackgroundWhite = 272,
35
36         // bit 16-23: flags
37         Console_Bold = 65536
38 };
39
40 enum ConsoleType
41 {
42         Console_Autodetect = -1,
43
44         Console_Dumb,
45 #ifndef _WIN32
46         Console_VT100,
47 #else /* _WIN32 */
48         Console_Windows,
49 #endif /* _WIN32 */
50 };
51
52 class ConsoleColorTag
53 {
54 public:
55         ConsoleColorTag(int color, ConsoleType consoleType = Console_Autodetect);
56
57         friend std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
58
59 private:
60         int m_Color;
61         int m_ConsoleType;
62 };
63
64 std::ostream& operator<<(std::ostream& fp, const ConsoleColorTag& cct);
65
66 /**
67  * Console utilities.
68  *
69  * @ingroup base
70  */
71 class Console
72 {
73 public:
74         static void DetectType();
75
76         static void SetType(std::ostream& fp, ConsoleType type);
77         static ConsoleType GetType(std::ostream& fp);
78
79 #ifndef _WIN32
80         static void PrintVT100ColorCode(std::ostream& fp, int color);
81 #else /* _WIN32 */
82         static void SetWindowsConsoleColor(std::ostream& fp, int color);
83 #endif /* _WIN32 */
84
85 private:
86         Console();
87 };
88
89 }
90
91 #endif /* CONSOLE_H */