Skip to content

Drain terminal events before releasing raw mode - #985

Open
TBarregren wants to merge 1 commit into
HalFrgrd:masterfrom
TBarregren:fix/drain-terminal-events-before-cooked-mode
Open

Drain terminal events before releasing raw mode#985
TBarregren wants to merge 1 commit into
HalFrgrd:masterfrom
TBarregren:fix/drain-terminal-events-before-cooked-mode

Conversation

@TBarregren

Copy link
Copy Markdown

Fixes #984

Summary

  • Restore terminal modes and drain trailing terminal reports while App still owns the terminal and raw mode remains active.
  • Remove the EndState transport type, since shutdown draining now happens inside App::run.
  • Add a deterministic pseudo-terminal regression test to the existing Bash integration-test images.

Root cause

The shutdown drain added in #971 runs in get_command, after App::run returns. App::run consumes App, so returning drops its terminal backend and restores cooked mode with echo before the drain begins. A FocusIn report arriving in that interval can be echoed as ^[[I; consuming it afterward prevents it from becoming input, but cannot undo the visible output.

This change sends the terminal reset sequences and performs the existing conditional drain at the end of App::run, before self is dropped. The shell still receives the same ExitState after the terminal handoff is complete.

Regression coverage

The new test runs Flyline as a real Bash loadable builtin behind a pseudo-terminal, emulates the terminal queries used during startup, submits an empty command, and injects a FocusIn report at the focus-tracking shutdown boundary. It fails on the unmodified code with ^[[I[flyline inserted newline] and passes when the drain runs before raw mode is released.

The test is part of the existing Docker Bash integration targets, so CI will exercise it across the supported Bash versions.

Verification

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-features -- -D warnings
  • cargo test --workspace --all-features --lib -- --skip history::tests::test_pipeline_history_entry_formatting — 1,031 passed, 0 failed, 1 ignored
  • TZ=UTC cargo test -p flyline history::tests::test_pipeline_history_entry_formatting -- --exact — passed; this existing test expects a UTC calendar date and fails under Europe/Stockholm
  • Regression test against unmodified Flyline 1.7.1 — failed as expected in three of three runs
  • Regression test against this branch — passed in three of three runs
  • Docker integration targets — passed with Bash 4.4-rc1, 4.4.18, 5.0, and 5.3

Bash 3.2 could not be built locally because the config.guess shipped with Bash 3.2 does not recognize Docker Desktop's ARM64 platform. The existing x86 GitHub Actions job will cover that target.

Flyline can receive a terminal report after accepting Enter. Draining after App::run returns is too late because App's terminal has already restored echo mode. Restore terminal modes and drain while App remains alive, and cover the handoff with a deterministic PTY regression test.
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.

[BUG]: FocusIn report leaks into the prompt when Return is pressed rapidly

1 participant