Implement readline-style Ctrl-U and Ctrl-Y

develop
lethosor 2014-08-09 20:10:34 -04:00
parent e71fc0455c
commit 71236afa42
1 changed files with 19 additions and 6 deletions

@ -648,15 +648,27 @@ namespace DFHack
prompt_refresh(); prompt_refresh();
} }
break; break;
case 21: // Ctrl+u, delete the whole line. case 21: // Ctrl+u, delete from current to beginning of line.
raw_buffer.clear(); if (raw_cursor > 0)
yank_buffer = raw_buffer.substr(0, raw_cursor);
raw_buffer.erase(0, raw_cursor);
raw_cursor = 0; raw_cursor = 0;
prompt_refresh(); prompt_refresh();
break; break;
case 11: // Ctrl+k, delete from current to end of line. case 11: // Ctrl+k, delete from current to end of line.
if (raw_cursor < raw_buffer.size())
yank_buffer = raw_buffer.substr(raw_cursor, raw_buffer.size() - raw_cursor);
raw_buffer.erase(raw_cursor); raw_buffer.erase(raw_cursor);
prompt_refresh(); prompt_refresh();
break; break;
case 25: // Ctrl+y, paste last text deleted with Ctrl+u/k
if (yank_buffer.size())
{
raw_buffer.insert(raw_cursor, yank_buffer);
raw_cursor += yank_buffer.size();
prompt_refresh();
}
break;
case 1: // Ctrl+a, go to the start of the line case 1: // Ctrl+a, go to the start of the line
raw_cursor = 0; raw_cursor = 0;
prompt_refresh(); prompt_refresh();
@ -686,6 +698,7 @@ namespace DFHack
bool in_batch; bool in_batch;
std::string prompt; // current prompt string std::string prompt; // current prompt string
std::string raw_buffer; // current raw mode buffer std::string raw_buffer; // current raw mode buffer
std::string yank_buffer; // last text deleted with Ctrl-K/Ctrl-U
int raw_cursor; // cursor position in the buffer int raw_cursor; // cursor position in the buffer
// thread exit mechanism // thread exit mechanism
int exit_pipe[2]; int exit_pipe[2];