commit c25b385500ae50e5f77b0cb1b1e895cda8ad0c55 Author: Unbewohnte Date: Wed Jan 11 17:01:59 2023 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..422843a --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +test: + gcc test.c -O2 -static -Wall -Werror -Wextra -o test + +clean: + rm -f test \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d560fe --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# cansic - C ANSI colors collection + +``` +``` \ No newline at end of file diff --git a/cansic.h b/cansic.h new file mode 100644 index 0000000..c8e91dd --- /dev/null +++ b/cansic.h @@ -0,0 +1,41 @@ +#ifndef CANSICC_H +#define CANSICC_H + +#define CANSIC_ESC "\033[" +#define CANSIC_END "\033[0m" +#define _ANSISEQUENCE(n) CANSIC_ESC #n + +#define CANSIC_RESET _ANSISEQUENCE(0) "m" +#define CANSIC_BOLD _ANSISEQUENCE(1) "m" +#define CANSIC_FAINT _ANSISEQUENCE(2) "m" +#define CANSIC_ITALIC _ANSISEQUENCE(3) "m" +#define CANSIC_UNDERLINE _ANSISEQUENCE(4) "m" +#define CANSIC_SLOWBLINK _ANSISEQUENCE(5) "m" +#define CANSIC_RAPIDBLINK _ANSISEQUENCE(6) "m" +#define CANSIC_SWAPFGBGCOLORS _ANSISEQUENCE(7) "m" +#define CANSIC_CONCEAL _ANSISEQUENCE(8) "m" +#define CANSIC_CROSSEDOUT _ANSISEQUENCE(9) "m" +#define CANSIC_FRACTUR _ANSISEQUENCE(20) "m" +#define CANSIC_BOLDOFF _ANSISEQUENCE(21) "m" +#define CANSIC_NORMALCOLOR _ANSISEQUENCE(22) "m" +#define CANSIC_NOTITALNOTFRAKTUR _ANSISEQUENCE(23) "m" +#define CANSIC_UNDERLINEOFF _ANSISEQUENCE(24) "m" +#define CANSIC_BLINKOFF _ANSISEQUENCE(25) "m" +#define CANSIC_INVERSEOFF _ANSISEQUENCE(27) "m" +#define CANSIC_REVEAL _ANSISEQUENCE(28) "m" +#define CANSIC_NOTCROSSEDOUT _ANSISEQUENCE(29) "m" +#define CANSIC_SETFGCOLOR _ANSISEQUENCE(38) +#define CANSIC_DEFAULTFGCOLOR _ANSISEQUENCE(39) "m" +#define CANSIC_SETBGCOLOR _ANSISEQUENCE(48) +#define CANSIC_DEFAULTBGCOLOR _ANSISEQUENCE(49) "m" +#define CANSIC_DIABLEPROPORTIONALSPACING _ANSISEQUENCE(50) "m" +#define CANSIC_FRAMED _ANSISEQUENCE(51) "m" +#define CANSIC_ENCIRCLED _ANSISEQUENCE(52) "m" +#define CANSIC_OVERLINED _ANSISEQUENCE(53) "m" +#define CANSIC_NOTFRAMEDNOTENCIRCLED _ANSISEQUENCE(54) "m" +#define CANSIC_NOTOVERLINED _ANSISEQUENCE(55) "m" + +#define CANSIC_FG_RGB(r, g, b) CANSIC_SETFGCOLOR ";2;" #r ";" #g ";" #b "m" +#define CANSIC_BG_RGB(r, g, b) CANSIC_SETBGCOLOR ";2;" #r ";" #g ";" #b "m" + +#endif \ No newline at end of file diff --git a/test.c b/test.c new file mode 100644 index 0000000..fa7a64d --- /dev/null +++ b/test.c @@ -0,0 +1,16 @@ +#include "cansic.h" +#include + +int main(void) { + const char* text = "This is a text"; + printf("%s%s%s\n", CANSIC_BOLD, text, CANSIC_END); + printf("%s%s%s\n", CANSIC_ITALIC, text, CANSIC_END); + printf("%s%s%s\n", CANSIC_UNDERLINE, text, CANSIC_END); + printf("%s%s%s\n", CANSIC_RAPIDBLINK, text, CANSIC_END); + printf("%s\n", CANSIC_BOLD CANSIC_UNDERLINE CANSIC_SLOWBLINK "String literals are more elegant" CANSIC_END); + + printf("%s%s%s\n", CANSIC_FG_RGB(90, 50, 200), text, CANSIC_END); + printf("%s%s%s\n", CANSIC_BG_RGB(255, 55, 55), text, CANSIC_END); + + return 0; +} \ No newline at end of file