2008年6月18日 星期三

opening page

讀書時貪得意寫的, 用類似原理, 現在用來做 console program waiting signal.


#include <stdio.h>
#include <termios.h>
#include <unistd.h>

#define COLOR "^[[%d;%dm"
#define POSITION "^[[%d;%df"
#define CLEAR "^[[2J"

struct termios save_termios;

main()
{
op();
printf(CLEAR);
}

tty_reset()
{
if (tcsetattr(STDIN_FILENO,TCSAFLUSH,&save_termios) < 0)
exit(-1);
return(0);
}

tty_cbreak(work,times)
int work;
int times;
{
int i;
char c;
struct termios buf;

if (tcgetattr(STDIN_FILENO,&save_termios)<0)
exit(0);
buf=save_termios;
buf.c_lflag &= ~(ECHO | ICANON);
buf.c_cc[VMIN] = work;
buf.c_cc[VTIME] = times;
if (tcsetattr(STDIN_FILENO,TCSAFLUSH,&buf) < 0)
exit(-1);
return(0);
}

op()
{
int work,times;
int x,y,z;
int cr=30;
int ef=1;
char c=0;

printf(CLEAR);

printf(POSITION,22,5);
printf("^[[5;37mPress any Key to continue!");

work=0;times=1;
tty_cbreak(work,times);

while (c==0)
{
read(STDIN_FILENO,&c,1);
y=1;
for (x=6;x<15;x++)
{
printf(POSITION,x,y++);
if (ef==0)ef=1;else ef=0;
if (cr==38)cr=31;
printf(COLOR,ef,cr++);
printf("VVV");
}
for (x=15;x>5;x--)
{
printf(POSITION,x,y++);
if (ef==0)ef=1;else ef=0;
if (cr==38)cr=31;
printf(COLOR,ef,cr++);
printf("VVV");
}

for (x=0;x<10000;x++)
for (y=0;y<50;y++)
;
}
tty_reset();
}

沒有留言: