cprintf is a header-only C library that adds ANSI colours and attributes to printf without having to write the full code out. This makes it easy to add coloured and styled text to your terminal output.
- Header-only library
- Supports ANSI colours for foreground and background
- Supports various text attributes
- Easy integration with existing code
Simply include the cprintf.h header file in your project.
To use cprintf, define CPRINTF_IMPLEMENTATION before including the header file in one of your source files.
#define CPRINTF_IMPLEMENTATION
#include "cprintf.h"Then, you can use cprintf, cfprintf, cvfprintf, csnprintf, and cvsnprintf in your code just like printf, but with additional formatting options.
Aditionally, you can enable/disable colored output with: cprintf_enable, cprintf_disable, cprintf_toggle, and cprintf_get_status. The default behavior is enabled, this can be overwritten by defining CPRINTF_ENABLE_FLAG_DEFAULT to either 0 (disabled) or 1 (enabled).
#define CPRINTF_IMPLEMENTATION
#define CPRINTF_ENABLE_FLAG_DEFAULT 0
#include "cprintf.h"#define CPRINTF_IMPLEMENTATION
#include "cprintf.h"
int main(int argc, char * argv[]) {
cprintf("%FbBLUE TEXT%Ar\n");
cprintf_disable();
cprintf("%FbNORMAL TEXT%Ar\n");
cprintf_enable();
cfprintf(stderr, "%FbBLUE TEXT%Ar\n");
return 0;
}-
%Fk: Black
-
%Fr: Red
-
%Fg: Green
-
%Fy: Yellow
-
%Fb: Blue
-
%Fm: Magenta
-
%Fc: Cyan
-
%Fw: White
-
%Bk: Black
-
%Br: Red
-
%Bg: Green
-
%By: Yellow
-
%Bb: Blue
-
%Bm: Magenta
-
%Bc: Cyan
-
%Bw: White
-
%Ar: Reset
-
%Ab: Bold
-
%Af: Dim
-
%Ai: Italic
-
%Au: Underline
-
%Al: Blink (slow)
-
%Ak: Blink (rapid)
-
%Av: Inverted
-
%Ah: Hidden
-
%As: Strikethrough
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to submit issues and pull requests. Contributions are welcome!