--- lbbs/src/screen.c 2025/05/03 06:24:54 1.26 +++ lbbs/src/screen.c 2025/05/04 14:54:55 1.30 @@ -76,8 +76,6 @@ void clearscr() int press_any_key() { - igetch(1); - moveto(screen_rows, 0); clrtoeol(); @@ -106,20 +104,18 @@ void set_input_echo(int echo) static int _str_input(char *buffer, int buffer_length, int echo_mode) { - char buf[256], ch; - int c, offset = 0, len, loop = 1, i, hz = 0; + int c, offset = 0, i, hz = 0; for (i = 0; i < buffer_length && buffer[i] != '\0'; i++) { offset++; } - igetch(1); - - while (c = igetch_t(60)) + 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) @@ -229,15 +225,14 @@ int display_file(const char *filename) int display_file_ex(const char *filename, int begin_line, int wait) { char buffer[LINE_BUFFER_LEN]; - char temp[LINE_BUFFER_LEN]; int ch = 0; int input_ok, line, max_lines; long int c_line_current = 0, c_line_total = 0; FILE *fin; - struct stat f_stat; long *p_line_offsets; int len; int percentile; + int loop = 1; if ((fin = fopen(filename, "r")) == NULL) { @@ -253,15 +248,38 @@ 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 (line >= max_lines) + if (c_line_current >= c_line_total && c_line_total <= screen_rows - 2) { - percentile = (c_line_current - (line - 1) + (screen_rows - 2)) * 100 / c_line_total; + if (wait) + { + ch = press_any_key(); + } + else + { + iflush(); + } + + loop = 0; + break; + } + + if (c_line_current >= c_line_total || line >= max_lines) + { + 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 + { + percentile = 100; + } moveto(screen_rows, 0); - prints("\033[1;44;32m下面还有喔 (%d%%)\033[33m │ 结束 ← │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", - percentile); + prints("\033[1;44;32m%s (%d%%)%s\033[33m │ 结束 ← │ ↑/↓/PgUp/PgDn 移动 │ ? 辅助说明 │ \033[m", + (percentile < 100 ? "下面还有喔" : "没有更多了"), percentile, + (percentile < 10 ? " " : (percentile < 100 ? " " : ""))); iflush(); input_ok = 0; @@ -279,7 +297,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 +311,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,16 +350,13 @@ 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': case 'H': // Display help information - strcpy(temp, app_home_dir); - strcat(temp, "data/read_help.txt"); - display_file_ex(temp, begin_line, 1); + display_file_ex(DATA_READ_HELP, begin_line, 1); // Refresh after display help information c_line_current -= (line - 1); @@ -376,13 +392,6 @@ int display_file_ex(const char *filename line++; } - iflush(); - - if (wait) - { - ch = press_any_key(); - } - free(p_line_offsets); fclose(fin); @@ -408,7 +417,6 @@ int show_top(char *status) int show_bottom(char *msg) { char str_time[LINE_BUFFER_LEN]; - char str_time_onine[20]; char buffer[LINE_BUFFER_LEN]; time_t time_online; struct tm *tm_online; @@ -440,11 +448,9 @@ int show_active_board() int len; int end_of_line; - sprintf(filename, "%sdata/active_board.txt", app_home_dir); - clrline(3, 2 + ACTIVE_BOARD_HEIGHT); - if ((fin = fopen(filename, "r")) == NULL) + if ((fin = fopen(DATA_ACTIVE_BOARD, "r")) == NULL) { log_error("Unable to open file %s\n", filename); return -1;