nocurses/nocurses.h

89 lines
1.5 KiB
C
Raw Normal View History

2019-10-18 03:38:07 +03:00
/*
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
2019-10-22 06:44:20 +03:00
Revision - oct 2019
2019-10-18 03:38:07 +03:00
*/
#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
2019-10-22 06:44:20 +03:00
int bg_color = BLACK,
font_color = WHITE,
font_bold = FALSE;
2019-10-18 03:38:07 +03:00
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);
2019-10-22 06:44:20 +03:00
font_color = color;
2019-10-18 03:38:07 +03:00
}
void setbgrcolor(int color){
printf("%c[4%dm", ESC, color);
2019-10-22 06:44:20 +03:00
bg_color = color;
2019-10-18 03:38:07 +03:00
}
void setfontbold(int status){
printf("%c[%dm", ESC, status);
2019-10-22 06:44:20 +03:00
font_bold = status;
setfontcolor(font_color);
setbgrcolor(bg_color);
2019-10-18 03:38:07 +03:00
}
void setunderline(int status){
if (status) status = 4;
printf("%c[%dm", ESC, status);
2019-10-22 06:44:20 +03:00
setfontcolor(font_color);
setbgrcolor(bg_color);
setfontbold(font_bold);
2019-10-18 03:38:07 +03:00
}
void setblink(int status){
if (status) status = 5;
printf("%c[%dm", ESC, status);
2019-10-22 06:44:20 +03:00
setfontcolor(font_color);
setbgrcolor(bg_color);
setfontbold(font_bold);
2019-10-18 03:38:07 +03:00
}
void clrline(){
printf("%c[2K%cE", ESC, ESC);
}
2019-10-18 03:44:02 +03:00
2019-10-22 06:44:20 +03:00
void resetcolors(){
printf("%c001b%c[0m", ESC, ESC);
}