--- lbbs/src/screen.c 2004/10/22 19:51:01 1.4 +++ lbbs/src/screen.c 2004/10/23 08:22:25 1.5 @@ -17,6 +17,8 @@ #include "io.h" +int screen_lines = 24; + void moveto (int row, int col) { @@ -39,6 +41,20 @@ clrtoeol () } void +clrline (int line_begin, int line_end) +{ + int i; + + for (i = line_begin; i <= line_end; i++) + { + moveto (i, 0); + prints ("\033[K"); + } + + iflush(); +} + +void clearscr() { prints ("\33[2J"); @@ -106,16 +122,32 @@ str_input (char *buffer, int buffer_leng } int -display_file(const char* filename) +display_file(const char* filename, int clear, int begin_line) { char buffer[260]; FILE *fin; - int i; + int i, line; + + if (clear) + { + clrline(begin_line, screen_lines - 1); + line = begin_line; + moveto (line, 0); + } if ((fin = fopen(filename, "r")) != NULL) { while (fgets(buffer, 255, fin)) { + if (line == screen_lines - 1) + { + moveto (screen_lines - 1, 0); + press_any_key(); + clrline(begin_line, screen_lines - 1); + line = begin_line; + moveto (line, 0); + } + i = strlen(buffer); if (buffer[i-1] == '\n' && buffer[i-2] != '\r') { @@ -125,6 +157,8 @@ display_file(const char* filename) } prints (buffer); iflush (); + + line ++; } fclose (fin); @@ -149,7 +183,7 @@ show_bottom() int press_any_key() { - prints (" \033[1;33m按任意键盘继续...\033[0;37m"); + prints (" \033[1;33m按任意键盘继续...\033[0;37m"); iflush(); return igetch ();