Skip to content

springlie/coprintf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coprintf

Colorful printf for C Code ( ascii color only )


Overview

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.

Screenshot

Active

screenshot

Inactive

screenshot

Install

Before using coprintf, simply include the header in your files like this:

#include "coprintf.h"

Usage

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

Leader Character

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.

Foreground color flag

mode color
k black
r red
g green
y yellow
b blue
p purple
c cyan
w write

Background color flag

mode color
K black
R red
G green
Y yellow
B blue
P purple
C cyan
W write

Action flag

mode action
d done
h highlight
u underline
e reverse
l blink
v invisible

Example (use default leader '^' )

set fg to red:
coprintf("^r%s","hello world !");

or

coprintf("^rhello world !");
set fg to red, bg to yellow, action to highlight and underline:
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

Macro

**You can customize the below Macros in coprintf.h file:

CO_PRINTF_INACTIVE

Default: not set.

coprintf will be disabled if CO_PRINTF_INACTIVE is set like this:

/* disable colorful ouptput */
#define CO_PRINTF_INACTIVE	
CO_PRINTF_LEADER

Default: '^'

The <leader> char can be customized by CO_PRINTF_LEADER:

/* set '#' as the <leader> char*/
#define CO_PRINTF_LEADER	'#'

Advanced

  • 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.

What's more

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!

About

Self-adapting colorful print/printf wrapper for C Code.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages