--- lbbs/src/screen.c 2005/03/20 17:23:17 1.10 +++ lbbs/src/screen.c 2005/03/22 08:19:11 1.13 @@ -78,27 +78,25 @@ press_any_key () prints (" \033[1;33m按任意键继续...\033[0;37m"); iflush (); - return igetch (); + return igetch_t (60); } void -set_input_echo(int echo) +set_input_echo (int echo) { - char temp[256]; - if (echo) - { - outc ('\x83'); // ASCII code 131 - iflush (); - } + { + outc ('\x83'); // ASCII code 131 + iflush (); + } else - { + { // outc ('\x85'); // ASCII code 133 - prints ("\xff\xfb\x01\xff\xfb\x03"); - iflush (); - igetch (); - igetch (); - } + prints ("\xff\xfb\x01\xff\xfb\x03"); + iflush (); + igetch_t (60); + igetch_t (60); + } } int @@ -109,12 +107,12 @@ str_input (char *buffer, int buffer_leng memset (buffer, '\0', buffer_length); - while (c = igetch ()) + while (c = igetch_t (60)) { - if (c == CR) - break; + if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) + break; if (c == LF) - continue; + continue; if (c == BACKSPACE) { if (offset > 0) @@ -170,15 +168,15 @@ display_file (const char *filename) int i; if ((fin = fopen (filename, "r")) == NULL) - { - return -1; - } + { + return -1; + } while (fgets (buffer, 255, fin)) { i = strlen (buffer); if (buffer[i - 1] == '\n' && buffer[i - 2] != '\r') - { + { buffer[i - 1] = '\r'; buffer[i] = '\n'; buffer[i + 1] = '\0'; @@ -186,7 +184,7 @@ display_file (const char *filename) prints (buffer); iflush (); } - fclose(fin); + fclose (fin); return 0; } @@ -196,7 +194,7 @@ display_file_ex (const char *filename, i { char buffer[260], temp[256]; int i, ch, input_ok; - long int line, c_line_begin = 0, c_line_total=0; + long int line, c_line_begin = 0, c_line_total = 0; long int f_line, f_size, f_offset; FILE *fin; struct stat f_stat; @@ -215,7 +213,7 @@ display_file_ex (const char *filename, i f_size = f_stat.st_size; while (fgets (buffer, 255, fin)) - c_line_total ++; + c_line_total++; rewind (fin); while (fgets (buffer, 255, fin)) @@ -227,13 +225,13 @@ display_file_ex (const char *filename, i moveto (screen_lines, 0); prints ("\033[1;44;32m下面还有喔 (%d%%)\033[33m │ 结束 ← │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", - (f_offset-strlen(buffer)) * 100 / f_size); + (f_offset - strlen (buffer)) * 100 / f_size); iflush (); input_ok = 0; while (!input_ok) { - ch = igetch (); + ch = igetch_t (MAX_DELAY_TIME); input_ok = 1; switch (ch) { @@ -279,12 +277,14 @@ display_file_ex (const char *filename, i } break; case KEY_RIGHT: - case KEY_PGDOWN: + case KEY_PGDN: case Ctrl ('F'): case KEY_SPACE: c_line_begin += (screen_lines - begin_line - 1); - if (c_line_begin + (screen_lines - begin_line) > c_line_total) - c_line_begin = c_line_total - (screen_lines - begin_line); + if (c_line_begin + (screen_lines - begin_line) > + c_line_total) + c_line_begin = + c_line_total - (screen_lines - begin_line); rewind (fin); for (f_line = 0; f_line < c_line_begin; f_line++) { @@ -292,6 +292,8 @@ display_file_ex (const char *filename, i goto exit; } break; + case KEY_NULL: + case KEY_TIMEOUT: case KEY_LEFT: case 'q': case 'Q': @@ -339,9 +341,9 @@ display_file_ex (const char *filename, i line++; } if (wait) - ch = press_any_key(); + ch = press_any_key (); else - ch = 0; + ch = 0; exit: fclose (fin);