diff --git a/ncdc/include/ncdc/input.h b/ncdc/include/ncdc/input.h index 5e273e4..e7d9c48 100644 --- a/ncdc/include/ncdc/input.h +++ b/ncdc/include/ncdc/input.h @@ -21,6 +21,9 @@ void ncdc_input_set_callback(ncdc_input_t i, ncdc_input_callback_t c, void *a); /* keybinding functions */ +void ncdc_input_kill_right(ncdc_input_t input); +void ncdc_input_kill_left(ncdc_input_t input); +void ncdc_input_kill_word_left(ncdc_input_t input); void ncdc_input_backward(ncdc_input_t i); void ncdc_input_forward(ncdc_input_t i); void ncdc_input_delete(ncdc_input_t input); diff --git a/ncdc/src/input.c b/ncdc/src/input.c index 9b8257f..0102ed2 100644 --- a/ncdc/src/input.c +++ b/ncdc/src/input.c @@ -105,6 +105,46 @@ static void ncdc_input_enter(ncdc_input_t input) input->cursor = 0; } +void ncdc_input_kill_word_left(ncdc_input_t input) +{ + ssize_t i = 0, j = 0; + + return_if_true(input->cursor == 0,); + return_if_true(input->buffer->len == 0,); + + i = input->cursor; + if (i == input->buffer->len) { + --i; + } + + for (; i >= 0 && iswspace(g_array_index(input->buffer, wchar_t, i)); i--, j++) + ; + for (; i >= 0 && !iswspace(g_array_index(input->buffer, wchar_t, i)); i--, j++) + ; + + if (i < 0) { + i = 0; + } + + g_array_remove_range(input->buffer, i, j); + input->cursor = i; +} + +void ncdc_input_kill_left(ncdc_input_t input) +{ + return_if_true(input->cursor == 0,); + g_array_remove_range(input->buffer, 0, input->cursor); + input->cursor = 0; +} + +void ncdc_input_kill_right(ncdc_input_t input) +{ + return_if_true(input->cursor == input->buffer->len,); + g_array_remove_range(input->buffer, input->cursor, + input->buffer->len - input->cursor + ); +} + void ncdc_input_delete(ncdc_input_t input) { return_if_true(input->cursor == input->buffer->len,); diff --git a/ncdc/src/keycodes.c b/ncdc/src/keycodes.c index 96b063a..845d2a2 100644 --- a/ncdc/src/keycodes.c +++ b/ncdc/src/keycodes.c @@ -9,7 +9,7 @@ ncdc_find_keybinding(ncdc_keybinding_t *keys, wchar_t const *key, size_t l) size_t i = 0; for (i = 0; keys[i].name != NULL; i++) { - if ((l == sizeof(wchar_t) && key[0] == keys[i].key[0]) || + if ((l == 1 && key[0] == keys[i].key[0]) || wcscmp(key, keys[i].key) == 0) { return keys+i; } @@ -41,6 +41,15 @@ ncdc_keybinding_t keys_emacs[] = { /* CTRL+B */ NCDC_BINDING(L"\x02", L"backward", ncdc_input_backward), + /* CTRL+K + */ + NCDC_BINDING(L"\x0B", L"kill-right", ncdc_input_kill_right), + /* CTRL+U + */ + NCDC_BINDING(L"\x15", L"kill-left", ncdc_input_kill_left), + /* CTRL+W + */ + NCDC_BINDING(L"\x17", L"kill-word-left", ncdc_input_kill_word_left), /* CTRL+D */ NCDC_BINDING(L"\x04", L"delete", ncdc_input_delete), diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index cfee626..b113307 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -267,10 +267,14 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n) return; } keylen = wcslen(key); + + FILE *f = fopen("keys.txt", "a+"); + fwprintf(f, L"KEY: %ls\n", key); + fclose(f); } FILE *f = fopen("keys.txt", "a+"); - fwprintf(f, L"%d - %ls\n", i, (key == NULL ? L"n/a" : &key[1])); + fwprintf(f, L"%X\n", i); fclose(f); if (key != NULL && @@ -281,7 +285,7 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n) if (n->focus == FOCUS_INPUT) { if (key == NULL) { - ncdc_input_feed(n->in, (wchar_t const *)&i, sizeof(wchar_t)); + ncdc_input_feed(n->in, (wchar_t const *)&i, 1); } else { ncdc_input_feed(n->in, key, wcslen(key)); }