Skip to content

raravel/cful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CFUL

Colorful console output in C

Language

What is CFUL?

CFUL is functions for colorful console output. It is support RGB system.

Support

  • Linux
  • Windows 10
  • MacOS

If your OS is not support true color, can use ansi color.

How to use?

You want this functions, then include only cful.h on your project.

#include "cful.h"



Get foreground color string

FG_COLOR(r, g, b);
_F(r, g, b);

Example

#include <stdio.h>
#include "cful.h"

int main ( void )
{
    printf(FG_COLOR(255, 0, 0)"Change font color red" RESET "\n");
    printf(_F(0, 255, 0) "Green" _F(0, 0, 255) "Blue" RESET "\n");
    return 0;
}



Get background color string

BG_COLOR(r, g, b);
_B(r, g, b);

Example

#include <stdio.h>
#include "cful.h"

int main ( void )
{
    printf(_F(255, 255, 255) BG_COLOR(255, 0, 0)"Change back color red" RESET "\n");
    printf(_F(255, 255, 255) _B(0, 255, 0) "Green" _B(0, 0, 255) "Blue" RESET "\n");
    return 0;
}



Set color

SET_COLOR(type, r, g, b);
SET_FG_COLOR(r, g, b);
SET_BG_COLOR(r, g, b);

Type is FOREGROUND or BACKGROUND define.

#define FOREGROUND  "38"
#define BACKGROUND  "48"

Example

#include <stdio.h>
#include "cful.h"

int main ( void )
{
    SET_COLOR(FOREGROUND, 255, 0, 0);
    printf("Set font color red");

    SET_BG_COLOR(0, 255, 0);
    printf("Set background color green");
    printf(RESET "\n");
    return 0;
}



Use ansi color

If your OS is not support true color, then use SET_ANSI_MODE(1) and you must use only SET_COLOR, SET_FG_COLOR, SET_BG_COLOR function.

SET_ANSI_COLOR(mode); // 1: enable, 0: disable

Example

#include <stdio.h>
#include "cful.h"

int main ( void )
{
    printf(_F(255, 0, 0) "Red true color" RESET "\n");

    SET_ANSI_MODE(1);
    SET_FG_COLOR(255, 0, 0); 
    printf("Red ansi color" RESET "\n");
    return 0;
}

Compile

When compile your project by gcc, then add library option for math.h in command.

gcc -o cful main.c -lm




Thanks.

About

Colorful output in CUI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published