--- lbbs/src/editor.c 2025/10/18 12:06:10 1.48 +++ lbbs/src/editor.c 2025/11/05 04:19:21 1.54 @@ -1,18 +1,10 @@ -/*************************************************************************** - editor.h - description - ------------------- - copyright : (C) 2004-2025 by Leaflet - email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * editor + * - user interactive full-screen text editor + * + * Copyright (C) 2004-2025 Leaflet + */ #include "bbs.h" #include "common.h" @@ -26,9 +18,13 @@ #include #include -#define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m" -#define EDITOR_MEM_POOL_LINE_PER_CHUNK 1000 -#define EDITOR_MEM_POOL_CHUNK_LIMIT (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1) +enum _editor_constant_t +{ + EDITOR_MEM_POOL_LINE_PER_CHUNK = 1000, + EDITOR_MEM_POOL_CHUNK_LIMIT = (MAX_EDITOR_DATA_LINES / EDITOR_MEM_POOL_LINE_PER_CHUNK + 1), +}; + +static const char EDITOR_ESC_DISPLAY_STR[] = "\033[32m*\033[m"; static MEMORY_POOL *p_mp_data_line; static MEMORY_POOL *p_mp_editor_data; @@ -445,7 +441,7 @@ int editor_data_insert(EDITOR_DATA *p_ed } int editor_data_delete(EDITOR_DATA *p_editor_data, long *p_display_line, long *p_offset, - long *p_last_updated_line) + long *p_last_updated_line, int del_line) { long display_line = *p_display_line; long offset = *p_offset; @@ -500,7 +496,11 @@ int editor_data_delete(EDITOR_DATA *p_ed } // Check str to be deleted - if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127) + if (del_line) + { + str_len = (int)(p_editor_data->display_line_lengths[display_line] - offset); + } + else if (p_data_line[offset_data_line] > 0 && p_data_line[offset_data_line] < 127) { str_len = 1; } @@ -523,7 +523,8 @@ int editor_data_delete(EDITOR_DATA *p_ed // Current display line is (almost) empty if (offset_data_line + str_len > len_data_line || - (offset_data_line + str_len == len_data_line && p_data_line[offset_data_line] == '\n')) + (offset_data_line + str_len == len_data_line && + p_data_line[del_line ? len_data_line - 1 : offset_data_line] == '\n')) { if (display_line + 1 >= p_editor_data->display_line_total) // No additional display line (data line) { @@ -663,6 +664,7 @@ int editor_display(EDITOR_DATA *p_editor int key_insert = 1; int i, j; char *p_str; + int del_line; clrline(output_current_row, SCREEN_ROWS); @@ -702,7 +704,7 @@ int editor_display(EDITOR_DATA *p_editor iflush(); str_len = 0; - ch = igetch_t(MAX_DELAY_TIME); + ch = igetch_t(BBS_max_user_idle_time); while (!SYS_server_exit) { if (ch != KEY_NULL && ch != KEY_TIMEOUT) @@ -769,7 +771,7 @@ int editor_display(EDITOR_DATA *p_editor if (!key_insert) // overwrite { if (editor_data_delete(p_editor_data, &display_line_out, &offset_out, - &last_updated_line) < 0) + &last_updated_line, 0) < 0) { log_error("editor_data_delete() error\n"); } @@ -838,7 +840,7 @@ int editor_display(EDITOR_DATA *p_editor str_len = 0; continue; } - else if (ch == KEY_DEL || ch == BACKSPACE) // Del + else if (ch == KEY_DEL || ch == BACKSPACE || ch == Ctrl('K') || ch == Ctrl('Y')) // Del { // Refresh current action while user input if (user_online_update(NULL) < 0) @@ -846,6 +848,8 @@ int editor_display(EDITOR_DATA *p_editor log_error("user_online_update(NULL) error\n"); } + del_line = 0; + if (ch == BACKSPACE) { if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden @@ -870,6 +874,15 @@ int editor_display(EDITOR_DATA *p_editor col_pos = MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos]); } } + else if (ch == Ctrl('K')) + { + del_line = 1; + } + else if (ch == Ctrl('Y')) + { + col_pos = 1; + del_line = 1; + } display_line_in = line_current - output_current_row + row_pos; offset_in = split_line(p_editor_data->p_display_lines[display_line_in], (int)col_pos - 1, &eol, &display_len, 0); @@ -877,9 +890,9 @@ int editor_display(EDITOR_DATA *p_editor offset_out = offset_in; if ((str_len = editor_data_delete(p_editor_data, &display_line_out, &offset_out, - &last_updated_line)) < 0) + &last_updated_line, del_line)) < 0) { - log_error("editor_data_delete() error\n"); + log_error("editor_data_delete() error: %d\n", str_len); } else { @@ -1043,8 +1056,6 @@ int editor_display(EDITOR_DATA *p_editor output_end_row = SCREEN_ROWS - 1; // Legacy Fterm only works with this line col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos])); break; - case KEY_SPACE: - break; case KEY_RIGHT: offset_in = split_line(p_editor_data->p_display_lines[line_current - output_current_row + row_pos], (int)col_pos - 1, &eol, &display_len, 0); @@ -1116,13 +1127,13 @@ int editor_display(EDITOR_DATA *p_editor break; case Ctrl('Q'): case KEY_F1: - if (!show_help) // Not reentrant + if (!show_help) // Not re-entrant { break; } // Display help information show_help = 0; - display_file(DATA_READ_HELP, 1); + display_file(DATA_EDITOR_HELP, 1); show_help = 1; case KEY_F5: // Refresh after display help information @@ -1149,7 +1160,7 @@ int editor_display(EDITOR_DATA *p_editor break; } - ch = igetch_t(MAX_DELAY_TIME); + ch = igetch_t(BBS_max_user_idle_time); } continue;