Skip to content

Console +/- resize keys unreliable across terminal protocols #412

@edlsh

Description

@edlsh

Description

The + and - keys for resizing the console window do not work reliably. The issue is intermittent and depends on the terminal emulator and keyboard protocol in use.

Root Cause Analysis

The key handling in packages/core/src/console.ts (lines 480-485) checks:

} else if (event.name === "+" || (event.name === "=" && event.shift)) {
  this.options.sizePercent = Math.min(100, this.options.sizePercent + 5)
  this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight)
} else if (event.name === "-") {

Issues identified:

  1. Kitty keyboard protocol inconsistency: When Kitty protocol is enabled, terminals may send the base key codepoint (= with shift modifier) rather than the shifted result (+). In parse.keypress-kitty.ts, key.name is set from String.fromCodePoint(codepoint) and the shifted codepoint only updates text, not key.name.

  2. US keyboard layout assumption: The + key requires Shift+= on US keyboards. Different terminals handle this differently:

    • Raw mode: Sends literal + character
    • Kitty protocol: May send codepoint 61 (=) with shift flag, or codepoint 43 (+)
  3. No keypad support: Numeric keypad + and - keys (codes 57413/57414 in Kitty) are mapped to kpminus/kpplus but not handled by the console.

Suggested Fix

Normalize key detection to handle all variants:

const isPlus = event.name === "+" || 
               (event.name === "=" && event.shift) ||
               event.name === "kpplus"

const isMinus = event.name === "-" || 
                event.name === "kpminus"

if (isPlus) {
  this.options.sizePercent = Math.min(100, this.options.sizePercent + 5)
  this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight)
} else if (isMinus) {
  this.options.sizePercent = Math.max(10, this.options.sizePercent - 5)
  this.resize(this.renderer.terminalWidth, this.renderer.terminalHeight)
}

Environment

  • Affected file: packages/core/src/console.ts
  • Related files: packages/core/src/lib/parse.keypress.ts, packages/core/src/lib/parse.keypress-kitty.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions