- #include <stdio.h>
- #include <termios.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <time.h>
-
- typedef enum
- {
- BLACK,
- RED,
- GREEN,
- YELLOW,
- BLUE,
- MAGENTA,
- CYAN,
- WHITE
- } COLORS;
-
- void mode_raw(int activer) {
- static struct termios cooked;
- static int raw_actif = 0;
- if (raw_actif == activer) {return;}
- if (activer) {
- struct termios raw;
- tcgetattr(STDIN_FILENO, &cooked);
- raw = cooked;
- cfmakeraw(&raw);
- tcsetattr(STDIN_FILENO, TCSANOW, &raw);
- }
- else {tcsetattr(STDIN_FILENO, TCSANOW, &cooked);}
- raw_actif = activer;
- }
-
- void ClrScr(void) {printf("\e[2J");}
-
- void GotoXY(int y, int x) {printf("\e[%d;%dH", x, y);}
-
- void Delay(int pause) {usleep(pause*1000);}
-
- void Blink(int activer) {(activer)? printf("\e[5m") : printf("\e[0m");}
-
- void Blod(int activer) {(activer)? printf("\e[1m") : printf("\e[0m");}
-
- void Underline(int activer) {(activer)? printf("\e[4m") : printf("\e[0m");}
-
- void TextColor(int fg)
- {
- int x=fg;
- if((fg < 0) || (fg > 7)) x = 0;
- printf("\e[3%dm", x);
- }
-
- void TextBackground(int bg)
- {
- int x=bg;
- if((bg < 0) || (bg > 7)) x = 0;
- printf("\e[4%dm", x);
- }
-
- char ReadKey(void)
- {
- char c;
- mode_raw(1);
- c = getchar();
- mode_raw(0);
- return c;
- }
-
- int KeyPressed(void)
- {
- struct timeval tv = { 0, 0 };
- fd_set readfds;
-
- FD_ZERO(&readfds);
- FD_SET(STDIN_FILENO, &readfds);
-
- return select(STDIN_FILENO + 1, &readfds, NULL, NULL, &tv) == 1;
- }
-
- void GetPass(char * prompt, char * pass)
- {
- int cpt=0;
- printf("%s", prompt);
- while((pass[cpt]=ReadKey())!=13 && cpt!=100)
- {
- putchar('*');
- cpt++;
- }
- printf("\n");
- pass[cpt]=0;
- }
-
- void line(int x, char c1, char c2)
- {
- int cpt;
- putchar(c1);
- for(cpt=1; cpt<=(x-2); cpt++) putchar(c2);
- putchar(c1);
- putchar('\n');
- }
-
- void box(int x, int y, char c1, char c2, char c3, char c4)
- {
- int cpt;
- line(x, c1, c2);
- for(cpt=1; cpt<=(y-2); cpt++) line(x, c3, c4);
- line(x, c1, c2);
- }
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
typedef enum
{
BLACK,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE
} COLORS;
void mode_raw(int activer) {
static struct termios cooked;
static int raw_actif = 0;
if (raw_actif == activer) {return;}
if (activer) {
struct termios raw;
tcgetattr(STDIN_FILENO, &cooked);
raw = cooked;
cfmakeraw(&raw);
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
}
else {tcsetattr(STDIN_FILENO, TCSANOW, &cooked);}
raw_actif = activer;
}
void ClrScr(void) {printf("\e[2J");}
void GotoXY(int y, int x) {printf("\e[%d;%dH", x, y);}
void Delay(int pause) {usleep(pause*1000);}
void Blink(int activer) {(activer)? printf("\e[5m") : printf("\e[0m");}
void Blod(int activer) {(activer)? printf("\e[1m") : printf("\e[0m");}
void Underline(int activer) {(activer)? printf("\e[4m") : printf("\e[0m");}
void TextColor(int fg)
{
int x=fg;
if((fg < 0) || (fg > 7)) x = 0;
printf("\e[3%dm", x);
}
void TextBackground(int bg)
{
int x=bg;
if((bg < 0) || (bg > 7)) x = 0;
printf("\e[4%dm", x);
}
char ReadKey(void)
{
char c;
mode_raw(1);
c = getchar();
mode_raw(0);
return c;
}
int KeyPressed(void)
{
struct timeval tv = { 0, 0 };
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(STDIN_FILENO, &readfds);
return select(STDIN_FILENO + 1, &readfds, NULL, NULL, &tv) == 1;
}
void GetPass(char * prompt, char * pass)
{
int cpt=0;
printf("%s", prompt);
while((pass[cpt]=ReadKey())!=13 && cpt!=100)
{
putchar('*');
cpt++;
}
printf("\n");
pass[cpt]=0;
}
void line(int x, char c1, char c2)
{
int cpt;
putchar(c1);
for(cpt=1; cpt<=(x-2); cpt++) putchar(c2);
putchar(c1);
putchar('\n');
}
void box(int x, int y, char c1, char c2, char c3, char c4)
{
int cpt;
line(x, c1, c2);
for(cpt=1; cpt<=(y-2); cpt++) line(x, c3, c4);
line(x, c1, c2);
}