sculpto
console_colors.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file console_colors.h
3 * \brief Helper to setting color of text in console implementation module.
4 *
5 * \author Sabitov Kirill
6 * \date 23 June 2022
7 *********************************************************************/
8
9#pragma once
10
11namespace scl::console
12{
14 enum class color
15 {
16 BLACK,
17 RED,
18 GREEN,
19 YELLOW,
20 BLUE,
21 MAGENTA,
22 CYAN,
23 WHITE,
24 };
25
26 /*!*
27 * Creating string literal for changing both foreground console colors.
28 *
29 * \param ForegroundColor - new console foreground color.
30 * \return String literal changing console color.
31 */
32 inline std::string color_literal(color ForegroundColor)
33 {
34 int foreground = 30 + (int)ForegroundColor;
35
36 return std::string("\x1b[") + std::to_string(foreground) + "m";
37 }
38
39 /*!*
40 * Creating string literal for changing both background and foreground console colors.
41 *
42 * \param ForegroundColor - new console foreground color.
43 * \param BackgroundColor - new console background color.
44 * \return String literal changing console color.
45 */
46 inline std::string color_literal(color ForegroundColor,
47 color BackgroundColor)
48 {
49 int foreground = 30 + (int)ForegroundColor;
50 int backgound = 40 + (int)BackgroundColor;
51
52 return std::string("\x1b[") +
53 std::to_string(foreground) + ";" +
54 std::to_string(backgound) + "m";
55 }
56
57 /*!*
58 * Creating string literal for reset console colors.
59 *
60 * \return String literal reseting console color.
61 */
62 inline const std::string color_literal_reset()
63 {
64 return "\x1b[0m";
65 }
66}
const std::string color_literal_reset()
std::string color_literal(color ForegroundColor)