Pretty Diagnostics
Create your own pretty diagnostics
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <ostream>
4
#include <vector>
5
6
namespace
pretty_diagnostics::color
{
7
11
enum class
Code
{
12
Reset
= 0,
13
Bold
= 1,
14
Dim
= 2,
15
Italic
= 3,
16
Underline
= 4,
17
Blink
= 5,
18
Reverse
= 7,
19
Hidden
= 8,
20
Strikethrough
= 9,
21
22
FgBlack
= 30,
23
FgRed
= 31,
24
FgGreen
= 32,
25
FgYellow
= 33,
26
FgBlue
= 34,
27
FgMagenta
= 35,
28
FgCyan
= 36,
29
FgWhite
= 37,
30
FgDefault
= 39,
31
32
BgBlack
= 40,
33
BgRed
= 41,
34
BgGreen
= 42,
35
BgYellow
= 43,
36
BgBlue
= 44,
37
BgMagenta
= 45,
38
BgCyan
= 46,
39
BgWhite
= 47,
40
BgDefault
= 49,
41
42
FgBrightBlack
= 90,
43
FgBrightRed
= 91,
44
FgBrightGreen
= 92,
45
FgBrightYellow
= 93,
46
FgBrightBlue
= 94,
47
FgBrightMagenta
= 95,
48
FgBrightCyan
= 96,
49
FgBrightWhite
= 97,
50
51
BgBrightBlack
= 100,
52
BgBrightRed
= 101,
53
BgBrightGreen
= 102,
54
BgBrightYellow
= 103,
55
BgBrightBlue
= 104,
56
BgBrightMagenta
= 105,
57
BgBrightCyan
= 106,
58
BgBrightWhite
= 107,
59
};
60
70
std::ostream&
operator<<
(std::ostream& os,
Code
code);
71
78
struct
SyledText
{
79
std::vector<Code>
style
;
80
std::string_view
text
;
81
};
82
93
std::ostream&
operator<<
(std::ostream& os,
const
SyledText
& text);
94
105
[[nodiscard]]
SyledText
style
(std::string_view text,
const
std::vector<Code>& codes);
106
113
int
color_enabled_index
();
114
123
void
set_color_enabled
(std::ostream& os,
bool
enabled);
124
131
bool
is_color_enabled
(std::ostream& os);
132
142
bool
is_colorable
(
const
std::ostream& os);
143
152
void
auto_enable_color
(std::ostream& os);
153
154
}
// namespace pretty_diagnostics::color
155
156
// BSD 3-Clause License
157
//
158
// Copyright (c) 2025, Timo Behrend
159
//
160
// Redistribution and use in source and binary forms, with or without
161
// modification, are permitted provided that the following conditions are met:
162
//
163
// 1. Redistributions of source code must retain the above copyright notice, this
164
// list of conditions and the following disclaimer.
165
//
166
// 2. Redistributions in binary form must reproduce the above copyright notice,
167
// this list of conditions and the following disclaimer in the documentation
168
// and/or other materials provided with the distribution.
169
//
170
// 3. Neither the name of the copyright holder nor the names of its
171
// contributors may be used to endorse or promote products derived from
172
// this software without specific prior written permission.
173
//
174
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
175
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
176
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
177
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
178
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
179
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
180
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
181
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
182
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
183
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pretty_diagnostics::color
Definition:
color.hpp:6
pretty_diagnostics::color::is_colorable
bool is_colorable(const std::ostream &os)
Checks whether the given output stream supports colored output.
pretty_diagnostics::color::color_enabled_index
int color_enabled_index()
Returns a unique std::ios_base::xalloc index used to store per-stream color enable state.
pretty_diagnostics::color::operator<<
std::ostream & operator<<(std::ostream &os, Code code)
Outputs a single ANSI escape code to the given stream.
pretty_diagnostics::color::is_color_enabled
bool is_color_enabled(std::ostream &os)
Checks whether color output is enabled for the given stream.
pretty_diagnostics::color::style
SyledText style(std::string_view text, const std::vector< Code > &codes)
Creates a styled text object from a text and a set of ANSI codes.
pretty_diagnostics::color::Code
Code
ANSI escape codes for text styling and coloring.
Definition:
color.hpp:11
pretty_diagnostics::color::Code::FgGreen
@ FgGreen
pretty_diagnostics::color::Code::FgBrightYellow
@ FgBrightYellow
pretty_diagnostics::color::Code::BgBrightYellow
@ BgBrightYellow
pretty_diagnostics::color::Code::Bold
@ Bold
pretty_diagnostics::color::Code::BgYellow
@ BgYellow
pretty_diagnostics::color::Code::BgBrightWhite
@ BgBrightWhite
pretty_diagnostics::color::Code::Italic
@ Italic
pretty_diagnostics::color::Code::BgBrightCyan
@ BgBrightCyan
pretty_diagnostics::color::Code::BgBrightRed
@ BgBrightRed
pretty_diagnostics::color::Code::BgCyan
@ BgCyan
pretty_diagnostics::color::Code::FgBrightBlue
@ FgBrightBlue
pretty_diagnostics::color::Code::FgBlue
@ FgBlue
pretty_diagnostics::color::Code::BgDefault
@ BgDefault
pretty_diagnostics::color::Code::FgMagenta
@ FgMagenta
pretty_diagnostics::color::Code::FgDefault
@ FgDefault
pretty_diagnostics::color::Code::Reset
@ Reset
pretty_diagnostics::color::Code::FgBrightGreen
@ FgBrightGreen
pretty_diagnostics::color::Code::FgBrightWhite
@ FgBrightWhite
pretty_diagnostics::color::Code::Reverse
@ Reverse
pretty_diagnostics::color::Code::FgWhite
@ FgWhite
pretty_diagnostics::color::Code::BgBrightBlack
@ BgBrightBlack
pretty_diagnostics::color::Code::FgYellow
@ FgYellow
pretty_diagnostics::color::Code::Hidden
@ Hidden
pretty_diagnostics::color::Code::Underline
@ Underline
pretty_diagnostics::color::Code::Dim
@ Dim
pretty_diagnostics::color::Code::Strikethrough
@ Strikethrough
pretty_diagnostics::color::Code::FgBrightRed
@ FgBrightRed
pretty_diagnostics::color::Code::BgBrightGreen
@ BgBrightGreen
pretty_diagnostics::color::Code::BgMagenta
@ BgMagenta
pretty_diagnostics::color::Code::FgRed
@ FgRed
pretty_diagnostics::color::Code::BgBlack
@ BgBlack
pretty_diagnostics::color::Code::BgBlue
@ BgBlue
pretty_diagnostics::color::Code::FgCyan
@ FgCyan
pretty_diagnostics::color::Code::FgBlack
@ FgBlack
pretty_diagnostics::color::Code::BgRed
@ BgRed
pretty_diagnostics::color::Code::BgWhite
@ BgWhite
pretty_diagnostics::color::Code::Blink
@ Blink
pretty_diagnostics::color::Code::BgBrightBlue
@ BgBrightBlue
pretty_diagnostics::color::Code::BgBrightMagenta
@ BgBrightMagenta
pretty_diagnostics::color::Code::FgBrightCyan
@ FgBrightCyan
pretty_diagnostics::color::Code::BgGreen
@ BgGreen
pretty_diagnostics::color::Code::FgBrightMagenta
@ FgBrightMagenta
pretty_diagnostics::color::Code::FgBrightBlack
@ FgBrightBlack
pretty_diagnostics::color::auto_enable_color
void auto_enable_color(std::ostream &os)
Enables or disables color output for a stream based on its capability.
pretty_diagnostics::color::set_color_enabled
void set_color_enabled(std::ostream &os, bool enabled)
Enables or disables color output for a specific output stream.
pretty_diagnostics::color::SyledText
Holds a piece of text together with one or more ANSI style codes.
Definition:
color.hpp:78
pretty_diagnostics::color::SyledText::style
std::vector< Code > style
Definition:
color.hpp:79
pretty_diagnostics::color::SyledText::text
std::string_view text
Definition:
color.hpp:80
include
pretty_diagnostics
color.hpp
Generated by
1.9.5