C++ 如何将彩色文本输出到Linux终端?
如何将彩色字符打印到支持它的Linux终端 如何判断终端是否支持颜色代码?您需要输出。请注意,并非所有端子都支持此功能;如果不支持颜色序列,将显示垃圾 例如:C++ 如何将彩色文本输出到Linux终端?,c++,linux,colors,terminal,C++,Linux,Colors,Terminal,如何将彩色字符打印到支持它的Linux终端 如何判断终端是否支持颜色代码?您需要输出。请注意,并非所有端子都支持此功能;如果不支持颜色序列,将显示垃圾 例如: cout << "\033[1;31mbold red text\033[0m\n"; 此外,您还可以使用这些: reset 0 (everything back to normal) bold/bright 1 (often a brighter shade o
cout << "\033[1;31mbold red text\033[0m\n";
此外,您还可以使用这些:
reset 0 (everything back to normal)
bold/bright 1 (often a brighter shade of the same colour)
underline 4
inverse 7 (swap foreground and background colours)
bold/bright off 21
underline off 24
inverse off 27
请参阅,以了解其他支持较少的代码
要确定终端是否支持颜色序列,请读取
术语
环境变量的值。它应该指定使用的特定终端类型(例如,vt100
,gnome终端
,xterm
,屏幕
,…)。然后在地图上查一下;检查颜色
功能。如果终端支持转义序列,则可以使用转义序列。例如:
echo \[\033[32m\]Hello, \[\033[36m\]colourful \[\033[33mworld!\033[0m\]
最好的方法是使用ncurses库-尽管这可能是一个大锤,如果您只想输出一个简单的彩色字符串,那么在输出所需的任何颜色之前,请确保您在终端中:
[ -t 1 ] && echo 'Yes I am in a terminal' # isatty(3) call in C
然后,您需要检查终端功能是否支持颜色
在具有(基于Linux的)的系统上,您可以获得以下支持颜色的数量:
Number_Of_colors_Supported=$(tput colors)
Number_Of_colors_Supported=$(tput Co)
在带有termcap
(基于BSD)的系统上,您可以获得以下支持颜色的数量:
Number_Of_colors_Supported=$(tput colors)
Number_Of_colors_Supported=$(tput Co)
然后你做出决定:
[ ${Number_Of_colors_Supported} -ge 8 ] && {
echo 'You are fine and can print colors'
} || {
echo 'Terminal does not support color'
}
顺便说一句,不要像以前建议的那样使用ESC字符的颜色。 使用标准的终端调用功能,该功能将为您指定特定终端支持的正确颜色 基于BSD的 基于Linux的 用作
这是一个古老的主题,但我编写了一个包含嵌套子类和由简单C宏定义的颜色的静态成员的类 我从dreamincode.net的这篇文章中获得了用户no2pencil提供的
color
函数
我这样做是为了能够像这样使用std::cout流中的静态常量:
cout << zkr::cc::fore::red << "This is red text. "
<< zkr::cc::console << "And changing to console default colors, fg, bg."
<< endl;
它可以与cc
静态类的fore
和back
静态子类一起使用
编辑2017
我只是在这里添加类代码,以便更实用
颜色代码宏:
#define CC_CONSOLE_COLOR_DEFAULT "\033[0m"
#define CC_FORECOLOR(C) "\033[" #C "m"
#define CC_BACKCOLOR(C) "\033[" #C "m"
#define CC_ATTR(A) "\033[" #A "m"
以及定义屏幕颜色或属性的主颜色函数:
char *cc::color(int attr, int fg, int bg)
{
static char command[13];
/* Command is the control command to the terminal */
sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
return command;
}
ccolor.h
#include <stdio.h>
#define CC_CONSOLE_COLOR_DEFAULT "\033[0m"
#define CC_FORECOLOR(C) "\033[" #C "m"
#define CC_BACKCOLOR(C) "\033[" #C "m"
#define CC_ATTR(A) "\033[" #A "m"
namespace zkr
{
class cc
{
public:
class fore
{
public:
static const char *black;
static const char *blue;
static const char *red;
static const char *magenta;
static const char *green;
static const char *cyan;
static const char *yellow;
static const char *white;
static const char *console;
static const char *lightblack;
static const char *lightblue;
static const char *lightred;
static const char *lightmagenta;
static const char *lightgreen;
static const char *lightcyan;
static const char *lightyellow;
static const char *lightwhite;
};
class back
{
public:
static const char *black;
static const char *blue;
static const char *red;
static const char *magenta;
static const char *green;
static const char *cyan;
static const char *yellow;
static const char *white;
static const char *console;
static const char *lightblack;
static const char *lightblue;
static const char *lightred;
static const char *lightmagenta;
static const char *lightgreen;
static const char *lightcyan;
static const char *lightyellow;
static const char *lightwhite;
};
static char *color(int attr, int fg, int bg);
static const char *console;
static const char *underline;
static const char *bold;
};
}
在OSX外壳上,这对我来说很有用(包括“红色文本”前面的2个空格): 基础
我编写了一个C++类,可以用来设置输出的前景和背景颜色。此示例程序作为打印
This->word的一个示例,请在此处尝试我的标题,以获得一种快速简便的文本着色方法:
转义序列颜色标题
使用C++在Unix中输出输出!!
文本属性选项:
颜色选项:
格式:
常规格式,在$variable中包含所需的值$
COLOR_$Foreground_Color$_$Background_Color$
COLOR_$Text_Attribute$_$Foreground_Color$_$Background_Color$
COLOR_NORMAL // To set color to default
e、 g
用法:
在输出文本和文本之前,只需使用流式显示所需的颜色即可
再次使用可在输出文本后将颜色设置为正常
cout << COLOR_BLUE_BLACK << "TEXT" << COLOR_NORMAL << endl;
cout << COLOR_BOLD_YELLOW_CYAN << "TEXT" << COLOR_NORMAL << endl;
cout正如其他人所说,您可以使用转义字符。
您可以使用以使其更容易:
#ifndef _COLORS_
#define _COLORS_
/* FOREGROUND */
#define RST "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define FRED(x) KRED x RST
#define FGRN(x) KGRN x RST
#define FYEL(x) KYEL x RST
#define FBLU(x) KBLU x RST
#define FMAG(x) KMAG x RST
#define FCYN(x) KCYN x RST
#define FWHT(x) KWHT x RST
#define BOLD(x) "\x1B[1m" x RST
#define UNDL(x) "\x1B[4m" x RST
#endif /* _COLORS_ */
使用标头宏的示例可以是:
#include <iostream>
#include "colors.h"
using namespace std;
int main()
{
cout << FBLU("I'm blue.") << endl;
cout << BOLD(FBLU("I'm blue-bold.")) << endl;
return 0;
}
#包括
#包括“colors.h”
使用名称空间std;
int main()
{
cout我使用以下解决方案,它非常简单和优雅,可以轻松粘贴到源代码中,并且在Linux/Bash上工作:
const std::string red("\033[0;31m");
const std::string green("\033[1;32m");
const std::string yellow("\033[1;33m");
const std::string cyan("\033[0;36m");
const std::string magenta("\033[0;35m");
const std::string reset("\033[0m");
std::cout << "Measured runtime: " << yellow << timer.count() << reset << std::endl;
const std::字符串红色(“\033[0;31m”);
常量标准::字符串绿色(“\033[1;32m”);
常量标准::字符串黄色(“\033[1;33m”);
常量标准::字符串青色(“\033[0;36m”);
常量标准::字符串洋红色(“\033[0;35m”);
常量标准::字符串重置(“\033[0m”);
std::cout您可以使用ANSI颜色代码
使用这些函数
enum c_color{BLACK=30,RED=31,GREEN=32,YELLOW=33,BLUE=34,MAGENTA=35,CYAN=36,WHITE=37};
enum c_decoration{NORMAL=0,BOLD=1,FAINT=2,ITALIC=3,UNDERLINE=4,RIVERCED=26,FRAMED=51};
void pr(const string str,c_color color,c_decoration decoration=c_decoration::NORMAL){
cout<<"\033["<<decoration<<";"<<color<<"m"<<str<<"\033[0m";
}
void prl(const string str,c_color color,c_decoration decoration=c_decoration::NORMAL){
cout<<"\033["<<decoration<<";"<<color<<"m"<<str<<"\033[0m"<<endl;
}
#include <iostream>
#include "COLORS.h"
int main() {
std::cout << SetBackBLU << SetForeRED << endl;
std::cout << "I am red text on a blue background! :) " << endl;
return 0;
}
enum c_color{黑色=30,红色=31,绿色=32,黄色=33,蓝色=34,品红色=35,青色=36,白色=37};
枚举c_装饰{NORMAL=0,BOLD=1,light=2,ITALIC=3,UNDERLINE=4,RIVERCED=26,FRAMED=51};
void pr(常量字符串str,c_颜色,c_装饰装饰=c_装饰::正常){
据我所知,这是一个典型的ANSI颜色代码
"\033[{FORMAT_ATTRIBUTE};{FORGROUND_COLOR};{BACKGROUND_COLOR}m{TEXT}\033[{RESET_FORMATE_ATTRIBUTE}m"
由(名称和编解码器)组成
- 格式属性
{ "Default", "0" },
{ "Bold", "1" },
{ "Dim", "2" },
{ "Italics", "3"},
{ "Underlined", "4" },
{ "Blink", "5" },
{ "Reverse", "7" },
{ "Hidden", "8" }
{ "All", "0" },
{ "Bold", "21" },
{ "Dim", "22" },
{ "Underlined", "24" },
{ "Blink", "25" },
{ "Reverse", "27" },
{ "Hidden", "28" }
- 放弃颜色
{ "Default", "39" },
{ "Black", "30" },
{ "Red", "31" },
{ "Green", "32" },
{ "Yellow", "33" },
{ "Blue", "34" },
{ "Magenta", "35" },
{ "Cyan", "36" },
{ "Light Gray", "37" },
{ "Dark Gray", "90" },
{ "Light Red", "91" },
{ "Light Green", "92" },
{ "Light Yellow", "93" },
{ "Light Blue", "94" },
{ "Light Magenta", "95" },
{ "Light Cyan", "96" },
{ "White", "97" }
{ "Default", "49" },
{ "Black", "40" },
{ "Red", "41" },
{ "Green", "42" },
{ "Yellow", "43" },
{ "Blue", "44" },
{ "Megenta", "45" },
{ "Cyan", "46" },
{ "Light Gray", "47" },
{ "Dark Gray", "100" },
{ "Light Red", "101" },
{ "Light Green", "102" },
{ "Light Yellow", "103" },
{ "Light Blue", "104" },
{ "Light Magenta", "105" },
{ "Light Cyan", "106" },
{ "White", "107" }
- 背景色
{ "Default", "39" },
{ "Black", "30" },
{ "Red", "31" },
{ "Green", "32" },
{ "Yellow", "33" },
{ "Blue", "34" },
{ "Magenta", "35" },
{ "Cyan", "36" },
{ "Light Gray", "37" },
{ "Dark Gray", "90" },
{ "Light Red", "91" },
{ "Light Green", "92" },
{ "Light Yellow", "93" },
{ "Light Blue", "94" },
{ "Light Magenta", "95" },
{ "Light Cyan", "96" },
{ "White", "97" }
{ "Default", "49" },
{ "Black", "40" },
{ "Red", "41" },
{ "Green", "42" },
{ "Yellow", "43" },
{ "Blue", "44" },
{ "Megenta", "45" },
{ "Cyan", "46" },
{ "Light Gray", "47" },
{ "Dark Gray", "100" },
{ "Light Red", "101" },
{ "Light Green", "102" },
{ "Light Yellow", "103" },
{ "Light Blue", "104" },
{ "Light Magenta", "105" },
{ "Light Cyan", "106" },
{ "White", "107" }
- 正文
- 重置格式属性
{ "Default", "0" },
{ "Bold", "1" },
{ "Dim", "2" },
{ "Italics", "3"},
{ "Underlined", "4" },
{ "Blink", "5" },
{ "Reverse", "7" },
{ "Hidden", "8" }
{ "All", "0" },
{ "Bold", "21" },
{ "Dim", "22" },
{ "Underlined", "24" },
{ "Blink", "25" },
{ "Reverse", "27" },
{ "Hidden", "28" }
有了这些信息,就可以很容易地将字符串“我是一个香蕉!”的颜色设置为圆形“黄色”和背景色“绿色”,如下所示
"\033[0;33;42mI am a Banana!\033[0m"
或用C++库< /P>
auto-const&colorized_text=color::rize(“我是香蕉!”、“黄”、“绿”);
标准::coutgon1332标题的扩展版本:
//
// COLORS.h
//
// Posted by Gon1332 May 15 2015 on StackOverflow
// https://stackoverflow.com/questions/2616906/how-do-i-output-coloured-text-to-a-linux-terminal#2616912
//
// Description: An easy header file to make colored text output to terminal second nature.
// Modified by Shades Aug. 14 2018
// PLEASE carefully read comments before using this tool, this will save you a lot of bugs that are going to be just about impossible to find.
#ifndef COLORS_h
#define COLORS_h
/* FOREGROUND */
// These codes set the actual text to the specified color
#define RESETTEXT "\x1B[0m" // Set all colors back to normal.
#define FOREBLK "\x1B[30m" // Black
#define FORERED "\x1B[31m" // Red
#define FOREGRN "\x1B[32m" // Green
#define FOREYEL "\x1B[33m" // Yellow
#define FOREBLU "\x1B[34m" // Blue
#define FOREMAG "\x1B[35m" // Magenta
#define FORECYN "\x1B[36m" // Cyan
#define FOREWHT "\x1B[37m" // White
/* BACKGROUND */
// These codes set the background color behind the text.
#define BACKBLK "\x1B[40m"
#define BACKRED "\x1B[41m"
#define BACKGRN "\x1B[42m"
#define BACKYEL "\x1B[43m"
#define BACKBLU "\x1B[44m"
#define BACKMAG "\x1B[45m"
#define BACKCYN "\x1B[46m"
#define BACKWHT "\x1B[47m"
// These will set the text color and then set it back to normal afterwards.
#define BLK(x) FOREBLK x RESETTEXT
#define RED(x) FORERED x RESETTEXT
#define GRN(x) FOREGRN x RESETTEXT
#define YEL(x) FOREYEL x RESETTEXT
#define BLU(x) FOREBLU x RESETTEXT
#define MAG(x) FOREMAG x RESETTEXT
#define CYN(x) FORECYN x RESETTEXT
#define WHT(x) FOREWHT x RESETTEXT
// Example usage: cout << BLU("This text's color is now blue!") << endl;
// These will set the text's background color then reset it back.
#define BackBLK(x) BACKBLK x RESETTEXT
#define BackRED(x) BACKRED x RESETTEXT
#define BackGRN(x) BACKGRN x RESETTEXT
#define BackYEL(x) BACKYEL x RESETTEXT
#define BackBLU(x) BACKBLU x RESETTEXT
#define BackMAG(x) BACKMAG x RESETTEXT
#define BackCYN(x) BACKCYN x RESETTEXT
#define BackWHT(x) BACKWHT x RESETTEXT
// Example usage: cout << BACKRED(FOREBLU("I am blue text on a red background!")) << endl;
// These functions will set the background to the specified color indefinitely.
// NOTE: These do NOT call RESETTEXT afterwards. Thus, they will set the background color indefinitely until the user executes cout << RESETTEXT
// OR if a function is used that calles RESETTEXT i.e. cout << RED("Hello World!") will reset the background color since it calls RESETTEXT.
// To set text COLOR indefinitely, see SetFore functions below.
#define SetBackBLK BACKBLK
#define SetBackRED BACKRED
#define SetBackGRN BACKGRN
#define SetBackYEL BACKYEL
#define SetBackBLU BACKBLU
#define SetBackMAG BACKMAG
#define SetBackCYN BACKCYN
#define SetBackWHT BACKWHT
// Example usage: cout << SetBackRED << "This text's background and all text after it will be red until RESETTEXT is called in some way" << endl;
// These functions will set the text color until RESETTEXT is called. (See above comments)
#define SetForeBLK FOREBLK
#define SetForeRED FORERED
#define SetForeGRN FOREGRN
#define SetForeYEL FOREYEL
#define SetForeBLU FOREBLU
#define SetForeMAG FOREMAG
#define SetForeCYN FORECYN
#define SetForeWHT FOREWHT
// Example usage: cout << SetForeRED << "This text and all text after it will be red until RESETTEXT is called in some way" << endl;
#define BOLD(x) "\x1B[1m" x RESETTEXT // Embolden text then reset it.
#define BRIGHT(x) "\x1B[1m" x RESETTEXT // Brighten text then reset it. (Same as bold but is available for program clarity)
#define UNDL(x) "\x1B[4m" x RESETTEXT // Underline text then reset it.
// Example usage: cout << BOLD(BLU("I am bold blue text!")) << endl;
// These functions will embolden or underline text indefinitely until RESETTEXT is called in some way.
#define SetBOLD "\x1B[1m" // Embolden text indefinitely.
#define SetBRIGHT "\x1B[1m" // Brighten text indefinitely. (Same as bold but is available for program clarity)
#define SetUNDL "\x1B[4m" // Underline text indefinitely.
// Example usage: cout << setBOLD << "I and all text after me will be BOLD/Bright until RESETTEXT is called in some way!" << endl;
#endif /* COLORS_h */
//
//颜色
//
//Gon1332于2015年5月15日在StackOverflow上发布
// https://stackoverflow.com/questions/2616906/how-do-i-output-coloured-text-to-a-linux-terminal#2616912
//
//描述:一个简单的头文件,使彩色文本输出到终端的第二性质。
//2018年8月14日修订
//在使用此工具之前,请仔细阅读评论,这将为您节省大量无法找到的bug。
#ifndef颜色
#定义颜色
/*前景*/
//这些代码将实际文本设置为指定的颜色
#定义RESETTEXT“\x1B[0m”//将所有颜色设置回正常值。
#定义FOREBLK“\x1B[30m”//Black
#定义FORERED“\x1B[31m”//Red
#定义FOREGRN“\x1B[32m”//Green
#定义FOREYEL“\x1B[33m”//Yellow
#定义FOREBLU“\x1B[34m”//Blue
#定义工头标记“\x1B[35m”//Magenta
#定义FORECYN“\x1B[36m”//Cyan
#定义前缀“\x1B[37m”//White
/*背景*/
//这些代码设置文本后面的背景色。
#定义BACKBLK“\x1B[40m”
#定义背景“\x1B[41m”
#定义BACKGRN“\x1B[42m”
#定义BACKYEL“\x1B[43m”
#定义BACKBLU“\x1B[44m”
#定义BACKMAG“\x1B[45m”
#定义BACKCYN“\x1B[46m”
#定义BACKWHT“\x1B[47m”
//这些将设置文本颜色,然后将其设置回正常。
#定义BLK(x)FOREBLK x RESETTEXT
#定义红色(x)Forred x RESETTEXT
#定义GRN(x)FOREGRN
{ "Default", "39" },
{ "Black", "30" },
{ "Red", "31" },
{ "Green", "32" },
{ "Yellow", "33" },
{ "Blue", "34" },
{ "Magenta", "35" },
{ "Cyan", "36" },
{ "Light Gray", "37" },
{ "Dark Gray", "90" },
{ "Light Red", "91" },
{ "Light Green", "92" },
{ "Light Yellow", "93" },
{ "Light Blue", "94" },
{ "Light Magenta", "95" },
{ "Light Cyan", "96" },
{ "White", "97" }
{ "Default", "49" },
{ "Black", "40" },
{ "Red", "41" },
{ "Green", "42" },
{ "Yellow", "43" },
{ "Blue", "44" },
{ "Megenta", "45" },
{ "Cyan", "46" },
{ "Light Gray", "47" },
{ "Dark Gray", "100" },
{ "Light Red", "101" },
{ "Light Green", "102" },
{ "Light Yellow", "103" },
{ "Light Blue", "104" },
{ "Light Magenta", "105" },
{ "Light Cyan", "106" },
{ "White", "107" }
{ "All", "0" },
{ "Bold", "21" },
{ "Dim", "22" },
{ "Underlined", "24" },
{ "Blink", "25" },
{ "Reverse", "27" },
{ "Hidden", "28" }
"\033[0;33;42mI am a Banana!\033[0m"
auto const& colorized_text = color::rize( "I am a banana!", "Yellow", "Green" );
std::cout << colorized_text << std::endl;
//
// COLORS.h
//
// Posted by Gon1332 May 15 2015 on StackOverflow
// https://stackoverflow.com/questions/2616906/how-do-i-output-coloured-text-to-a-linux-terminal#2616912
//
// Description: An easy header file to make colored text output to terminal second nature.
// Modified by Shades Aug. 14 2018
// PLEASE carefully read comments before using this tool, this will save you a lot of bugs that are going to be just about impossible to find.
#ifndef COLORS_h
#define COLORS_h
/* FOREGROUND */
// These codes set the actual text to the specified color
#define RESETTEXT "\x1B[0m" // Set all colors back to normal.
#define FOREBLK "\x1B[30m" // Black
#define FORERED "\x1B[31m" // Red
#define FOREGRN "\x1B[32m" // Green
#define FOREYEL "\x1B[33m" // Yellow
#define FOREBLU "\x1B[34m" // Blue
#define FOREMAG "\x1B[35m" // Magenta
#define FORECYN "\x1B[36m" // Cyan
#define FOREWHT "\x1B[37m" // White
/* BACKGROUND */
// These codes set the background color behind the text.
#define BACKBLK "\x1B[40m"
#define BACKRED "\x1B[41m"
#define BACKGRN "\x1B[42m"
#define BACKYEL "\x1B[43m"
#define BACKBLU "\x1B[44m"
#define BACKMAG "\x1B[45m"
#define BACKCYN "\x1B[46m"
#define BACKWHT "\x1B[47m"
// These will set the text color and then set it back to normal afterwards.
#define BLK(x) FOREBLK x RESETTEXT
#define RED(x) FORERED x RESETTEXT
#define GRN(x) FOREGRN x RESETTEXT
#define YEL(x) FOREYEL x RESETTEXT
#define BLU(x) FOREBLU x RESETTEXT
#define MAG(x) FOREMAG x RESETTEXT
#define CYN(x) FORECYN x RESETTEXT
#define WHT(x) FOREWHT x RESETTEXT
// Example usage: cout << BLU("This text's color is now blue!") << endl;
// These will set the text's background color then reset it back.
#define BackBLK(x) BACKBLK x RESETTEXT
#define BackRED(x) BACKRED x RESETTEXT
#define BackGRN(x) BACKGRN x RESETTEXT
#define BackYEL(x) BACKYEL x RESETTEXT
#define BackBLU(x) BACKBLU x RESETTEXT
#define BackMAG(x) BACKMAG x RESETTEXT
#define BackCYN(x) BACKCYN x RESETTEXT
#define BackWHT(x) BACKWHT x RESETTEXT
// Example usage: cout << BACKRED(FOREBLU("I am blue text on a red background!")) << endl;
// These functions will set the background to the specified color indefinitely.
// NOTE: These do NOT call RESETTEXT afterwards. Thus, they will set the background color indefinitely until the user executes cout << RESETTEXT
// OR if a function is used that calles RESETTEXT i.e. cout << RED("Hello World!") will reset the background color since it calls RESETTEXT.
// To set text COLOR indefinitely, see SetFore functions below.
#define SetBackBLK BACKBLK
#define SetBackRED BACKRED
#define SetBackGRN BACKGRN
#define SetBackYEL BACKYEL
#define SetBackBLU BACKBLU
#define SetBackMAG BACKMAG
#define SetBackCYN BACKCYN
#define SetBackWHT BACKWHT
// Example usage: cout << SetBackRED << "This text's background and all text after it will be red until RESETTEXT is called in some way" << endl;
// These functions will set the text color until RESETTEXT is called. (See above comments)
#define SetForeBLK FOREBLK
#define SetForeRED FORERED
#define SetForeGRN FOREGRN
#define SetForeYEL FOREYEL
#define SetForeBLU FOREBLU
#define SetForeMAG FOREMAG
#define SetForeCYN FORECYN
#define SetForeWHT FOREWHT
// Example usage: cout << SetForeRED << "This text and all text after it will be red until RESETTEXT is called in some way" << endl;
#define BOLD(x) "\x1B[1m" x RESETTEXT // Embolden text then reset it.
#define BRIGHT(x) "\x1B[1m" x RESETTEXT // Brighten text then reset it. (Same as bold but is available for program clarity)
#define UNDL(x) "\x1B[4m" x RESETTEXT // Underline text then reset it.
// Example usage: cout << BOLD(BLU("I am bold blue text!")) << endl;
// These functions will embolden or underline text indefinitely until RESETTEXT is called in some way.
#define SetBOLD "\x1B[1m" // Embolden text indefinitely.
#define SetBRIGHT "\x1B[1m" // Brighten text indefinitely. (Same as bold but is available for program clarity)
#define SetUNDL "\x1B[4m" // Underline text indefinitely.
// Example usage: cout << setBOLD << "I and all text after me will be BOLD/Bright until RESETTEXT is called in some way!" << endl;
#endif /* COLORS_h */
#include <iostream>
#include "COLORS.h"
int main() {
std::cout << SetBackBLU << SetForeRED << endl;
std::cout << "I am red text on a blue background! :) " << endl;
return 0;
}
//hello.cpp
#include "color_ostream.h"
using namespace color_ostream;
int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {
rd_wcout.imbue(std::locale(std::locale(),"",LC_CTYPE));
rd_wcout << L"Hello world\n";
rd_wcout << L"Hola Mundo\n";
rd_wcout << L"Bonjour le monde\n";
rd256_wcout << L"\n256 color" << std::endl;
rd256_wcout << L"Hello world\n";
rd256_wcout << L"Hola Mundo\n";
rd256_wcout << L"Bonjour le monde\n";
rdtrue_wcout << L"\ntrue color" << std::endl;
rdtrue_wcout << L"Hello world\n";
rdtrue_wcout << L"Hola Mundo\n";
rdtrue_wcout << L"Bonjour le monde\n";
return 0;
}