Add "delete word" support to Console-posix

develop
lethosor 2020-08-02 23:10:35 -04:00
parent bb66ef32a7
commit dba7df7ab8
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 25 additions and 0 deletions

@ -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 - Extended ``Filesystem::listdir_recursive`` to optionally make returned filenames relative to the start directory
## Internals ## 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` - Added support for splitting scripts into multiple files in the ``scripts/internal`` folder without polluting the output of `ls`
## Lua ## Lua

@ -541,6 +541,7 @@ namespace DFHack
return Console::SHUTDOWN; return Console::SHUTDOWN;
} }
lock->lock(); lock->lock();
const int old_cursor = raw_cursor;
/* Only autocomplete when the callback is set. It returns < 0 when /* Only autocomplete when the callback is set. It returns < 0 when
* there was an error reading from fd. Otherwise it will return the * there was an error reading from fd. Otherwise it will return the
* character that should be handled next. */ * character that should be handled next. */
@ -597,6 +598,29 @@ namespace DFHack
{ {
forward_word(); 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] == '[') else if(seq[0] == '[')
{ {
if (!read_char(seq[1])) if (!read_char(seq[1]))