[PATCH v6 0/1] MR8467: conhost: Implement F1 and F3 support for history retrieval.
F1 and F3 allow partial retrieval of previous entry from console history. They are used as shortcuts such that if the following were entered at the command line: ``` md tmptmp cd <F3> ``` F3 will retrieve the previous line from history past the cursor position, and be auto-completed to "cd tmptmp". F1 works in a similar fashion, but with one character at a time. -- v6: conhost: Implement F1 and F3 support for history retrieval. https://gitlab.winehq.org/wine/wine/-/merge_requests/8467
From: Joe Souza <jsouza(a)yahoo.com> --- programs/conhost/conhost.c | 61 ++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 89c030e86c8..dfb65958c93 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -774,6 +774,47 @@ static void edit_line_find_in_history( struct console *console ) while (ctx->history_index != start_pos); } +static void edit_line_copy_from_history( struct console *console, int copycount ) +{ + if (console->edit_line.history_index) + { + struct edit_line *ctx = &console->edit_line; + unsigned int index = ctx->history_index - 1; + WCHAR *line = console->history[index]->text; + unsigned int len = console->history[index]->len / sizeof(WCHAR); + + if (len > ctx->cursor) + { + unsigned int ccount = (copycount > 0) ? copycount : len - ctx->cursor; + + if (ctx->cursor == lstrlenW(ctx->buf)) + { + /* Clean the screen. */ + edit_line_delete(console, ctx->cursor, ctx->len); + /* Insert new string. */ + if (edit_line_grow(console, ccount)) + { + edit_line_insert( console, &line[ctx->cursor], ccount ); + } + } + else + { + ctx->cursor += ccount; + } + } + } +} + +static void edit_line_copy_one_from_history( struct console *console ) +{ + edit_line_copy_from_history(console, 1); +} + +static void edit_line_copy_all_from_history( struct console *console ) +{ + edit_line_copy_from_history(console, -1); +} + static void edit_line_move_left( struct console *console ) { if (console->edit_line.cursor > 0) console->edit_line.cursor--; @@ -1137,15 +1178,17 @@ static const struct edit_line_key_map emacs_key_map[] = static const struct edit_line_key_entry win32_std_key_map[] = { - { VK_LEFT, edit_line_move_left }, - { VK_RIGHT, edit_line_move_right }, - { VK_HOME, edit_line_move_home }, - { VK_END, edit_line_move_end }, - { VK_UP, edit_line_move_to_prev_hist }, - { VK_DOWN, edit_line_move_to_next_hist }, - { VK_INSERT, edit_line_toggle_insert }, - { VK_F8, edit_line_find_in_history }, - { VK_ESCAPE, edit_line_clear }, + { VK_LEFT, edit_line_move_left }, + { VK_RIGHT, edit_line_move_right }, + { VK_HOME, edit_line_move_home }, + { VK_END, edit_line_move_end }, + { VK_UP, edit_line_move_to_prev_hist }, + { VK_DOWN, edit_line_move_to_next_hist }, + { VK_INSERT, edit_line_toggle_insert }, + { VK_F8, edit_line_find_in_history }, + { VK_ESCAPE, edit_line_clear }, + { VK_F1, edit_line_copy_one_from_history }, + { VK_F3, edit_line_copy_all_from_history }, { 0 } }; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/8467
On Sun Jul 6 04:56:23 2025 +0000, Joe Souza wrote:
changed this line in [version 6 of the diff](/wine/wine/-/merge_requests/8467/diffs?diff_id=191118&start_sha=ccbb22bafaf729c3efbd2d469f883c1e46491993#d1f6ceee9c59eda45dd9dd99f99c894449cab85d_777_777) I changed the names as you requested, but what about existing functions edit_line_move_to_prev_hist and edit_line_move_to_next_hist?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/8467#note_108928
On Sun Jul 6 04:56:23 2025 +0000, Joe Souza wrote:
changed this line in [version 6 of the diff](/wine/wine/-/merge_requests/8467/diffs?diff_id=191118&start_sha=ccbb22bafaf729c3efbd2d469f883c1e46491993#d1f6ceee9c59eda45dd9dd99f99c894449cab85d_781_781) -1 because I need the previous line in history, not the current line which in history is currently empty.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/8467#note_108929
Changes pushed. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8467#note_108931
participants (2)
-
Joe Souza -
Joe Souza (@JoeS209)