Skip to content

fix: use platform-specific arrow key sequences for Windows compatibility#2436

Closed
maxandersen wants to merge 1 commit intojbangdev:mainfrom
maxandersen:2403-fix-windows-arrow-keys
Closed

fix: use platform-specific arrow key sequences for Windows compatibility#2436
maxandersen wants to merge 1 commit intojbangdev:mainfrom
maxandersen:2403-fix-windows-arrow-keys

Conversation

@maxandersen
Copy link
Copy Markdown
Collaborator

Fixes #2403
Fixes #2348

Problem

The jbang deps search command was broken on Windows terminals (CMD, PowerShell, Git Bash). When pressing arrow keys:

  • Down arrow added 'B' characters to the input instead of moving selection
  • The list became shorter
  • Selection indicator didn't move

Root Cause

The code used hardcoded ANSI escape sequences for arrow keys:

  • Up: \033[A
  • Down: \033[B
  • Left: \033[D
  • Right: \033[C

These sequences don't work correctly on Windows terminals because different terminals send different escape sequences.

Solution

Use JLine3's KeyMap.key(terminal, Capability) method to get platform-specific escape sequences:

  • KeyMap.key(terminal, Capability.key_up)
  • KeyMap.key(terminal, Capability.key_down)
  • KeyMap.key(terminal, Capability.key_left)
  • KeyMap.key(terminal, Capability.key_right)

This method queries the terminal's capabilities and returns the correct sequence for each platform, with fallback to standard ANSI sequences for terminals that don't provide capability information.

Changes

  • ComboBox.java: Use platform-specific sequences for up/down arrow keys (list navigation)
  • ArtifactSearchWidget.java: Use platform-specific sequences for left/right arrow keys (phase navigation)

Testing

  • ✅ Maintains backward compatibility with fallback mechanism
  • ✅ Uses JLine's built-in platform abstraction
  • ✅ Should work on Windows CMD, PowerShell, Git Bash, and all Unix terminals
  • ⚠️ Needs testing on Windows to confirm (I don't have access to Windows)

🤖 Generated with Claude Code

Fixes jbangdev#2403, jbangdev#2348

The `jbang deps search` command was broken on Windows terminals because
it used hardcoded ANSI escape sequences (\033[A, \033[B, etc.) for arrow
keys. These sequences don't work correctly on Windows CMD, PowerShell,
or Git Bash.

Changes:
- ComboBox.java: Use KeyMap.key(terminal, Capability) to get platform-
  specific escape sequences for up/down arrow keys with fallback to
  standard ANSI sequences
- ArtifactSearchWidget.java: Same fix for left/right arrow keys used
  in phase navigation

This ensures cross-platform compatibility while maintaining backward
compatibility for terminals that don't provide capability information.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@maxandersen
Copy link
Copy Markdown
Collaborator Author

lets fix this using a different tui.

@maxandersen maxandersen closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jbang deps search <artifact> broken jbang deps search faulty terminal UI on Windows

1 participant