cUnicodeLib

C header only Library to write UTF8 text to the console for Windows, macOs and Linux.

MIT License

Stars
4

cUnicodeLib

Description

Simple C Library to write UTF8 code in Windows and macOS and Linux in console mode.

Images

Video Demo

https://github.com/Im-Rises/cubeAscii/assets/59691442/f5bd5eae-67f1-4b75-88f0-6140808ba2f8

I use this lib in my project cubeAscii to display the cube in the console with colors for Windows, macOS and Linux.

Features

  • Write UTF8
  • Set font color
  • Set text highlight
  • Bold text
  • Manual FG and BG color selection (24 bits)

QuickStart

Setup

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;
}

Example

Write UTF8

To write a text you can use the function below:

printf(" ");

Set font color

To set the font color you can use the function below:

printf(ESC_COLOR_RED " ");

Set text highlight

To set the text highlight you can use the function below:

printf(ESC_HIGHLIGHT " ");

Reset all

To reset the color and highlight you can use the function below:

printf(ESC_RESET_ALL " ");

Use of the printf varyings

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.

Notes

Note: If you don't call the ESC_RESET_ALL function, the color and highlight will be kept for the next prints.

Demo Example

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:

Github-Actions

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

Documentations

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

Contributors

Quentin MOREL :

Badges
Extracted from project README
CMake flawfinder CodeQL Microsoft C++ Code Analysis GitHub contributors