Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef STDARG_H
- #define STDARG_H
- #include <stdarg.h>
- #endif
- #ifndef STDIO_H
- #define STDIO_H
- #include <stdio.h>
- #endif
- #ifndef CONCOL_H_
- #define CONCOL_H_
- enum CONST {
- NORMAL, BOLD, LIGHT, ITALIC, UNDERSTROKE, INVERT = 7, UNVISIBLE,
- BLACK = 30, RED, GREEN, BROWN, BLUE, PURPLE, CYAN, LIGHT_GRAY,
- BG_BLACK = 40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE, BG_PURPLE, BG_CYAN, BG_GRAY,
- RIGHT = 50, LEFT, UP, DOWN
- };
- void setColor(int count, ...); // - Set color style
- void setCursorPosition(int L, int C); // - Position the Cursor
- void clear(void); // - Clear the screen, move to (0,0)
- void out(const char * sym); // - Print wrapper
- void moveUpN(int N); // - Move the cursor up N lines
- void moveDownN(int N); // - Move the cursor down N lines
- void moveRightN(int N); // - Move the cursor forward N columns
- void moveLeftN(int N); // - Move the cursor backward N columns
- void moveCursor(int DIRECTION, int N); // - Move the cursor
- void eraseToENDL(void); // - Erase to end of line
- void saveCurPos(void); // - Save cursor position
- void restoreCurPos(void); // - Restore cursor position
- struct ANSI{
- void (*clear)(void);
- void (*pos)(int, int);
- void (*col)(int, ...);
- void (*out)(const char *);
- void (*up)(int);
- void (*down)(int);
- void (*right)(int);
- void (*left)(int);
- void (*move)(int, int);
- void (*erase)(void);
- void (*save)(void);
- void (*res)(void);
- };
- struct ANSI console = {
- clear,
- setCursorPosition,
- setColor,
- out,
- moveUpN,
- moveDownN,
- moveRightN,
- moveLeftN,
- moveCursor,
- eraseToENDL,
- saveCurPos,
- restoreCurPos
- };
- void setColor(int count, ...){
- printf("\033[0m");
- if(!count) return;
- va_list ap;
- va_start(ap, count);
- printf("\033[");
- for(int i=0; i<count; i++){
- if(i+1 == count) printf("%dm",va_arg(ap,int));
- else printf("%d;",va_arg(ap,int));
- }
- va_end(ap);
- }
- void setCursorPosition(int L, int C){
- printf("\033[%d;%dH",C,L);
- }
- void clear(void){
- printf("\033[2J");
- }
- void out(const char * sym){
- printf(sym);
- }
- void moveUpN(int N){
- printf("\033[%dA",N);
- }
- void moveDownN(int N){
- printf("\033[%dB",N);
- }
- void moveRightN(int N){
- printf("\033[%dC",N);
- }
- void moveLeftN(int N){
- printf("\033[%dD",N);
- }
- void moveCursor(int DIRECTION, int N){
- switch(DIRECTION){
- case UP: moveUpN(N); break;
- case DOWN: moveDownN(N); break;
- case LEFT: moveLeftN(N); break;
- case RIGHT: moveRightN(N); break;
- default: clear(); break;
- }
- }
- void eraseToENDL(void){
- printf("\033[K");
- }
- void saveCurPos(void){
- printf("\033[s");
- }
- void restoreCurPos(void){
- printf("\033[u");
- }
- #endif /* CONCOL_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement