Colorful printf for C Code ( ascii color only )
A light wrapper of printf
, with color flags of foreground, background and action ( highlight, underline, blink ... ) . With it, you can easily colorize your output of C / CPP.
Before using coprintf
, simply include the header in your files like this:
#include "coprintf.h"
Support multi-string in one command:
coprintf("<leader>rHello <leader>bWorld");
Support stdout and stderr:
coprintf("<leader>rHello <leader>bWorld");
ceprintf("<leader>rHello <leader>bWorld");
Support setting foreground, background and action
coprintf("<leader>r<leader>YHello <leader>b<leader>CWorld");
Support switch the printf status:
#define CO_PRINTF_INACTIVE ---> normal output
/*#define CO_PRINTF_INACTIVE*/ ---> colorful output
We define a character as the character, who will combine the mode character as escape character.
The default option is "^", you can customize it to any char you want, before calling coprintf.
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.
mode | color |
---|---|
k | black |
r | red |
g | green |
y | yellow |
b | blue |
p | purple |
c | cyan |
w | write |
mode | color |
---|---|
K | black |
R | red |
G | green |
Y | yellow |
B | blue |
P | purple |
C | cyan |
W | write |
mode | action |
---|---|
d | done |
h | highlight |
u | underline |
e | reverse |
l | blink |
v | invisible |
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!");
More examples in demo.c
**You can customize the below Macros in coprintf.h
file:
Default: not set.
coprintf
will be disabled if CO_PRINTF_INACTIVE
is set like this:
/* disable colorful ouptput */
#define CO_PRINTF_INACTIVE
Default: '^'
The <leader>
char can be customized by CO_PRINTF_LEADER
:
/* set '#' as the <leader> char*/
#define CO_PRINTF_LEADER '#'
- 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. Yes, coprintf
is just the C version of cecho
!