From 63616ca0e013c1d223d24ee65201dfa0d3c974c7 Mon Sep 17 00:00:00 2001 From: "Rahul M. Juliato" Date: Thu, 17 Oct 2019 21:38:07 -0300 Subject: [PATCH] First commit --- nocurses.h | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 42 +++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 nocurses.h create mode 100644 readme.md diff --git a/nocurses.h b/nocurses.h new file mode 100644 index 0000000..8c1f83f --- /dev/null +++ b/nocurses.h @@ -0,0 +1,83 @@ +/* + nocurses.h - Provides a basic 'VT100 ESC sequences' printing without + the need to use ncurses. + This is inspired by Borland conio.h + + Author - Rahul M. Juliato + Original - 25 jun 2005 + Revision - 17 oct 2019 +*/ + +#include + +#define ESC 27 +#define BLACK 0 +#define RED 1 +#define GREEN 2 +#define YELLOW 3 +#define BLUE 4 +#define MAGENTA 5 +#define CYAN 6 +#define WHITE 7 + +#define TRUE 1 +#define FALSE 0 + + +int GdBgColor = 47, + GdFontColor = 30, + GdFontBold = 0 ; + + +void pause(){ + fgetc(stdin); +} + + +void clrscr(){ + printf("%c[2J%c[?6h", ESC, ESC); +} + + +void gotoxy(int x, int y){ + printf("%c[%d;%dH", ESC, y, x); +} + + +void setfontcolor(int color){ + printf("%c[3%dm", ESC, color); + GdFontColor = color; +} + +void setbgrcolor(int color){ + printf("%c[4%dm", ESC, color); + GdBgColor = color; +} + + +void setfontbold(int status){ + printf("%c[%dm", ESC, status); + GdFontBold = status; + setfontcolor(GdFontColor); + setbgrcolor(GdBgColor); +} + +void setunderline(int status){ + if (status) status = 4; + printf("%c[%dm", ESC, status); + setfontcolor(GdFontColor); + setbgrcolor(GdBgColor); + setfontbold(GdFontBold); +} + +void setblink(int status){ + if (status) status = 5; + printf("%c[%dm", ESC, status); + setfontcolor(GdFontColor); + setbgrcolor(GdBgColor); + setfontbold(GdFontBold); +} + +void clrline(){ + printf("%c[2K%cE", ESC, ESC); +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c264a9b --- /dev/null +++ b/readme.md @@ -0,0 +1,42 @@ +nocurses.h +---------- + +This library provides terminal manipulation capability by the use of VT100 ESC sequences. + +It is aimed to simple applications where ncurses is simple "too much". + +Inspired on the old Borland conio.h for DOS. + + +Functions Provided +------------------ +| Function | Description | Example | +|--------------------------|:--------------------------------------------------------------------------------------:|:--------------------:| +| pause() | Waits for the user to hit [ENTER]. | pause(); | +| clrscr() | Clears the screen. | clrscr(); | +| gotoxy(x, y) | Sets the cursor do the position x, y. Where x is the row number and y the line number. | gotoxy(10,25); | +| setfontcolor(color_name) | Sets the text color to one of the colors described on the color table below. | setfontcolor(RED); | +| setbgrcolor(color_name) | Sets the background color to one of the colors described on the color table below. | setbgrcolor(BLUE); | +| setfontbold(status) | Sets the bold atribute on or off. status can be TRUE or FALSE. | setfontbold(TRUE); | +| setunderline(status) | Sets the underline atribute on or off. status can be TRUE or FALSE. | setunderline(FALSE); | +| setblink(status) | Sets the blink atribute on or off. status can be TRUE or FALSE. | setblink(TRUE); | +| clrline() | Clears the row contents. | clrline(); | + + + +color_name +---------- + +Valid color names are: + +| color_name | +|:----------:| +| BLACK | +| RED | +| GREEN | +| YELLOW | +| BLUE | +| MAGENTA | +| CYAN | +| WHITE | +