[PR #15991] ConPTY: Fix missing flush on console mode changes #30795

Open
opened 2026-01-31 09:42:59 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/15991

State: closed
Merged: Yes


Previously, all unknown escape sequences would lead to an immediate call
to VtEngine::_Flush(). This lead to problems with nushell which uses
FTCS marks that were unknown to us. Combined with the linewise redrawing
that nushell does, Terminal would get the prompt in two separate frames,
causing a slight flickering.

#14677 fixed this by suppressing the _Flush() call when unknown
sequences are encountered. Unfortunately, this triggered a bug due
to our somewhat "inconsistent" architecture in conhost:
XtermEngine::WriteTerminalW isn't just used to flush unknown sequences
but also used directly by InputBuffer::PassThroughWin32MouseRequest
to write its mouse sequence directly to the ConPTY host.
VtEngine already contains a number of specialized member functions
like RequestWin32Input() to ensure that _Flush() is called
immediately and another member could've been added to solve this issue.
This commit now adds RequestMouseMode in the same vein.

But I believe we can make the system more robust in general by using
eager flushing by default (= safe), similar to how a write() on a
TCP socket flushes by default, and instead only selectively pause and
unpause flushing with a system similar to TCP_CORK.

This seems to work fairly well, as it solves:

  • The original nushell bug
  • The new bug
  • Improves overall throughput by ~33% (due to less flushing)

In particular the last point is noteworthy, as this commit removes
the last performance bottleneck in ConPTY that isn't VtEngine.
Around ~95% of all CPU and wall time is spent in there now and any
improvements to VtEngine should yield immediately results.

Closes #15711

Validation Steps Performed

**Original Pull Request:** https://github.com/microsoft/terminal/pull/15991 **State:** closed **Merged:** Yes --- Previously, all unknown escape sequences would lead to an immediate call to `VtEngine::_Flush()`. This lead to problems with nushell which uses FTCS marks that were unknown to us. Combined with the linewise redrawing that nushell does, Terminal would get the prompt in two separate frames, causing a slight flickering. #14677 fixed this by suppressing the `_Flush()` call when unknown sequences are encountered. Unfortunately, this triggered a bug due to our somewhat "inconsistent" architecture in conhost: `XtermEngine::WriteTerminalW` isn't just used to flush unknown sequences but also used directly by `InputBuffer::PassThroughWin32MouseRequest` to write its mouse sequence directly to the ConPTY host. `VtEngine` already contains a number of specialized member functions like `RequestWin32Input()` to ensure that `_Flush()` is called immediately and another member could've been added to solve this issue. This commit now adds `RequestMouseMode` in the same vein. But I believe we can make the system more robust in general by using eager flushing by default (= safe), similar to how a `write()` on a TCP socket flushes by default, and instead only selectively pause and unpause flushing with a system similar to `TCP_CORK`. This seems to work fairly well, as it solves: * The original nushell bug * The new bug * Improves overall throughput by ~33% (due to less flushing) In particular the last point is noteworthy, as this commit removes the last performance bottleneck in ConPTY that isn't `VtEngine`. Around ~95% of all CPU and wall time is spent in there now and any improvements to `VtEngine` should yield immediately results. Closes #15711 ## Validation Steps Performed * Clone/Run https://github.com/chrisant996/repro_enable_mouse_input * Hold Ctrl+Alt and circle with the mouse over the viewport * Repro.exe prints the current cursor coordinates ✅ * Run nushell * No flickering when typing in the prompt ✅
claunia added the pull-request label 2026-01-31 09:42:59 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30795