Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/dev/jbang/search/ArtifactSearchWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ public Artifact search(String initialQuery) {
}
});

artifactCombobox.handle("next_phase", "\u001b[C", (g) -> {
// Use platform-specific arrow key sequences (fixes Windows compatibility #2403, #2348)
String keyRight = org.jline.keymap.KeyMap.key(terminal, Capability.key_right);
String keyLeft = org.jline.keymap.KeyMap.key(terminal, Capability.key_left);

artifactCombobox.handle("next_phase", keyRight != null ? keyRight : "\u001b[C", (g) -> {
if (g.matches().size() == 0) {
return Collections.<Combobox.ComboboxAction>emptyList();
}
Expand All @@ -332,7 +336,7 @@ public Artifact search(String initialQuery) {
return actions;
});

artifactCombobox.handle("previous_phase", "\u001b[D", (g) -> {
artifactCombobox.handle("previous_phase", keyLeft != null ? keyLeft : "\u001b[D", (g) -> {

Fuzz.SearchFuzzedResult<Artifact> selected = g.matches().get(g.selectedIndex());

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/dev/jbang/search/ComboBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ class Combobox<T> {
this.itemRenderer = (t) -> new AttributedString(t.toString());
this.qb = new StringBuilder(initialQuery);

// Define key bindings
// Define key bindings using platform-specific sequences from terminal capabilities
keys.setNomatch("nomatch"); // Any printable char
handle("up", "\033[A", this::selectionUp); // Arrow up
handle("down", "\033[B", this::selectionDown); // Arrow down

// Use KeyMap.key() to get platform-specific escape sequences for arrow keys
// This fixes Windows terminal compatibility (issue #2403, #2348)
String keyUp = KeyMap.key(terminal, Capability.key_up);
String keyDown = KeyMap.key(terminal, Capability.key_down);

// Fallback to standard ANSI sequences if terminal doesn't provide capabilities
handle("up", keyUp != null ? keyUp : "\033[A", this::selectionUp);
handle("down", keyDown != null ? keyDown : "\033[B", this::selectionDown);
handle("backspace", "\177", this::delete);
handle("enter", "\r", this::select);
handle("nomatch", "\u0003", this::update); // Ctrl-C
Expand Down
Loading