Simple C Library to write UTF8 code in Windows and macOS and Linux in console mode.
demo_video.mp4
I use this lib in my project cubeAscii to display the cube in the console with colors for Windows, macOS and Linux.
- Write UTF8
- Set font color
- Set text highlight
- Bold text
- Manual FG and BG color selection (24 bits)
To use the lib, download the cUnicodeLib file header and include it in your project.
#include "cUnicodeLib.h"
Then, you need to initialize the lib with the function initUnicodeLib()
.
void initUnicodeLib();
Be sure to test if the lib is correctly initialized, prefer using the function this way:
if (initUnicodeLib() == 0)
{
printf("UnicodeLib initialized successfully\n");
}
else
{
fprintf(stderr, "UnicodeLib initialization failed\n");
return 1;
}
To write a text you can use the function below:
printf("кошка 日本国");
To set the font color you can use the function below:
printf(ESC_COLOR_RED "кошка 日本国");
To set the text highlight you can use the function below:
printf(ESC_HIGHLIGHT "кошка 日本国");
To reset the color and highlight you can use the function below:
printf(ESC_RESET_ALL "кошка 日本国");
You can still use the varying arguments of the printf function.
printf(ESC_FG_B_BLUE ESC_BG_B_RED "Varying argument %d and %d" ESC_RESET_ALL "\n",1 , 2 );
Check the main.c
file in the test
folder for more examples.
Note:
If you don't call theESC_RESET_ALL
function, the color and highlight will be kept for the next prints.
The demo can be found in the test
folder.
Use CMake or the command line to compile the demo.
The output should be like this:
The project is set with a set of different scripts:
- CMake : to build the project for Windows, macOS and Linux
- flawfinder : to check for security flaws in the code
- CodeQl : to check for code quality and security
- Microsoft C++ Code Analysis : Microsoft code analysis tool
cppreference:
https://en.cppreference.com/w/
Microsoft:
https://docs.microsoft.com/en-us/cpp/?view=msvc-170
Wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
Quentin MOREL :
- @Im-Rises
- https://github.com/Im-Rises