From e70839ee30f3241b97ab5c965429688c8d2806e5 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Thu, 3 Oct 2024 18:26:36 +0200 Subject: [PATCH] Add support for c-Left/c-Right --- src/Editor/Editor.php | 11 +++++++++++ src/Terminal/Terminal.php | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/Editor/Editor.php b/src/Editor/Editor.php index 903eefa..1198f4a 100644 --- a/src/Editor/Editor.php +++ b/src/Editor/Editor.php @@ -736,6 +736,17 @@ class Editor if ($cursorPos < mb_strlen($value)) $cursorPos++; break; + case "k{CLEFT}": + while ($cursorPos > 0) { + $cursorPos--; + if (mb_substr($value, $cursorPos - 1, 1) == " ") { + break; + } + } + break; + case "k{CRIGHT}": + $cursorPos = min(mb_strlen($value), (mb_strpos($value, " ", $cursorPos) ?: mb_strlen($value)) + 1); + break; case "k{HOME}": $cursorPos = 0; break; diff --git a/src/Terminal/Terminal.php b/src/Terminal/Terminal.php index b68f50d..825e8c0 100644 --- a/src/Terminal/Terminal.php +++ b/src/Terminal/Terminal.php @@ -112,9 +112,15 @@ class Terminal } elseif (strncmp($this->inputBuffer, "\e[C", 3) === 0) { $this->inputBuffer = mb_substr($this->inputBuffer, 3); return "k{RIGHT}"; + } elseif (strncmp($this->inputBuffer, "\e[1;5C", 6) === 0) { + $this->inputBuffer = mb_substr($this->inputBuffer, 6); + return "k{CRIGHT}"; } elseif (strncmp($this->inputBuffer, "\e[D", 3) === 0) { $this->inputBuffer = mb_substr($this->inputBuffer, 3); return "k{LEFT}"; + } elseif (strncmp($this->inputBuffer, "\e[1;5D", 6) === 0) { + $this->inputBuffer = mb_substr($this->inputBuffer, 6); + return "k{CLEFT}"; } elseif (strncmp($this->inputBuffer, "\e[H", 3) === 0) { $this->inputBuffer = mb_substr($this->inputBuffer, 3); return "k{HOME}";