AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
formatter.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework 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
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-cli-export.hpp"
23
24#include <cstdint>
25#include <array>
26#include <optional>
27#include <ostream>
28
29namespace anch::cli {
30
36 enum class Color {
37
39 BLACK = 0,
40
42 RED = 1,
43
45 GREEN = 2,
46
48 YELLOW = 3,
49
51 BLUE = 4,
52
55
57 CYAN = 6,
58
60 WHITE = 7,
61
63 DEFAULT = 9
64
65 };
66
74 struct ANCH_CLI_EXPORT Formatter {
75
81 static bool DISABLED;
82
84 std::optional<Color> _fg_color;
85
87 std::optional<std::array<uint8_t,3>> _rgb_fg_color;
88
90 std::optional<Color> _bg_color;
91
93 std::optional<std::array<uint8_t,3>> _rgb_bg_color;
94
96 std::optional<bool> _bold = false;
97
99 std::optional<bool> _underline = false;
100
102 std::optional<bool> _blink = false;
103
105 bool _reset = false;
106
111
115 virtual ~Formatter();
116
123
131 Formatter& bold(bool state = true);
132
140 Formatter& underline(bool state = true);
141
149 Formatter& blink(bool state = true);
150
157
165 Formatter& fgColor(const Color& color);
166
174 Formatter& fgColor(const std::array<uint8_t,3>& color);
175
183 Formatter& bgColor(const Color& color);
184
192 Formatter& bgColor(const std::array<uint8_t,3>& color);
193
194 };
195
197 extern ANCH_CLI_EXPORT anch::cli::Formatter BOLD;
198
200 extern ANCH_CLI_EXPORT anch::cli::Formatter UNBOLD;
201
203 extern ANCH_CLI_EXPORT anch::cli::Formatter UNDERLINE;
204
206 extern ANCH_CLI_EXPORT anch::cli::Formatter UNUNDERLINE;
207
209 extern ANCH_CLI_EXPORT anch::cli::Formatter BLINK;
210
212 extern ANCH_CLI_EXPORT anch::cli::Formatter UNBLINK;
213
215 extern ANCH_CLI_EXPORT anch::cli::Formatter RESET;
216
226 ANCH_CLI_EXPORT std::ostream& operator<<(std::ostream& stream, const anch::cli::Formatter& fmt);
227
228} // anch::cli
AnCH command line interface library namespace.
Definition app.hpp:30
anch::cli::Formatter RESET
anch::cli::Formatter BLINK
std::ostream & operator<<(std::ostream &stream, const anch::cli::Formatter &fmt)
anch::cli::Formatter BOLD
Color
Definition formatter.hpp:36
@ BLACK
Definition formatter.hpp:39
@ BLUE
Definition formatter.hpp:51
@ CYAN
Definition formatter.hpp:57
@ YELLOW
Definition formatter.hpp:48
@ GREEN
Definition formatter.hpp:45
@ RED
Definition formatter.hpp:42
@ WHITE
Definition formatter.hpp:60
@ MAGENTA
Definition formatter.hpp:54
anch::cli::Formatter UNBOLD
anch::cli::Formatter UNBLINK
anch::cli::Formatter UNUNDERLINE
anch::cli::Formatter UNDERLINE
Console formatter.
Definition formatter.hpp:74
Formatter & bgColor(const std::array< uint8_t, 3 > &color)
Formatter & underline(bool state=true)
Formatter & fgColor(const std::array< uint8_t, 3 > &color)
Formatter & reset()
static Formatter format()
bool _reset
Definition formatter.hpp:105
std::optional< Color > _fg_color
Definition formatter.hpp:84
std::optional< std::array< uint8_t, 3 > > _rgb_fg_color
Definition formatter.hpp:87
Formatter & bold(bool state=true)
static bool DISABLED
Definition formatter.hpp:81
std::optional< std::array< uint8_t, 3 > > _rgb_bg_color
Definition formatter.hpp:93
Formatter & fgColor(const Color &color)
std::optional< bool > _bold
Definition formatter.hpp:96
Formatter & blink(bool state=true)
std::optional< bool > _blink
Definition formatter.hpp:102
std::optional< bool > _underline
Definition formatter.hpp:99
Formatter & bgColor(const Color &color)
std::optional< Color > _bg_color
Definition formatter.hpp:90