Improved linebuffering to stdout

This commit is contained in:
Michiel Broek 2002-07-29 20:31:18 +00:00
parent bc61853ff3
commit 1ed82f8b40
2 changed files with 242 additions and 230 deletions

View File

@ -58,8 +58,9 @@ void Enter(int num)
{ {
int i; int i;
for(i = 0; i < num; i++) for (i = 0; i < num; i++)
printf("\n"); fprintf(stdout, "\n");
fflush(stdout);
} }
@ -68,7 +69,8 @@ void Enter(int num)
void pout(int fg, int bg, char *Str) void pout(int fg, int bg, char *Str)
{ {
colour(fg, bg); colour(fg, bg);
printf(Str); fprintf(stdout, Str);
fflush(stdout);
} }
@ -84,7 +86,8 @@ void poutCenter(int fg, int bg, char *Str)
void poutCR(int fg, int bg, char *Str) void poutCR(int fg, int bg, char *Str)
{ {
colour(fg, bg); colour(fg, bg);
puts(Str); fputs(Str, stdout);
fflush(stdout);
} }
@ -99,13 +102,14 @@ void colour(int fg, int bg)
int att=0, fore=37, back=40; int att=0, fore=37, back=40;
if (fg<0 || fg>31 || bg<0 || bg>7) { if (fg<0 || fg>31 || bg<0 || bg>7) {
printf("ANSI: Illegal colour specified: %i, %i\n", fg, bg); fprintf(stdout, "ANSI: Illegal colour specified: %i, %i\n", fg, bg);
fflush(stdout);
return; return;
} }
printf("["); fprintf(stdout, "[");
if ( fg > 15) { if ( fg > 15) {
printf("5;"); fprintf(stdout, "5;");
fg-=16; fg-=16;
} }
if (fg > 7) { if (fg > 7) {
@ -131,7 +135,8 @@ void colour(int fg, int bg)
else if (bg==7) back=47; else if (bg==7) back=47;
else back=40; else back=40;
printf("%d;%d;%dm", att, fore, back); fprintf(stdout, "%d;%d;%dm", att, fore, back);
fflush(stdout);
} }
} }
@ -147,17 +152,18 @@ void Center(char *string)
Str = calloc(81, sizeof(char)); Str = calloc(81, sizeof(char));
Strlen = strlen(string); Strlen = strlen(string);
if(Strlen == Maxlen) if (Strlen == Maxlen)
printf("%s\n", string); fprintf(stdout, "%s\n", string);
else { else {
x = Maxlen - Strlen; x = Maxlen - Strlen;
z = x / 2; z = x / 2;
for(i = 0; i < z; i++) for (i = 0; i < z; i++)
strcat(Str, " "); strcat(Str, " ");
strcat(Str, string); strcat(Str, string);
printf("%s\n", Str); fprintf(stdout, "%s\n", Str);
} }
fflush(stdout);
free(Str); free(Str);
} }
@ -167,8 +173,9 @@ void clear()
{ {
if (termmode == 1) { if (termmode == 1) {
colour(LIGHTGRAY, BLACK); colour(LIGHTGRAY, BLACK);
printf(ANSI_HOME); fprintf(stdout, ANSI_HOME);
printf(ANSI_CLEAR); fprintf(stdout, ANSI_CLEAR);
fflush(stdout);
} else } else
Enter(1); Enter(1);
} }
@ -183,17 +190,20 @@ void locate(int y, int x)
if (termmode > 0) { if (termmode > 0) {
if (exitinfo.iScreenLen != 0) { if (exitinfo.iScreenLen != 0) {
if (y > exitinfo.iScreenLen || x > 80) { if (y > exitinfo.iScreenLen || x > 80) {
printf("ANSI: Invalid screen coordinates: %i, %i\n", y, x); fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
printf("ANSI: exitinfo.iScreenLen: %i\n", exitinfo.iScreenLen); fprintf(stdout, "ANSI: exitinfo.iScreenLen: %i\n", exitinfo.iScreenLen);
fflush(stdout);
return; return;
} }
} else { } else {
if (y > 25 || x > 80) { if (y > 25 || x > 80) {
printf("ANSI: Invalid screen coordinates: %i, %i\n", y, x); fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
fflush(stdout);
return; return;
} }
} }
printf("\x1B[%i;%iH", y, x); fprintf(stdout, "\x1B[%i;%iH", y, x);
fflush(stdout);
} }
} }
@ -205,13 +215,14 @@ void fLine(int Len)
if (termmode == 0) if (termmode == 0)
for (x = 0; x < Len; x++) for (x = 0; x < Len; x++)
printf("-"); fprintf(stdout, "-");
if (termmode == 1) if (termmode == 1)
for (x = 0; x < Len; x++) for (x = 0; x < Len; x++)
printf("%c", 196); fprintf(stdout, "%c", 196);
printf(" \n"); fprintf(stdout, " \n");
fflush(stdout);
} }
@ -239,8 +250,9 @@ void mvprintw(int y, int x, const char *format, ...)
va_end(va_ptr); va_end(va_ptr);
locate(y, x); locate(y, x);
printf(outputstr); fprintf(stdout, outputstr);
free(outputstr); free(outputstr);
fflush(stdout);
} }

View File

@ -53,10 +53,10 @@ void clrtoeol()
{ {
int i; int i;
printf("\r"); fprintf(stdout, "\r");
for (i = 0; i < COLS; i++) for (i = 0; i < COLS; i++)
putchar(' '); fputc(' ', stdout);
printf("\r"); fprintf(stdout, "\r");
fflush(stdout); fflush(stdout);
} }
@ -68,7 +68,7 @@ void hor_lin(int y, int x, int len)
locate(y, x); locate(y, x);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
putchar('-'); fputc('-', stdout);
fflush(stdout); fflush(stdout);
} }
@ -167,7 +167,7 @@ void screen_start(char *name)
colour(LIGHTGRAY, BLACK); colour(LIGHTGRAY, BLACK);
clrtoeol(); clrtoeol();
if (i < LINES) if (i < LINES)
printf("\n"); fprintf(stdout, "\n");
} }
fflush(stdout); fflush(stdout);
@ -226,19 +226,19 @@ void working(int txno, int y, int x)
break; break;
case 2: mvprintw(4, 66, (char *)">>> ERROR <<<"); case 2: mvprintw(4, 66, (char *)">>> ERROR <<<");
for (i = 1; i <= 5; i++) { for (i = 1; i <= 5; i++) {
putchar(7); fputc(7, stdout);
fflush(stdout); fflush(stdout);
usleep(150000); usleep(150000);
} }
usleep(550000); usleep(550000);
break; break;
case 3: mvprintw(4, 66, (char *)"Form inserted"); case 3: mvprintw(4, 66, (char *)"Form inserted");
putchar(7); fputc(7, stdout);
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
break; break;
case 4: mvprintw(4, 66, (char *)"Form deleted "); case 4: mvprintw(4, 66, (char *)"Form deleted ");
putchar(7); fputc(7, stdout);
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
break; break;
@ -295,7 +295,7 @@ void showhelp(char *T)
set_color(WHITE, RED); set_color(WHITE, RED);
} }
} else { } else {
putchar(T[i]); fputc(T[i], stdout);
x++; x++;
} }
} }