--- lbbs/src/screen.c 2025/05/10 13:17:36 1.42 +++ lbbs/src/screen.c 2025/05/15 05:14:57 1.49 @@ -98,7 +98,7 @@ void set_input_echo(int echo) prints("\xff\xfb\x01\xff\xfb\x03"); iflush(); igetch(0); - igetch(1); + igetch_reset(); } } @@ -112,22 +112,26 @@ static int _str_input(char *buffer, int for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++) ; - while ((c = igetch_t(MIN(MAX_DELAY_TIME, 60)))) + igetch_reset(); + + while (!SYS_server_exit) { + c = igetch_t(MIN(MAX_DELAY_TIME, 60)); + if (c == CR) { - igetch(1); // Cleanup remaining '\n' in the buffer + igetch_reset(); break; } - if (c == KEY_TIMEOUT) + else if (c == KEY_TIMEOUT || c == KEY_NULL) // timeout or broken pipe { return -1; } - if (c == KEY_NULL || c == LF) + else if (c == LF || c == '\0') { continue; } - if (c == BACKSPACE) + else if (c == BACKSPACE) { if (offset > 0) { @@ -148,29 +152,32 @@ static int _str_input(char *buffer, int } continue; } - if (c > 255 || iscntrl(c)) + else if (c > 255 || iscntrl(c)) { continue; } - if (c > 127 && c <= 255) + else if (c > 127 && c <= 255) { if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character { - igetch(1); // Cleanup remaining input + igetch(0); // Ignore 1 character outc('\a'); iflush(); continue; } hz = (!hz); } + if (offset + 1 > buf_size - 1) { outc('\a'); iflush(); continue; } + buffer[offset++] = (char)c; buffer[offset] = '\0'; + switch (echo_mode) { case DOECHO: @@ -207,8 +214,6 @@ int get_data(int row, int col, char *pro { int len; - igetch(1); // Cleanup input buffer - moveto(row, col); prints(prompt); prints(buffer); @@ -275,7 +280,7 @@ int display_file_ex(const char *filename line = begin_line; max_lines = screen_rows - 1; - while (loop) + while (!SYS_server_exit && loop) { if (c_line_current >= c_line_total && c_line_total <= screen_rows - 2) { @@ -310,7 +315,7 @@ int display_file_ex(const char *filename iflush(); input_ok = 0; - while (!input_ok) + while (!SYS_server_exit && !input_ok) { ch = igetch_t(MAX_DELAY_TIME); input_ok = 1; @@ -330,8 +335,9 @@ int display_file_ex(const char *filename // 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: + igetch_reset(); + case KEY_DOWN: if (c_line_current + ((screen_rows - 2) - (line - 1)) >= c_line_total) // Reach bottom { break;