We often use ASCII color like \033[0m
when developing. But it's hard to remember them.
When writing shell, we can use CLEAR='\033[0m'
, but for C, I have to write the implementation myself.
So I use {color}
for text color and [color]
for background color, and make them map to print the color, that's this project. Simple, stupid, maybe a bit useless.
I use it to format output in my program.
You can just use cprintf as a modified version of "echo -ne" with the color format support. If the color in {}
or []
is not recognized, it will just output the original string.
cprintf()
and cfprintf()
is a macro and will not return anything.
You can import include/cprintf.h and cprintf.c to your project, and use cprintf()
and cfprintf()
just like printf()
and fprintf()
.
These color format will be recognized:
clear :reset the color.
underline :underline
highlight :highlight
red
blue
green
yellow
cyan
black
white
purple
base :You need to define it.
R;G;B :RGB color.
Use {color}
for foreground color and [color]
for background color.
Note that cprintf() will always clear the color in the end once you call it, but for background color, you need a [clear]
before \n
.
#include "include/cprintf.h"
int main()
{
cprintf("[91;207;250] [clear]\n");
cprintf("[245;170;185] [clear]\n");
cprintf("[255;255;255] [clear]\n");
cprintf("[245;170;185] [clear]\n");
cprintf("[91;207;250] [clear]\n");
}
何もない僕たちに
なぜ夢を見させたか
終わりある人生に
なぜ希望を持たせたか
なぜこの手をすり抜ける
ものばかり与えたか
それでもなおしがみつく
僕らは醜いかい
それとも、きれいかい