--- lbbs/src/screen.c 2025/10/17 01:25:08 1.111 +++ lbbs/src/screen.c 2025/10/19 03:17:03 1.116 @@ -102,15 +102,32 @@ void clearscr() moveto(0, 0); } -int press_any_key() +inline int press_any_key() { + return press_any_key_ex(" \033[1;33m按任意键继续...\033[m", 60); +} + +int press_any_key_ex(const char *msg, int sec) +{ + int ch = 0; + int duration = 0; + time_t t_begin = time(NULL); + moveto(SCREEN_ROWS, 0); clrtoeol(); - prints(" \033[1;33m按任意键继续...\033[0;37m"); + prints(msg); iflush(); - return igetch_t(MIN(MAX_DELAY_TIME, 60)); + igetch_reset(); + + do + { + ch = igetch_t(sec - duration); + duration = (int)(time(NULL) - t_begin); + } while (!SYS_server_exit && ch == 0 && duration < 60); + + return ch; } void set_input_echo(int echo) @@ -165,7 +182,7 @@ static int _str_input(char *buffer, int offset--; if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 { - while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) + while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) { offset--; } @@ -186,14 +203,14 @@ static int _str_input(char *buffer, int else if ((ch & 0xff80) == 0x80) // head of multi-byte character { str_len = 0; - c = (char)(ch & 0b11110000); - while (c & 0b10000000) + c = (char)(ch & 0xf0); + while (c & 0x80) { input_str[str_len] = (char)(ch - 256); str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; - if ((c & 0b10000000) == 0) // Input completed + if ((c & 0x80) == 0) // Input completed { break; } @@ -283,7 +300,7 @@ int str_input(char *buffer, int buf_size iflush(); return len; -}; +} int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int max_display_len) { @@ -336,7 +353,7 @@ int get_data(int row, int col, char *pro offset--; if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 { - while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) + while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) { str_len++; offset--; @@ -366,11 +383,11 @@ int get_data(int row, int col, char *pro if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character { str_len = 0; - c = (char)(buffer[offset] & 0b11110000); - while (c & 0b10000000) + c = (char)(buffer[offset] & 0xf0); + while (c & 0x80) { str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } display_len--; } @@ -400,7 +417,7 @@ int get_data(int row, int col, char *pro offset--; if (buffer[offset] < 0 || buffer[offset] > 127) // UTF8 { - while (offset > 0 && (buffer[offset] & 0b11000000) != 0b11000000) + while (offset > 0 && (buffer[offset] & 0xc0) != 0xc0) { str_len++; offset--; @@ -421,11 +438,11 @@ int get_data(int row, int col, char *pro str_len = 0; if ((buffer[offset] & 0x80) == 0x80) // head of multi-byte character { - c = (char)(buffer[offset] & 0b11110000); - while (c & 0b10000000) + c = (char)(buffer[offset] & 0xf0); + while (c & 0x80) { str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } col_cur++; } @@ -473,14 +490,14 @@ int get_data(int row, int col, char *pro else if ((ch & 0xff80) == 0x80) // head of multi-byte character { str_len = 0; - c = (char)(ch & 0b11110000); - while (c & 0b10000000) + c = (char)(ch & 0xf0); + while (c & 0x80) { input_str[str_len] = (char)(ch - 256); str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; - if ((c & 0b10000000) == 0) // Input completed + if ((c & 0x80) == 0) // Input completed { break; } @@ -699,7 +716,6 @@ int display_data(const void *p_data, lon output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line break; case CR: - case KEY_SPACE: case KEY_DOWN: if (line_current + (screen_row_total - (output_current_row - screen_begin_row)) >= display_line_total) // Reach end { @@ -727,6 +743,7 @@ int display_data(const void *p_data, lon output_end_row = SCREEN_ROWS - 1; clrline(output_current_row, SCREEN_ROWS); break; + case KEY_SPACE: case KEY_PGDN: if (line_current + screen_row_total - (output_current_row - screen_begin_row) >= display_line_total) // Reach end {