Skip to content

Commit bf86049

Browse files
committed
fix: check terminal capability
1 parent d10f565 commit bf86049

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/charm/input/keymap.clj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,15 @@
134134

135135
(defn- bind-from-capability!
136136
"Bind a key from terminal capability, stripping ESC prefix.
137-
Returns nil if terminal is nil."
137+
Returns nil if terminal is nil or capability not found."
138138
[^KeyMap keymap ^Terminal terminal ^InfoCmp$Capability cap event]
139139
(when terminal
140-
(when-let [seq (KeyMap/key terminal cap)]
141-
;; JLine's key() returns the full sequence including ESC
142-
;; We need to strip the ESC since we read sequences after ESC
143-
(let [seq-str (String. ^chars seq)]
144-
(when (and (pos? (count seq-str))
145-
(= (int (first seq-str)) 27))
146-
(bind-key! keymap (subs seq-str 1) event))))))
140+
;; JLine's getStringCapability returns the full sequence including ESC
141+
;; We need to strip the ESC since we read sequences after ESC
142+
(when-let [seq-str (.getStringCapability terminal cap)]
143+
(when (and (pos? (count seq-str))
144+
(= (int (first seq-str)) 27))
145+
(bind-key! keymap (subs seq-str 1) event)))))
147146

148147
(defn- bind-fallback-sequences!
149148
"Bind fallback sequences for a key."

0 commit comments

Comments
 (0)