1#ifndef __CPP_CONSOLE_GRAPHICS_HPP__
2#define __CPP_CONSOLE_GRAPHICS_HPP__
4#include <initializer_list>
67std::string
bold(
const std::string& str) {
75std::string
faint(
const std::string& str) {
83std::string
italic(
const std::string& str) {
99std::string
blink(
const std::string& str) {
115std::string
hidden(
const std::string& str) {
135 std::cout << (
set ?
"\033[1m" :
"\033[22m");
147 std::cout << (
set ?
"\033[2m" :
"\033[22m");
151 SetConsoleTextAttribute(
152 GetStdHandle(STD_OUTPUT_HANDLE),
153 set ? FOREGROUND_INTENSITY
154 : (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE));
165 std::cout << (
set ?
"\033[3m" :
"\033[23m");
177 std::cout << (
set ?
"\033[4m" :
"\033[24m");
189 std::cout << (
set ?
"\033[5m" :
"\033[25m");
201 std::cout << (
set ?
"\033[7m" :
"\033[27m");
213 std::cout << (
set ?
"\033[8m" :
"\033[28m");
225 std::cout << (
set ?
"\033[9m" :
"\033[29m");
230void set(std::initializer_list<Graphics> list) {
231 std::string itemStr =
"";
232 for (
const auto& item : list) {
233 itemStr += std::to_string(item);
234 if (item != *(list.end() - 1)) itemStr +=
";";
237 std::cout <<
"\033[" << itemStr <<
"m";
242std::string
set(
const std::string& str, std::initializer_list<Graphics> list) {
243 std::string itemStr =
"";
244 for (
const auto& item : list) {
245 itemStr += std::to_string(item);
246 if (item != *(list.end() - 1)) itemStr +=
";";
248 if (
isANSIEnabled())
return "\033[" + itemStr +
"m" + str +
"\033[0m";
254 std::cout <<
"\033[0m";
Namespace Containing all console commands.
Definition ansi.hpp:16
std::string bold(const std::string &str)
Returns a bolded string if ANSI is enabled.
Definition graphics.hpp:67
void setInverse(bool set)
Sets the text to be inversed/reversed or not.
Definition graphics.hpp:199
void setUnderline(bool set)
Sets the text to be underlined or not.
Definition graphics.hpp:175
std::string inverse(const std::string &str)
Returns a inversed/reversed string if ANSI is enabled.
Definition graphics.hpp:107
void setHidden(bool set)
Sets the text to be hidden or not.
Definition graphics.hpp:211
void setFaint(bool set)
Sets the text to be faint/dim or not.
Definition graphics.hpp:145
std::string blink(const std::string &str)
Returns a blinking string if ANSI is enabled.
Definition graphics.hpp:99
std::string faint(const std::string &str)
Returns a faint/dim string if ANSI is enabled.
Definition graphics.hpp:75
void setBlink(bool set)
Sets the text to be blinking or not.
Definition graphics.hpp:187
Graphics
Enumeration of builtin colors for ANSI escape codes, along with other graphics modes.
Definition graphics.hpp:19
@ BRIGHT_YELLOW
Definition graphics.hpp:49
@ BG_GREEN
Definition graphics.hpp:39
@ WHITE
Definition graphics.hpp:35
@ BRIGHT_GREEN
Definition graphics.hpp:48
@ BG_RED
Definition graphics.hpp:38
@ BRIGHT_BLACK
Definition graphics.hpp:46
@ BLUE
Definition graphics.hpp:32
@ BOLD
Definition graphics.hpp:20
@ HIDDEN
Definition graphics.hpp:26
@ BLINK
Definition graphics.hpp:24
@ BG_BRIGHT_GREEN
Definition graphics.hpp:56
@ BRIGHT_MAGENTA
Definition graphics.hpp:51
@ BG_BRIGHT_YELLOW
Definition graphics.hpp:57
@ MAGENTA
Definition graphics.hpp:33
@ BG_BRIGHT_CYAN
Definition graphics.hpp:60
@ DIM
Definition graphics.hpp:21
@ BG_BRIGHT_BLACK
Definition graphics.hpp:54
@ BG_BLACK
Definition graphics.hpp:37
@ BRIGHT_BLUE
Definition graphics.hpp:50
@ BRIGHT_WHITE
Definition graphics.hpp:53
@ DEFAULT
Definition graphics.hpp:36
@ UNDERLINE
Definition graphics.hpp:23
@ BG_CYAN
Definition graphics.hpp:43
@ BG_BRIGHT_RED
Definition graphics.hpp:55
@ BG_BLUE
Definition graphics.hpp:41
@ BRIGHT_RED
Definition graphics.hpp:47
@ GREEN
Definition graphics.hpp:30
@ CYAN
Definition graphics.hpp:34
@ INVERT
Definition graphics.hpp:25
@ ITALIC
Definition graphics.hpp:22
@ BG_MAGENTA
Definition graphics.hpp:42
@ BG_BRIGHT_WHITE
Definition graphics.hpp:61
@ BG_BRIGHT_MAGENTA
Definition graphics.hpp:59
@ BG_YELLOW
Definition graphics.hpp:40
@ BG_BRIGHT_BLUE
Definition graphics.hpp:58
@ YELLOW
Definition graphics.hpp:31
@ BG_WHITE
Definition graphics.hpp:44
@ BG_DEFAULT
Definition graphics.hpp:45
@ BLACK
Definition graphics.hpp:28
@ RED
Definition graphics.hpp:29
@ STRIKETHROUGH
Definition graphics.hpp:27
@ BRIGHT_CYAN
Definition graphics.hpp:52
std::string hidden(const std::string &str)
Returns a hidden string if ANSI is enabled.
Definition graphics.hpp:115
void set(std::initializer_list< Graphics > list)
Definition graphics.hpp:230
std::string underline(const std::string &str)
Returns an underlined string if ANSI is enabled.
Definition graphics.hpp:91
std::string strikethrough(const std::string &str)
Returns a strikethough string if ANSI is enabled.
Definition graphics.hpp:123
void setStrikethrough(bool set)
Sets the text to be strikethrough or not.
Definition graphics.hpp:223
void setItalic(bool set)
Sets the text to be italicized or not.
Definition graphics.hpp:163
std::string italic(const std::string &str)
Returns an italicized string if ANSI is enabled.
Definition graphics.hpp:83
void clearGraphics()
Definition graphics.hpp:252
bool isANSIEnabled()
Checks if ANSI Codes are enable in windows.
Definition ansi.hpp:22
void setBold(bool set)
Sets the text to be bold or not.
Definition graphics.hpp:133