First commit

This commit is contained in:
Rahul M. Juliato 2019-10-17 21:38:07 -03:00
commit 63616ca0e0
2 changed files with 125 additions and 0 deletions

83
nocurses.h Normal file
View File

@ -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 <stdio.h>
#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);
}

42
readme.md Normal file
View File

@ -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 |