AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
formatter.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 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 <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <cstdint>
23#include <array>
24#include <optional>
25#include <ostream>
26
27namespace anch::cli {
28
34 enum class Color {
35
37 BLACK = 0,
38
40 RED = 1,
41
43 GREEN = 2,
44
46 YELLOW = 3,
47
49 BLUE = 4,
50
52 MAGENTA = 5,
53
55 CYAN = 6,
56
58 WHITE = 7,
59
61 DEFAULT = 9
62
63 };
64
72 struct Formatter {
73
75 static bool DISABLED;
76
78 std::optional<Color> _fg_color;
79
81 std::optional<std::array<uint8_t,3>> _rgb_fg_color;
82
84 std::optional<Color> _bg_color;
85
87 std::optional<std::array<uint8_t,3>> _rgb_bg_color;
88
90 std::optional<bool> _bold = false;
91
93 std::optional<bool> _underline = false;
94
96 std::optional<bool> _blink = false;
97
99 bool _reset = false;
100
105
109 virtual ~Formatter();
110
117
125 Formatter& bold(bool state = true);
126
134 Formatter& underline(bool state = true);
135
143 Formatter& blink(bool state = true);
144
151
159 Formatter& fgColor(const Color& color);
160
168 Formatter& fgColor(const std::array<uint8_t,3>& color);
169
177 Formatter& bgColor(const Color& color);
178
186 Formatter& bgColor(const std::array<uint8_t,3>& color);
187
188 };
189
191 extern anch::cli::Formatter BOLD;
192
194 extern anch::cli::Formatter UNBOLD;
195
197 extern anch::cli::Formatter UNDERLINE;
198
200 extern anch::cli::Formatter UNUNDERLINE;
201
203 extern anch::cli::Formatter BLINK;
204
206 extern anch::cli::Formatter UNBLINK;
207
209 extern anch::cli::Formatter RESET;
210
211} // anch::cli
212
221std::ostream&
222operator<<(std::ostream& stream, const anch::cli::Formatter& fmt);
Console formatter.
Definition formatter.hpp:72
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:99
std::optional< Color > _fg_color
Definition formatter.hpp:78
std::optional< std::array< uint8_t, 3 > > _rgb_fg_color
Definition formatter.hpp:81
Formatter & bold(bool state=true)
static bool DISABLED
Definition formatter.hpp:75
std::optional< std::array< uint8_t, 3 > > _rgb_bg_color
Definition formatter.hpp:87
Formatter & fgColor(const Color &color)
std::optional< bool > _bold
Definition formatter.hpp:90
Formatter & blink(bool state=true)
std::optional< bool > _blink
Definition formatter.hpp:96
std::optional< bool > _underline
Definition formatter.hpp:93
Formatter & bgColor(const Color &color)
std::optional< Color > _bg_color
Definition formatter.hpp:84