--- lbbs/src/screen.c 2004/10/22 18:47:51 1.2 +++ 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,17 +122,43 @@ 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[256]; + char buffer[260]; FILE *fin; + 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') + { + buffer[i-1] = '\r'; + buffer[i] = '\n'; + buffer[i+1] = '\0'; + } prints (buffer); iflush (); + + line ++; } fclose (fin); @@ -141,7 +183,7 @@ show_bottom() int press_any_key() { - prints (" \033[1;33m按任意键盘继续...\033[0;37m \r\n"); + prints (" \033[1;33m按任意键盘继续...\033[0;37m"); iflush(); return igetch ();