--- lbbs/src/editor.c 2025/06/11 10:44:33 1.9 +++ lbbs/src/editor.c 2025/06/11 12:56:52 1.12 @@ -27,6 +27,8 @@ #define _POSIX_C_SOURCE 200809L #include +#define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m" + EDITOR_DATA *editor_data_load(const char *p_data) { EDITOR_DATA *p_editor_data; @@ -169,7 +171,7 @@ int editor_data_insert(EDITOR_DATA *p_ed // Get accurate offset of first character of CJK at offset position for (i = 0; i < offset; i++) { - if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK + if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK { i++; } @@ -368,7 +370,7 @@ int editor_data_delete(EDITOR_DATA *p_ed // Get accurate offset of first character of CJK at offset position for (i = 0; i < offset; i++) { - if (p_editor_data->p_display_lines[display_line][i] < 0) // GBK + if (p_editor_data->p_display_lines[display_line][i] < 0 || p_editor_data->p_display_lines[display_line][i] > 127) // GBK { i++; } @@ -417,8 +419,10 @@ int editor_data_delete(EDITOR_DATA *p_ed } else { - log_error("Some strange character at display_line %ld, offset %ld\n", display_line, offset); - return -2; + log_error("Some strange character at display_line %ld, offset %ld: %d %d %d %d\n", + display_line, offset, p_data_line[offset_data_line], p_data_line[offset_data_line + 1], + p_data_line[offset_data_line + 2], p_data_line[offset_data_line + 3]); + str_len = 1; } // Current display line is (almost) empty @@ -544,7 +548,8 @@ int editor_display(EDITOR_DATA *p_editor int scroll_rows; long last_updated_line = 0; int key_insert = 1; - int i; + int i, j; + char *p_str; screen_current_row = screen_begin_row; clrline(screen_begin_row, SCREEN_ROWS); @@ -586,11 +591,9 @@ int editor_display(EDITOR_DATA *p_editor iflush(); input_ok = 0; + ch = igetch_t(MAX_DELAY_TIME); while (!SYS_server_exit && !input_ok) { - ch = igetch_t(MAX_DELAY_TIME); - input_ok = 1; - // extended key handler if (editor_display_key_handler(&ch, &ctx) != 0) { @@ -607,7 +610,8 @@ int editor_display(EDITOR_DATA *p_editor str_len = 0; } - if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || ch == CR) // printable character or GBK + if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || // Printable character or GBK + ch == CR || ch == KEY_ESC) // Special character { if (str_len == 0) { @@ -668,9 +672,15 @@ int editor_display(EDITOR_DATA *p_editor row_pos += (display_line_out - display_line_in); } col_pos = offset_out + 1; + } - continue; + // Check whether there is additional input + ch = igetch(0); + if (ch == KEY_TIMEOUT) + { + input_ok = 1; } + continue; } else if (ch == KEY_DEL || ch == BACKSPACE) // Del { @@ -716,9 +726,16 @@ int editor_display(EDITOR_DATA *p_editor } } + // Check whether there is additional input + ch = igetch(0); + if (ch == KEY_TIMEOUT) + { + input_ok = 1; + } continue; } + input_ok = 1; switch (ch) { case KEY_NULL: @@ -855,8 +872,6 @@ int editor_display(EDITOR_DATA *p_editor col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_lengths[line_current - screen_current_row + row_pos])); clrline(screen_begin_row, SCREEN_ROWS); break; - case KEY_ESC: - break; case KEY_F1: if (!show_help) // Not reentrant { @@ -881,6 +896,10 @@ int editor_display(EDITOR_DATA *p_editor } BBS_last_access_tm = time(0); + if (!input_ok) + { + ch = igetch_t(MAX_DELAY_TIME); + } } continue; @@ -898,8 +917,23 @@ int editor_display(EDITOR_DATA *p_editor len = 0; } - memcpy(buffer, (const char *)p_editor_data->p_display_lines[line_current], (size_t)len); - buffer[len] = '\0'; + // memcpy(buffer, p_editor_data->p_display_lines[line_current], (size_t)len); + // Replace '\033' with '*' + p_str = p_editor_data->p_display_lines[line_current]; + for (i = 0, j = 0; i < len; i++) + { + if (p_str[i] == '\033') + { + memcpy(buffer + j, EDITOR_ESC_DISPLAY_STR, sizeof(EDITOR_ESC_DISPLAY_STR) - 1); + j += (int)(sizeof(EDITOR_ESC_DISPLAY_STR) - 1); + } + else + { + buffer[j] = p_str[i]; + j++; + } + } + buffer[j] = '\0'; moveto(screen_current_row, 0); clrtoeol();