1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/****************************************************
// conio.c
Libconio 1.0 (C) 2004 FSL A.C.
Basado en la implementacion de conio.h escrita
por Salvador Fernandez Barquin y adaptado a lib
por Maximo Pech Jaramillo <makz@linuxmail.org>
Se permite su uso, copia, distribucion y modificacion
bajo los tιrminos de la GNU GPL versiσn 2.0 publicada
por la Free Software Foundation.
*****************************************************/
#include "conio.h"
struct textinfo text={0, 0};
int getche()
{
struct termios t;
int c;
tcgetattr(0,&t);
t.c_lflag&=~ICANON;
tcsetattr(0,TCSANOW,&t);
fflush(stdout);
c=getchar();
t.c_lflag|=ICANON;
tcsetattr(0,TCSANOW,&t);
return c;
}
int getch()
{
struct termios t;
int c;
tcgetattr(0,&t);
t.c_lflag&=~ECHO+~ICANON;
tcsetattr(0,TCSANOW,&t);
fflush(stdout);
c=getchar();
t.c_lflag|=ICANON+ECHO;
tcsetattr(0,TCSANOW,&t);
return c;
}
void gotoxy(int x, int y)
{
printf("%c[%d;%dH", ESC, y, x);
text.curx = x;
text.cury = y;
}
void clreol()
{
printf("%c[K", ESC);
}
void clrscr()
{
printf("%c[2J", ESC);
gotoxy(0, 0);
}
void textcolor(int color)
{
if(color >= BLACK && color <= LIGHTGRAY ) /* dark color */
printf ("%c[0;%dm", ESC, 30+color);
else
printf("%c[1;%dm", ESC, 30+(color-8));
}
void textbackground(int color)
{
printf ("%c[%dm", ESC, 40+color);
}
int wherex(void)
{
return text.curx;
}
int wherey(void)
{
return text.cury;
}
| |