about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAndrew Ho <andrew@zeuscat.com>2014-12-30 22:36:54 -0800
committerAndrew Ho <andrew@zeuscat.com>2014-12-30 22:36:54 -0800
commit7fac4bcc14d6b9a21c28fbda11401c43ecfdf3c5 (patch)
treefe6a6ae811c385b4e6db148f232637c6e109aea7 /src
parente7ddff61dcb0831d8f8ca469844c0de0306f8994 (diff)
downloadprofani-tty-7fac4bcc14d6b9a21c28fbda11401c43ecfdf3c5.tar.gz
Add readline-style keybindings
Diffstat (limited to 'src')
-rw-r--r--src/ui/inputwin.c17
-rw-r--r--src/ui/inputwin.h10
2 files changed, 26 insertions, 1 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 4ed47601..4c5f139e 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -423,6 +423,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_D:
             if (inp_x == display_size-1) {
                 gchar *start = g_utf8_substring(input, 0, inp_x);
                 for (*size = 0; *size < strlen(start); (*size)++) {
@@ -459,6 +460,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_B:
             if (inp_x > 0) {
                 wmove(inp_win, 0, inp_x-1);
 
@@ -474,6 +476,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_F:
             if (inp_x < display_size) {
                 wmove(inp_win, 0, inp_x+1);
 
@@ -489,6 +492,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_P:
             prev = cmd_history_previous(input, size);
             if (prev) {
                 inp_replace_input(input, prev, size);
@@ -499,6 +503,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_N:
             next = cmd_history_next(input, size);
             if (next) {
                 inp_replace_input(input, next, size);
@@ -513,6 +518,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_A:
             wmove(inp_win, 0, 0);
             pad_start = 0;
             _inp_win_update_virtual();
@@ -522,6 +528,7 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             if (result != KEY_CODE_YES) {
                 return 0;
             }
+        case KEY_CTRL_E:
             _go_to_end(display_size);
             return 1;
 
@@ -535,10 +542,18 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             }
             return 1;
 
-        case 23: // ctrl-w
+        case KEY_CTRL_W:
             _delete_previous_word(input, size);
             return 1;
             break;
+
+        case KEY_CTRL_U:
+            while (getcurx(inp_win) > 0) {
+                _delete_previous_word(input, size);
+            }
+            return 1;
+            break;
+
         default:
             return 0;
         }
diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h
index eae20a51..971c1088 100644
--- a/src/ui/inputwin.h
+++ b/src/ui/inputwin.h
@@ -35,6 +35,16 @@
 #ifndef UI_INPUTWIN_H
 #define UI_INPUTWIN_H
 
+#define KEY_CTRL_A 0001
+#define KEY_CTRL_B 0002
+#define KEY_CTRL_D 0004
+#define KEY_CTRL_E 0005
+#define KEY_CTRL_F 0006
+#define KEY_CTRL_N 0016
+#define KEY_CTRL_P 0020
+#define KEY_CTRL_U 0025
+#define KEY_CTRL_W 0027
+
 void create_input_window(void);
 wint_t inp_get_char(char *input, int *size, int *result);
 void inp_win_reset(void);