termcolor-c
·118 words·1 min
termcolor-c #
Simple color printing in C
Example #
#include "termcolor.h"
#include <stdio.h>
int main() {
cprint("Passed\n", FG_GREEN);
cprint("Failed\n", FG_RED);
char *msg = "Hello!!";
char *new;
color(msg, new, FG_BLUE);
printf("%s\n", new);
return 0;
}
Quick start #
Add termcolor as a dependency #
git submodule add git@github.com:JakeRoggenbuck/termcolor-c.git
For CMakeLists.txt (if you are using that) #
-add_executable(project_name ${SOURCES})
+add_executable(project_name ${SOURCES} termcolor-c/src/termcolor.c)
+include_directories(${PROJECT_SOURCE_DIR}/termcolor-c/src)
Add the color printing code #
#include "termcolor.h"
#include <stdio.h>
int main() {
cprint("Hello World!\n", FG_GREEN);
return 0;
}
Why #
I made this just in case I start writing a bunch of CLI stuff in C in the next few months before college, and during college as well. So far, here are my favorites: