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:
Steps to reproduce
- Open a terminal that does not support Kitty/iTerm2/Sixel graphics (e.g. standard macOS Terminal.app)
- Run code that calls
TerminalGraphicsManager.getBestProtocol(terminal) and then closes the terminal
- 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.
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 theTerminalis subsequently closed, these response bytes leak into the parent shell's input buffer, resulting in garbled output like:Steps to reproduce
TerminalGraphicsManager.getBestProtocol(terminal)and then closes the terminalExpected 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-diagramin Apache Camel, which uses JLine 4'sTerminalGraphicsAPI to display inline images. See apache/camel#22794.