aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-09-11 09:34:42 -0700
committerRebecca Turner <rbt@sent.as>2024-09-11 09:35:00 -0700
commitdf0137226d7db4bfac455076be9f37dae6f01ffe (patch)
tree71cb6bf625a6d91449011bad404945477c23ba3a
parent24db81eaf28259ab8f8334ccd6368673a26ed422 (diff)
editline: Vendor cl/1883 patch to recognize `Alt+Left`/`Alt+Right`
This vendors the patch added in cl/1883 to avoid GitHub garbage-collecting the commits we're referring to. As @emilazy pointed out on GitHub: > GitHub can garbage‐collect unmerged PR commits if they are later > force‐pushed, which means that code review in upstreams can cause > Nixpkgs builds to fail to reproduce in future. See: https://github.com/NixOS/nixpkgs/pull/341131#discussion_r1753046220 See: https://github.com/troglobit/editline/pull/70 See: https://gerrit.lix.systems/c/lix/+/1883 Change-Id: Ifff522f7f23310d6dbe9efc72fd40be5500ae872
-rw-r--r--nix-support/editline.patch106
-rw-r--r--package.nix12
2 files changed, 108 insertions, 10 deletions
diff --git a/nix-support/editline.patch b/nix-support/editline.patch
new file mode 100644
index 000000000..df31cfdc4
--- /dev/null
+++ b/nix-support/editline.patch
@@ -0,0 +1,106 @@
+From d0f2a5bc2300b96b2434c7838184c1dfd6a639f5 Mon Sep 17 00:00:00 2001
+From: Rebecca Turner <rbt@sent.as>
+Date: Sun, 8 Sep 2024 15:42:42 -0700
+Subject: [PATCH 1/2] Recognize Meta+Left and Meta+Right
+
+Recognize `Alt-Left` and `Alt-Right` for navigating by words in more
+terminals/shells/platforms.
+
+I'm not sure exactly where to find canonical documentation for these
+codes, but this seems to match what my terminal produces (macOS + iTerm2
++ Fish + Tmux).
+
+It might also be nice to have some more support for editing the bindings
+for these characters; sequences of more than one character are not
+supported by `el_bind_key` and similar.
+
+Originally from: https://github.com/troglobit/editline/pull/70
+This patch is applied upstream: https://gerrit.lix.systems/c/lix/+/1883
+
+---
+ src/editline.c | 29 +++++++++++++++++++++++++++--
+ 1 file changed, 27 insertions(+), 2 deletions(-)
+
+diff --git a/src/editline.c b/src/editline.c
+index 5ec9afb..d1cfbbc 100644
+--- a/src/editline.c
++++ b/src/editline.c
+@@ -1034,6 +1034,30 @@ static el_status_t meta(void)
+ return CSeof;
+
+ #ifdef CONFIG_ANSI_ARROWS
++ /* See: https://en.wikipedia.org/wiki/ANSI_escape_code */
++ /* Recognize ANSI escapes for `Meta+Left` and `Meta+Right`. */
++ if (c == '\e') {
++ switch (tty_get()) {
++ case '[':
++ {
++ switch (tty_get()) {
++ /* \e\e[C = Meta+Left */
++ case 'C': return fd_word();
++ /* \e\e[D = Meta+Right */
++ case 'D': return bk_word();
++ default:
++ break;
++ }
++
++ return el_ring_bell();
++ }
++ default:
++ break;
++ }
++
++ return el_ring_bell();
++ }
++
+ /* Also include VT-100 arrows. */
+ if (c == '[' || c == 'O') {
+ switch (tty_get()) {
+@@ -1043,6 +1067,7 @@ static el_status_t meta(void)
+ char seq[4] = { 0 };
+ seq[0] = tty_get();
+
++ /* \e[1~ */
+ if (seq[0] == '~')
+ return beg_line(); /* Home */
+
+@@ -1050,9 +1075,9 @@ static el_status_t meta(void)
+ seq[c] = tty_get();
+
+ if (!strncmp(seq, ";5C", 3))
+- return fd_word(); /* Ctrl+Right */
++ return fd_word(); /* \e[1;5C = Ctrl+Right */
+ if (!strncmp(seq, ";5D", 3))
+- return bk_word(); /* Ctrl+Left */
++ return bk_word(); /* \e[1;5D = Ctrl+Left */
+
+ break;
+ }
+
+From 4c4455353a0a88bee09d5f27c28f81f747682fed Mon Sep 17 00:00:00 2001
+From: Rebecca Turner <rbt@sent.as>
+Date: Mon, 9 Sep 2024 09:44:44 -0700
+Subject: [PATCH 2/2] Add support for \e[1;3C and \e[1;3D
+
+---
+ src/editline.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/src/editline.c b/src/editline.c
+index d1cfbbc..350b5cb 100644
+--- a/src/editline.c
++++ b/src/editline.c
+@@ -1074,9 +1074,11 @@ static el_status_t meta(void)
+ for (c = 1; c < 3; c++)
+ seq[c] = tty_get();
+
+- if (!strncmp(seq, ";5C", 3))
++ if (!strncmp(seq, ";5C", 3)
++ || !strncmp(seq, ";3C", 3))
+ return fd_word(); /* \e[1;5C = Ctrl+Right */
+- if (!strncmp(seq, ";5D", 3))
++ if (!strncmp(seq, ";5D", 3)
++ || !strncmp(seq, ";3D", 3))
+ return bk_word(); /* \e[1;5D = Ctrl+Left */
+
+ break;
diff --git a/package.nix b/package.nix
index c9341d4cb..23ebc3a82 100644
--- a/package.nix
+++ b/package.nix
@@ -87,16 +87,8 @@
# Recognize `Alt-Left` and `Alt-Right` for navigating by words in more
# terminals/shells/platforms.
#
- # See: https://github.com/troglobit/editline/pull/70/commits
- (fetchpatch {
- url = "https://github.com/troglobit/editline/pull/70/commits/d0f2a5bc2300b96b2434c7838184c1dfd6a639f5.diff";
- hash = "sha256-0bbtYDUlk1wA0kpTtlaNI6KaCjLmAesZjcWBJZ+DpyQ=";
- })
-
- (fetchpatch {
- url = "https://github.com/troglobit/editline/pull/70/commits/4c4455353a0a88bee09d5f27c28f81f747682fed.diff";
- hash = "sha256-nVezspwVzeB/8zENeKgwPVum0W1MLv4dOW0967WbX5w=";
- })
+ # See: https://github.com/troglobit/editline/pull/70
+ ./nix-support/editline.patch
];
configureFlags = (prev.configureFlags or [ ]) ++ [