-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix kitty keyboard protocol parsing of ctrl-o
Commit 6e4510b (subshell: recognize CSI u encoding for ctrl-o, 2024-10-09) made us parse sequences like \e[111;5u (meaning ctrl-o). As reported in fish-shell/fish-shell#10640 (comment), the kitty keyboard protocol specifies various other sequences that also mean ctrl-o. Specifically, when numlock is active. Instead of matching raw byte values, let's add teach our ECMA-48 CSI parser to decode parameter bytes and interpret them according to the kitty keyboard protocol. Tested with fish version 4: 1. Turn on numlock 2. SHELL=/bin/fish src/mc 3. ctrl-o 4. Enter 5. ctrl-o -- confirmed that this one is recognized now Note that capslock still disables ctrl-o. We could change that easily (and for consistency also allow ctrl-O). While at it, add some unit tests (using a fish prompt as input data).
- Loading branch information
Showing
8 changed files
with
272 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terminal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
PACKAGE_STRING = "/src/lib" | ||
|
||
AM_CPPFLAGS = \ | ||
-DTEST_SHARE_DIR=\"$(abs_srcdir)\" \ | ||
$(GLIB_CFLAGS) \ | ||
-I$(top_srcdir) \ | ||
@CHECK_CFLAGS@ | ||
|
||
LIBS = @CHECK_LIBS@ \ | ||
$(top_builddir)/src/libinternal.la \ | ||
$(top_builddir)/lib/libmc.la | ||
|
||
if ENABLE_MCLIB | ||
LIBS += $(GLIB_LIBS) | ||
endif | ||
|
||
TESTS = \ | ||
terminal | ||
|
||
check_PROGRAMS = $(TESTS) | ||
|
||
edit_complete_word_cmd_SOURCES = \ | ||
terminal.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
#include <config.h> | ||
#include "lib/global.h" // include <glib.h> | ||
#include "lib/terminal.h" | ||
#include "lib/strutil.h" | ||
|
||
#define TEST_SUITE_NAME "/src/lib/terminal" | ||
|
||
#include "tests/mctest.h" | ||
|
||
/* --------------------------------------------------------------------------------------------- */ | ||
|
||
static void | ||
setup (void) | ||
{ | ||
str_init_strings (NULL); | ||
} | ||
|
||
static void | ||
teardown (void) | ||
{ | ||
str_uninit_strings (); | ||
} | ||
|
||
/* --------------------------------------------------------------------------------------------- */ | ||
|
||
START_TEST (test_parse_csi) | ||
{ | ||
const char *s = &"\x1b[=5uRest"[2]; | ||
const char *end = s + strlen (s); | ||
gboolean ok = parse_csi (NULL, &s, end); | ||
ck_assert_msg (ok, "failed to parse"); | ||
ck_assert_str_eq (s, "Rest"); | ||
} | ||
END_TEST | ||
|
||
/* --------------------------------------------------------------------------------------------- */ | ||
|
||
START_TEST (test_strip_ctrl_codes) | ||
{ | ||
char *s = strdup ( | ||
"\033]0;~\a\033[30m\033(B\033[m\033]133;A;special_key=1\a$ " | ||
"\033[K\033[?2004h\033[>4;1m\033[=5u\033=\033[?2004l\033[>4;0m\033[=0u\033>\033[?2004h\033[" | ||
">4;1m\033[=5u\033=\033[?2004l\033[>4;0m\033[=0u\033>\033[?2004h\033[>4;1m\033[=5u\033="); | ||
char *actual = strip_ctrl_codes (s); | ||
const char *expected = "$ "; | ||
ck_assert_str_eq (actual, expected); | ||
free (s); | ||
} | ||
|
||
/* --------------------------------------------------------------------------------------------- */ | ||
|
||
int | ||
main (void) | ||
{ | ||
TCase *tc_core; | ||
|
||
tc_core = tcase_create ("Core"); | ||
|
||
tcase_add_checked_fixture (tc_core, setup, teardown); | ||
|
||
// Add new tests here: *************** | ||
tcase_add_test (tc_core, test_parse_csi); | ||
tcase_add_test (tc_core, test_strip_ctrl_codes); | ||
// *********************************** | ||
|
||
return mctest_run_all (tc_core); | ||
} | ||
|
||
/* --------------------------------------------------------------------------------------------- */ |