Colorful printf for C Code ( ascii color only ), decorate your terminal with more colors.
A light, self-adapting wrapper of printf
with several useful features, makes easy work for changing foreground, background and text action ( highlight, underline, blink ... ) . It makes you easy to enable and disable colorizing in your c&cpp's output.
coprintf("^r%s","hello world !");
or
coprintf("^rhello world !");
coprintf("^r^Y^h^u%s","hello world !");
set [ red, yellow, highlight & underline ] for "hello", [ cyan, red, reverse ] for "world", [ green, black, blink ] for "!" :
coprintf("^r^Y^h^u%shello^d ^c^R^eworld^d ^g^K^l!");
Please refer to demo.c for more examples:
Simply include the header in your files, like this:
#include "coprintf.h"
coprintf("<leader>rHello <leader>bWorld");
ceprintf("<leader>rHello <leader>bWorld");
coprintf("<leader>r<leader>YHello <leader>b<leader>CWorld");
ceprintf("<leader>r<leader>YHello <leader>b<leader>CWorld");
macro CO_PRINTF_INACTIVE defined ? | colorize |
---|---|
yes | not colorful |
no | colorful |
output fd | colorize |
---|---|
not tty | not colorful |
tty | colorful |
What's <Leader>
Character ?
We define a character as the <leader>
which will combine the mode character as an escape character.
The default <leader>
is "^", but you can customize it to any char you want.
mode | color |
---|---|
<leader> k |
black |
<leader> r |
red |
<leader> g |
green |
<leader> y |
yellow |
<leader> b |
blue |
<leader> p |
purple |
<leader> c |
cyan |
<leader> w |
write |
mode | color |
---|---|
<leader> K |
black |
<leader> R |
red |
<leader> G |
green |
<leader> Y |
yellow |
<leader> B |
blue |
<leader> P |
purple |
<leader> C |
cyan |
<leader> W |
write |
mode | action |
---|---|
<leader> d |
done |
<leader> h |
highlight |
<leader> u |
underline |
<leader> e |
reverse |
<leader> l |
blink |
<leader> v |
invisible |
The mode control formats are easily memorized:
-
Foreground : almost the lowercase of color mode head, "black" is exceptive.
-
Background : almost the uppercase of color mode head, "black" is exceptive.
-
Controling : almost the lowercase of mode head, with some exceptions.
You can customize the below Macros in coprintf.h:
Default: not set.
coprintf
will be disabled if CO_PRINTF_INACTIVE
is set in coprintf.h
like this:
#define CO_PRINTF_INACTIVE
Or compiling with option like this:
-DCO_PRINTF_INACTIVE
Default: '^'
The <leader>
char can be customized by CO_PRINTF_LEADER
:
/* set '#' as the <leader> char*/
#define CO_PRINTF_LEADER '#'
coprintf
is self-adapting. When the colorful output is redirected to other file,coprintf
will disabled color automatically.- Action flag
<leader>d
will turn off all settings ( fg, bg and action ), Thus, in single command, you have to set flags again to make it work well once there are other strings after<leader>d
. - If you want to print the itself, try
<leader><leader>
; If the char after leader isn't defined as an escape char, it will be ignored. - It's not necessary use
<leader>d
at the begin/end of commands,coprintf
do it automatically. - Actions can overlaied.
This project is really same as cecho, which supports similar functions to echo
in shell script.