From dba7df7ab8ba562726f10f6b9a5f6312e0637b70 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 2 Aug 2020 23:10:35 -0400 Subject: [PATCH] Add "delete word" support to Console-posix --- docs/changelog.txt | 1 + library/Console-posix.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 8a45ba5b7..bf953d562 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -55,6 +55,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - Extended ``Filesystem::listdir_recursive`` to optionally make returned filenames relative to the start directory ## Internals +- Linux/macOS: Added console keybindings for deleting words (Alt+Backspace and Alt+d in most terminals) - Added support for splitting scripts into multiple files in the ``scripts/internal`` folder without polluting the output of `ls` ## Lua diff --git a/library/Console-posix.cpp b/library/Console-posix.cpp index 6fb1cbff3..595f50e97 100644 --- a/library/Console-posix.cpp +++ b/library/Console-posix.cpp @@ -541,6 +541,7 @@ namespace DFHack return Console::SHUTDOWN; } lock->lock(); + const int old_cursor = raw_cursor; /* Only autocomplete when the callback is set. It returns < 0 when * there was an error reading from fd. Otherwise it will return the * character that should be handled next. */ @@ -597,6 +598,29 @@ namespace DFHack { forward_word(); } + else if (seq[0] == 127 || seq[0] == 8) // backspace || ctrl-h + { + // delete word + back_word(); + if (old_cursor > raw_cursor) + { + yank_buffer = raw_buffer.substr(raw_cursor, old_cursor - raw_cursor); + raw_buffer.erase(raw_cursor, old_cursor - raw_cursor); + prompt_refresh(); + } + } + else if (seq[0] == 'd') + { + // delete word forward + forward_word(); + if (old_cursor < raw_cursor) + { + yank_buffer = raw_buffer.substr(old_cursor, raw_cursor - old_cursor); + raw_buffer.erase(old_cursor, raw_cursor - old_cursor); + raw_cursor = old_cursor; + prompt_refresh(); + } + } else if(seq[0] == '[') { if (!read_char(seq[1]))