aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-23 01:32:43 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-23 01:37:07 +0200
commit20c883fb8acede8854c1d6322938d2baaa2fe0bd (patch)
tree88cd01db4121c72874c7f494a3a55fe4aafba066
parentbbf97f6d3dea95d47af32cbd3c9904ba418d4675 (diff)
downloadsdn-20c883fb8acede8854c1d6322938d2baaa2fe0bd.tar.gz
sdn-20c883fb8acede8854c1d6322938d2baaa2fe0bd.tar.xz
sdn-20c883fb8acede8854c1d6322938d2baaa2fe0bd.zip
Implement C-v in the editor
Not completely happy with the explicit `halfdelay (1)`. Updates #4
-rw-r--r--sdn.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/sdn.cpp b/sdn.cpp
index dffe978..ec74df7 100644
--- a/sdn.cpp
+++ b/sdn.cpp
@@ -416,7 +416,7 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) \
XX(TOGGLE_FULL) XX(REVERSE_SORT) XX(SHOW_HIDDEN) XX(REDRAW) XX(RELOAD) \
XX(INPUT_ABORT) XX(INPUT_CONFIRM) XX(INPUT_B_DELETE) XX(INPUT_DELETE) \
- XX(INPUT_B_KILL_LINE) XX(INPUT_KILL_LINE) \
+ XX(INPUT_B_KILL_LINE) XX(INPUT_KILL_LINE) XX(INPUT_QUOTED_INSERT) \
XX(INPUT_BACKWARD) XX(INPUT_FORWARD) XX(INPUT_BEGINNING) XX(INPUT_END)
#define XX(name) ACTION_ ## name,
@@ -457,6 +457,7 @@ static map<wint_t, action> g_input_actions {
{KEY (BACKSPACE), ACTION_INPUT_B_DELETE}, {KEY (DC), ACTION_INPUT_DELETE},
{CTRL ('U'), ACTION_INPUT_B_KILL_LINE},
{CTRL ('K'), ACTION_INPUT_KILL_LINE},
+ {CTRL ('V'), ACTION_INPUT_QUOTED_INSERT},
{CTRL ('B'), ACTION_INPUT_BACKWARD}, {KEY (LEFT), ACTION_INPUT_BACKWARD},
{CTRL ('F'), ACTION_INPUT_FORWARD}, {KEY (RIGHT), ACTION_INPUT_FORWARD},
{CTRL ('A'), ACTION_INPUT_BEGINNING}, {KEY (HOME), ACTION_INPUT_BEGINNING},
@@ -532,6 +533,7 @@ static struct {
const wchar_t *editor; ///< Prompt string for editing
wstring editor_line; ///< Current user input
int editor_cursor = 0; ///< Cursor position
+ bool editor_inserting; ///< Inserting a literal character
void (*editor_on_change) (); ///< Callback on editor change
void (*editor_on_confirm) (); ///< Callback on editor confirmation
@@ -1188,7 +1190,12 @@ fun move_towards_spacing (int diff) -> bool {
}
fun handle_editor (wint_t c) {
- auto i = g_input_actions.find (c);
+ auto i = g_input_actions.find (g.editor_inserting ? WEOF : c);
+ if (g.editor_inserting) {
+ (void) halfdelay (1);
+ g.editor_inserting = false;
+ }
+
switch (i == g_input_actions.end () ? ACTION_NONE : i->second) {
case ACTION_INPUT_CONFIRM:
if (g.editor_on_confirm)
@@ -1198,6 +1205,7 @@ fun handle_editor (wint_t c) {
g.editor = 0;
g.editor_line.clear ();
g.editor_cursor = 0;
+ g.editor_inserting = false;
g.editor_on_change = nullptr;
g.editor_on_confirm = nullptr;
break;
@@ -1239,6 +1247,10 @@ fun handle_editor (wint_t c) {
case ACTION_INPUT_KILL_LINE:
g.editor_line.erase (g.editor_cursor);
break;
+ case ACTION_INPUT_QUOTED_INSERT:
+ (void) raw ();
+ g.editor_inserting = true;
+ break;
default:
if (c & (ALT | SYM)) {
beep ();