Skip to content

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

License

Notifications You must be signed in to change notification settings

Im-Rises/cUnicodeLib

Repository files navigation

cUnicodeLib

cmakeLogo cLogo cppLogo

Description

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

Images

Capture d'écran 2023-05-16 222504

Video Demo

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.

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:

Capture d'écran 2023-05-16 222504

Github-Actions

CMake flawfinder CodeQL Microsoft C++ Code Analysis

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 :

GitHub contributors

About

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

Topics

Resources

License

Stars

Watchers

Forks