Repository navigation
Description
Describe the Bug
When I press Return several times in quick succession, Flyline occasionally prints ^[[I[flyline inserted newline]. Holding Return down only produces blank prompts, as expected. The ^[[I prefix is the terminal's FocusIn report (CSI I), not user input.
This happens during Flyline's prompt shutdown. App::run currently returns an EndState before restore_terminal and drain_shutdown_events run in get_command. Because App::run consumes App, returning drops the terminal backend and restores cooked mode with echo first. A focus report arriving in that interval is therefore echoed visibly before the drain can consume it.
#971 added the shutdown drain for trailing terminal events. The drain handles FocusIn, but its current position means it starts after raw mode has already been released. This appears closely related to #901, although that report concerned mouse events over SSH.
Expected behavior: focus reports emitted during the handoff remain invisible, and repeated empty submissions produce only empty prompts.
Actual behavior: a FocusIn report is intermittently rendered immediately before Flyline's inserted-newline marker.
Environment & Version Information
flyline 1.7.1
git hash: unknown
build mode: release
build datetime: 2026-08-19T20:21:48Z
build target: aarch64-apple-darwin
rustc version: rustc 1.97.1 (8bab26f4f 2026-07-14) (Homebrew)
Running in: Bash 5.3.15(1)-release
shell: /opt/homebrew/bin/bash
Running in: xterm-ghostty (Ghostty)
multiplexer: none
program: ghostty
program version: 1.3.1
Running in: macOS 26.5.1 (arm64)
Debug Logs (Optional / If Necessary)
Not collected. A deterministic pseudo-terminal regression test reproduces the terminal-mode handoff directly.
Steps to Reproduce
- Start an interactive Bash session in Ghostty with Flyline 1.7.1 enabled.
- Press Return several times in quick succession instead of holding it down.
- Observe that
^[[I[flyline inserted newline]occasionally appears between prompts.
The race can be reproduced deterministically with a pseudo-terminal by waiting for Flyline to enable focus tracking, sending Return, and then sending a FocusIn report immediately after Flyline emits the escape sequence that disables focus tracking. On the current code, the report is echoed after raw mode is released; keeping raw mode active through the existing drain prevents the visible leak.
Activity
Drain terminal events before releasing raw mode (HalFrgrd#985)