about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-12-01 21:45:08 +0000
committerJames Booth <boothj5@gmail.com>2014-12-01 21:45:08 +0000
commitfe021a226c1246350493d3655608a3d559294455 (patch)
treebad264bbe173768ccfa0598eaa11dfbc870884a0 /src/ui
parent71ed9ac2d1b50b9063ecb10f183d94a51ccb8d20 (diff)
downloadprofani-tty-fe021a226c1246350493d3655608a3d559294455.tar.gz
Added ctrl-w support (with debug)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/inputwin.c135
1 files changed, 77 insertions, 58 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 03211d94..c3b20e1a 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -72,6 +72,7 @@ static void _handle_backspace(int display_size, int inp_x, int *size, char *inpu
 static int _printable(const wint_t ch);
 static void _clear_input(void);
 static void _go_to_end(int display_size);
+static void _delete_previous_word(char *input, int *size);
 
 void
 create_input_window(void)
@@ -134,6 +135,14 @@ inp_get_char(char *input, int *size, int *result)
     noecho();
     *result = wget_wch(inp_win, &ch);
 
+    if (*result != ERR) {
+        if (*result == KEY_CODE_YES) {
+            cons_debug("KEY %d, KEY_CODE_YES", ch);
+        } else {
+            cons_debug("KEY %d", ch);
+        }
+    }
+
     gboolean in_command = FALSE;
     if ((display_size > 0 && input[0] == '/') ||
             (display_size == 0 && ch == '/')) {
@@ -534,6 +543,10 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
             }
             return 1;
 
+        case 23: // ctrl-w
+            _delete_previous_word(input, size);
+            return 1;
+            break;
         default:
             return 0;
         }
@@ -597,8 +610,7 @@ _handle_backspace(int display_size, int inp_x, int *size, char *input)
 static int
 _handle_alt_key(char *input, int *size, int key)
 {
-    int end_del = getcurx(inp_win);
-    int start_del = end_del;
+    cons_debug("ALT %d", key);
 
     switch (key)
     {
@@ -640,75 +652,82 @@ _handle_alt_key(char *input, int *size, int key)
             break;
         case 263:
         case 127:
-            input[*size] = '\0';
-            gchar *curr_ch = g_utf8_offset_to_pointer(input, end_del);
-            curr_ch = g_utf8_find_prev_char(input, curr_ch);
-            gchar *prev_ch;
-            gunichar curr_uni;
-            gunichar prev_uni;
+            _delete_previous_word(input, size);
+            break;
+        default:
+            break;
+    }
+    return 1;
+}
 
-            while (curr_ch != NULL) {
-                curr_uni = g_utf8_get_char(curr_ch);
+static void
+_delete_previous_word(char *input, int *size)
+{
+    int end_del = getcurx(inp_win);
+    int start_del = end_del;
 
-                if (g_unichar_isspace(curr_uni)) {
-                    curr_ch = g_utf8_find_prev_char(input, curr_ch);
-                } else {
-                    prev_ch = g_utf8_find_prev_char(input, curr_ch);
-                    if (prev_ch == NULL) {
-                        curr_ch = NULL;
-                        break;
-                    } else {
-                        prev_uni = g_utf8_get_char(prev_ch);
-                        if (g_unichar_isspace(prev_uni)) {
-                            break;
-                        } else {
-                            curr_ch = prev_ch;
-                        }
-                    }
-                }
-            }
+    input[*size] = '\0';
+    gchar *curr_ch = g_utf8_offset_to_pointer(input, end_del);
+    curr_ch = g_utf8_find_prev_char(input, curr_ch);
+    gchar *prev_ch;
+    gunichar curr_uni;
+    gunichar prev_uni;
 
-            if (curr_ch == NULL) {
-                start_del = 0;
+    while (curr_ch != NULL) {
+        curr_uni = g_utf8_get_char(curr_ch);
+
+        if (g_unichar_isspace(curr_uni)) {
+            curr_ch = g_utf8_find_prev_char(input, curr_ch);
+        } else {
+            prev_ch = g_utf8_find_prev_char(input, curr_ch);
+            if (prev_ch == NULL) {
+                curr_ch = NULL;
+                break;
             } else {
-                start_del = g_utf8_pointer_to_offset(input, curr_ch);
+                prev_uni = g_utf8_get_char(prev_ch);
+                if (g_unichar_isspace(prev_uni)) {
+                    break;
+                } else {
+                    curr_ch = prev_ch;
+                }
             }
+        }
+    }
 
-            gint len = g_utf8_strlen(input, -1);
-            gchar *start_string = g_utf8_substring(input, 0, start_del);
-            gchar *end_string = g_utf8_substring(input, end_del, len);
+    if (curr_ch == NULL) {
+        start_del = 0;
+    } else {
+        start_del = g_utf8_pointer_to_offset(input, curr_ch);
+    }
 
-            int i;
-            for (i = 0; i < strlen(start_string); i++) {
-                input[i] = start_string[i];
-            }
-            for (i = 0; i < strlen(end_string); i++) {
-                input[strlen(start_string)+i] = end_string[i];
-            }
+    gint len = g_utf8_strlen(input, -1);
+    gchar *start_string = g_utf8_substring(input, 0, start_del);
+    gchar *end_string = g_utf8_substring(input, end_del, len);
 
-            *size = strlen(start_string)+i;
-            input[*size] = '\0';
+    int i;
+    for (i = 0; i < strlen(start_string); i++) {
+        input[i] = start_string[i];
+    }
+    for (i = 0; i < strlen(end_string); i++) {
+        input[strlen(start_string)+i] = end_string[i];
+    }
 
-            _clear_input();
-            waddstr(inp_win, input);
-            wmove(inp_win, 0, start_del);
+    *size = strlen(start_string)+i;
+    input[*size] = '\0';
 
-            // if gone off screen to left, jump left (half a screen worth)
-            if (start_del <= pad_start) {
-                pad_start = pad_start - (cols / 2);
-                if (pad_start < 0) {
-                    pad_start = 0;
-                }
+    _clear_input();
+    waddstr(inp_win, input);
+    wmove(inp_win, 0, start_del);
 
-                _inp_win_update_virtual();
-            }
+    // if gone off screen to left, jump left (half a screen worth)
+    if (start_del <= pad_start) {
+        pad_start = pad_start - (cols / 2);
+        if (pad_start < 0) {
+            pad_start = 0;
+        }
 
-            return 1;
-            break;
-        default:
-            break;
+        _inp_win_update_virtual();
     }
-    return 1;
 }
 
 static void