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