--- lbbs/src/screen.c 2025/05/03 06:24:54 1.26 +++ lbbs/src/screen.c 2025/05/03 13:41:21 1.28 @@ -76,8 +76,6 @@ void clearscr() int press_any_key() { - igetch(1); - moveto(screen_rows, 0); clrtoeol(); @@ -114,12 +112,11 @@ static int _str_input(char *buffer, int offset++; } - igetch(1); - while (c = igetch_t(60)) { if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) { + igetch(1); // Cleanup remaining '\n' in the buffer break; } if (c == LF) @@ -238,6 +235,7 @@ int display_file_ex(const char *filename long *p_line_offsets; int len; int percentile; + int loop = 1; if ((fin = fopen(filename, "r")) == NULL) { @@ -253,11 +251,34 @@ int display_file_ex(const char *filename line = begin_line; max_lines = screen_rows - 1; - while (c_line_current < c_line_total) + while (loop) { + if (c_line_current >= c_line_total) + { + if (wait) + { + ch = press_any_key(); + } + else + { + iflush(); + } + + loop = 0; + break; + } + if (line >= max_lines) { - percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; + if (c_line_current - (line - 1) + (screen_rows - 2) < c_line_total) + { + percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; + } + else + { + log_error("P100 reached\n"); + percentile = 100; + } moveto(screen_rows, 0); prints("\033[1;44;32m下面还有喔 (%d%%)\033[33m │ 结束 ← │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", @@ -279,7 +300,8 @@ int display_file_ex(const char *filename c_line_current -= line; line = begin_line; max_lines = begin_line + 1; - prints("\033[1T"); // Scroll down 1 line + prints("\033[T"); // Scroll down 1 line + //max_lines = screen_rows - 1; // Legacy Fterm only works with this line break; case KEY_DOWN: case CR: @@ -292,7 +314,7 @@ int display_file_ex(const char *filename max_lines = screen_rows - 1; moveto(screen_rows, 0); clrtoeol(); - prints("\033[1S"); // Scroll up 1 line + prints("\033[S"); // Scroll up 1 line break; case KEY_PGUP: case Ctrl('B'): @@ -331,8 +353,7 @@ int display_file_ex(const char *filename case KEY_LEFT: case 'q': case 'Q': - c_line_current = c_line_total; - wait = 0; + loop = 0; break; case '?': case 'h': @@ -376,13 +397,6 @@ int display_file_ex(const char *filename line++; } - iflush(); - - if (wait) - { - ch = press_any_key(); - } - free(p_line_offsets); fclose(fin);