Skip to content

TerminalGraphicsManager.getBestProtocol() leaks DA response bytes to parent shell #1856

@gnodet

Description

@gnodet

Description

When using TerminalGraphicsManager.getBestProtocol(terminal) to detect terminal graphics support, the method sends DA (Device Attributes) capability queries to the terminal. If the terminal does not support any graphics protocol, the DA responses arrive asynchronously and are not consumed before the method returns. When the Terminal is subsequently closed, these response bytes leak into the parent shell's input buffer, resulting in garbled output like:

^[[?62;4;9;22c^[[?1;2c

Steps to reproduce

  1. Open a terminal that does not support Kitty/iTerm2/Sixel graphics (e.g. standard macOS Terminal.app)
  2. Run code that calls TerminalGraphicsManager.getBestProtocol(terminal) and then closes the terminal
  3. Observe the DA response escape sequences printed to the terminal after the program exits

Expected behavior

getBestProtocol() should drain any pending probe responses before returning, so no leftover escape sequences leak to the parent shell.

Context

Discovered while implementing camel cmd route-diagram in Apache Camel, which uses JLine 4's TerminalGraphics API to display inline images. See apache/camel#22794.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixBug fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions