qxLib
terminal_color.h
Go to the documentation of this file.
1 /**
2 
3  @file terminal_color.h
4  @author Khrapov
5  @date 10.12.2022
6  @copyright © Nick Khrapov, 2022. All right reserved.
7 
8 **/
9 #pragma once
10 
12 #include <qx/render/color.h>
13 
14 #include <iostream>
15 
16 namespace qx
17 {
18 
19 class terminal_color;
20 
21 }
22 
23 template<class char_t>
24 std::basic_ostream<char_t>& operator<<(std::basic_ostream<char_t>& os, const qx::terminal_color& terminalColor);
25 
26 namespace qx
27 {
28 
29 /**
30 
31  @class terminal_color
32  @brief Class for colors manipulating in terminal
33  @details Always check which colors are available in your machine, for ex. with qx::terminal_color::test_colors()
34  @author Khrapov
35  @date 13.12.2022
36 
37  @code
38 
39  std::cout << qx::terminal_color::font(qx::color::green()) << "green" << qx::terminal_color::reset() << std::endl;
40 
41  @endcode
42 
43 **/
45 {
46  template<class char_t>
47  friend std::basic_ostream<char_t>& ::operator<<(
48  std::basic_ostream<char_t>& is,
49  const terminal_color
50  & terminalColor);
51 
52  enum class type
53  {
54  font,
55  back,
56  reset
57  };
58 
59 public:
60  /**
61  @brief Set font color
62  @param fontColor - new font color
63  @retval - terminal_color instance to pass to the ostream
64  **/
65  static constexpr terminal_color font(const color& fontColor) noexcept;
66 
67  /**
68  @brief Set background color
69  @param bgColor - new background color
70  @retval - terminal_color instance to pass to the ostream
71  **/
72  static constexpr terminal_color back(const color& bgColor) noexcept;
73 
74  /**
75  @brief Reset all colors
76  @retval - terminal_color instance to pass to the ostream
77  **/
78  static constexpr terminal_color reset() noexcept;
79 
80  /**
81  @brief Output colors available in qx::color to test if terminal color work
82  **/
83  static void test_colors();
84 
85 private:
86  /**
87  @brief terminal_color object constructor
88  @param inColor - color to set
89  @param eType - output type
90  **/
91  constexpr terminal_color(const color& inColor, type eType) noexcept;
92 
93  /**
94  @brief terminal_color object constructor
95  @param eType - output type
96  **/
97  constexpr terminal_color(type eType) noexcept;
98 
99 private:
100  color m_Color = color::white();
101  type m_eType = type::reset;
102 };
103 
104 } // namespace qx
105 
RGBA color.
Definition: color.h:193
Class for colors manipulating in terminal.
static void test_colors()
Output colors available in qx::color to test if terminal color work.
static constexpr terminal_color reset() noexcept
Reset all colors.
static constexpr terminal_color font(const color &fontColor) noexcept
Set font color.
static constexpr terminal_color back(const color &bgColor) noexcept
Set background color.