cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
10#pragma once
11
13
14#include <array>
15#include <cstdint>
16#include <string>
17
18namespace Term
19{
20
21class Color
22{
23public:
24 enum class Type : std::uint8_t
25 {
26 Unset,
27 NoColor,
28 Bit3,
29 Bit4,
30 Bit8,
31 Bit24
32 };
33
39 enum class Name : std::uint8_t
40 {
41 Black = 0,
42 Red = 1,
43 Green = 2,
44 Yellow = 3,
45 Blue = 4,
46 Magenta = 5,
47 Cyan = 6,
48 White = 7,
49 Default = 9,
50 Gray = 60,
51 BrightBlack = 60,
52 BrightRed = 61,
53 BrightGreen = 62,
54 BrightYellow = 63,
55 BrightBlue = 64,
56 BrightMagenta = 65,
57 BrightCyan = 66,
58 BrightWhite = 67
59 };
60 bool operator==(const Color&) const;
61 bool operator!=(const Color&) const;
62 Color();
63 Color(const Term::Color::Name& name);
64 Color(const std::uint8_t& color);
65 Color(const std::uint8_t& red, const std::uint8_t& green, const std::uint8_t& blue);
66 Type getType() const;
67 Name to3bits() const;
68 Name to4bits() const;
69 std::uint8_t to8bits() const;
70 std::array<std::uint8_t, 3> to24bits() const;
71
72private:
74 union
75 {
76 std::uint8_t m_bit8;
77 std::array<std::uint8_t, 3> m_bit24;
78 };
79};
80
81std::string color_bg(const Term::Color::Name& name);
82std::string color_bg(const std::uint8_t& value);
83std::string color_bg(const std::uint8_t& red, const std::uint8_t& green, const std::uint8_t& blue);
84std::string color_bg(const Color& color);
85
86std::string color_fg(const Term::Color::Name& name);
87std::string color_fg(const std::uint8_t& value);
88std::string color_fg(const std::uint8_t& red, const std::uint8_t& green, const std::uint8_t& blue);
89std::string color_fg(const Color& color);
90
91} // namespace Term
Name to4bits() const
Definition color.cpp:48
std::uint8_t to8bits() const
Definition color.cpp:64
bool operator==(const Color &) const
Definition color.cpp:14
Type m_Type
Definition color.hpp:73
std::array< std::uint8_t, 3 > to24bits() const
Definition color.cpp:77
std::array< std::uint8_t, 3 > m_bit24
Definition color.hpp:77
Type getType() const
Definition color.cpp:37
std::uint8_t m_bit8
Definition color.hpp:76
Name to3bits() const
Definition color.cpp:39
Name
The 3bit/4bit colors for the terminal.
Definition color.hpp:40
@ Cyan
Cyan FG: 36, BG: 46.
@ White
White FG: 37, BG: 47.
@ BrightBlue
BrightBlue FG: 94, BG: 104.
@ BrightRed
BrightRed FG: 91, BG: 101.
@ BrightWhite
BrightWhite FG: 97, BG: 107.
@ BrightMagenta
BrightMagenta FG: 95, BG: 105.
@ Yellow
Yellow FG: 33, BG: 43.
@ Default
Use the default terminal color, FG: 39, BG: 49.
@ BrightYellow
BrightYellow FG: 93, BG: 103.
@ BrightBlack
BrightBlack FG: 90, BG: 100.
@ Blue
Blue FG: 34, BG: 44.
@ Gray
Gray FG: 90, BG: 100.
@ BrightGreen
BrightGreen FG: 92, BG: 102.
@ Magenta
Magenta FG: 35, BG: 45.
@ BrightCyan
BrightCyan FG: 96, BG: 106.
@ Green
Green FG: 32, BG: 42.
@ Black
Black FG: 30, BG: 40.
@ Red
Red FG: 31, BG: 41.
bool operator!=(const Color &) const
Definition color.cpp:21
Definition args.cpp:13
std::string color_bg(const Term::Color::Name &name)
Definition color.cpp:79
std::string color_fg(const Term::Color::Name &name)
Definition color.cpp:110