summaryrefslogtreecommitdiff
path: root/include/consolecolors.h
blob: f7ca1335ed244f16514d457d4fa035971fab2996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * InspIRCd -- Internet Relay Chat Daemon
 *
 * This file is part of InspIRCd.  InspIRCd is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef CONSOLECOLORS_H
#define CONSOLECOLORS_H

#include <ostream>

#ifdef _WIN32

#include <windows.h>

extern WORD g_wOriginalColors;
extern WORD g_wBackgroundColor;
extern HANDLE g_hStdout;

inline std::ostream& con_green(std::ostream &s)
{
    SetConsoleTextAttribute(g_hStdout, FOREGROUND_GREEN|FOREGROUND_INTENSITY|g_wBackgroundColor);
    return s;
}

inline std::ostream& con_red(std::ostream &s)
{
    SetConsoleTextAttribute(g_hStdout, FOREGROUND_RED|FOREGROUND_INTENSITY|g_wBackgroundColor);
    return s;
}

inline std::ostream& con_white(std::ostream &s)
{
    SetConsoleTextAttribute(g_hStdout, FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|g_wBackgroundColor);
    return s;
}

inline std::ostream& con_white_bright(std::ostream &s)
{
    SetConsoleTextAttribute(g_hStdout, FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY|g_wBackgroundColor);
    return s;
}

inline std::ostream& con_bright(std::ostream &s)
{
    SetConsoleTextAttribute(g_hStdout, FOREGROUND_INTENSITY|g_wBackgroundColor);
    return s;
}

inline std::ostream& con_reset(std::ostream &s)
{
    SetConsoleTextAttribute(g_hStdout, g_wOriginalColors);
    return s;
}

#else

inline std::ostream& con_green(std::ostream &s)
{
    return s << "\033[1;32m";
}

inline std::ostream& con_red(std::ostream &s)
{
    return s << "\033[1;31m";
}

inline std::ostream& con_white(std::ostream &s)
{
    return s << "\033[0m";
}

inline std::ostream& con_white_bright(std::ostream &s)
{
    return s << "\033[1m";
}

inline std::ostream& con_bright(std::ostream &s)
{
    return s << "\033[1m";
}

inline std::ostream& con_reset(std::ostream &s)
{
    return s << "\033[0m";
}

#endif

#endif