Fixes #3985. Remove unix driver; augment ansi driver to support configurable size detection#4821
Fixes #3985. Remove unix driver; augment ansi driver to support configurable size detection#4821tig merged 15 commits intov2_developfrom
Conversation
…pport polling size detection - Delete UnixComponentFactory, IUnixInput, UnixInput, UnixInputProcessor, UnixOutput - Move shared Unix infrastructure (UnixIOHelper, UnixRawModeHelper, UnixTerminalHelper, SuspendHelper, UnixClipboard) to Drivers/ root - Remove Names.UNIX and UNIX driver registration from DriverRegistry - Update GetDefaultDriver() to return 'ansi' on Unix/macOS instead of 'unix' - Add SizeDetectionMode enum (Polling/AnsiQuery) - Add Driver.SizeDetection ConfigurationProperty defaulting to Polling - Update AnsiComponentFactory.CreateSizeMonitor() to use config-based selection - Register SizeDetectionMode in SourceGenerationContext for AOT - Remove Unix driver tests for deleted classes - Update all references to Names.UNIX and UnixComponentFactory Co-authored-by: tig <585482+tig@users.noreply.github.com>
|
@copilot you need to update drivers.md and the other deep dives that refer to the unix driver. |
|
@tig The model You can try again without specifying a model (just If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: |
|
@copilot non-parallelt unit tests are failing on all runners. you must fix. also "New behavior selects the size monitor based on the new Driver.SizeDetection configuration (and returns AnsiSizeMonitor vs SizeMonitorImpl). There are existing tests for AnsiComponentFactory creation, but none cover this selection logic. Please add unit tests that verify: (1) injected sizeMonitor is returned, (2) AnsiQuery returns AnsiSizeMonitor (when output is AnsiOutput), and (3) Polling returns SizeMonitorImpl." |
BDisp
left a comment
There was a problem hiding this comment.
Except for the flaw in the unit tests, everything seems to be fine to me.
…ing uses NativeSizeQuery, update docs and tests Co-authored-by: tig <585482+tig@users.noreply.github.com>
…lock with trace logging Co-authored-by: tig <585482+tig@users.noreply.github.com>
Updated in commit
Fixed in commit Fixes:
New tests in |
…s/Terminal.Gui into copilot/remove-unix-driver
Previously, the ANSI driver was stuck at 80×25 and did not respond to terminal resize events due to using SizeMonitorImpl, which only saw a cached size. This commit ensures AnsiSizeMonitor is always used for AnsiOutput, regardless of SizeDetectionMode, enabling correct resize detection via CSI 18t queries. Added Trace.Lifecycle instrumentation for event/trace observability. Updated and added comprehensive tests for monitor behavior and trace output. Also restored and cleaned up clipboard, IO, and Windows VT helper files. Documentation details the bug, fix, and verification steps. The ANSI driver now reliably tracks terminal size changes on all supported platforms.
SuspendHelper contains only Unix libc P/Invoke (killpg, uname) for SIGTSTP. It belongs in UnixHelpers alongside the other Unix-specific helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move tcdrain/fsync to UnixIOHelper.FlushStdout() and FlushFileBuffers to WindowsVTOutputHelper.FlushStdout(). Add isatty to UnixIOHelper for Phase 3. AnsiTerminalHelper is now a pure dispatcher with zero DllImport. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Create WindowsConsoleHelper with GetStdHandle/GetConsoleMode. Driver.IsAttachedToTerminal dispatches to WindowsConsoleHelper and UnixIOHelper.IsTerminal; contains zero DllImport itself. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NetWinVTConsole uses different console mode flags than WindowsVTInputHelper (more conservative), so it cannot be deleted as a straight replacement. Move it to WindowsHelpers to consolidate all Win32 P/Invoke in the correct directory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reformat and reorganize code for readability Refactored several files to improve code readability and maintainability by reformatting constructor initializations, Bash command invocations, and P/Invoke declarations. No functional changes were made; all updates are organizational and stylistic.
Restore terminal to cooked mode (stty sane) before sending SIGTSTP so the shell can function while the process is stopped. Add diagnostic logging to the suspend/resume lifecycle and fix the killpg P/Invoke declaration (SetLastError, parameter name). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Termios P/Invoke struct used uint (4 bytes) for tcflag_t/speed_t and NCCS=32, which matches Linux (56 bytes total) but is wrong for macOS where tcflag_t/speed_t are unsigned long (8 bytes) and NCCS=20 (72 bytes total). This caused a buffer overflow in tcgetattr and corrupted terminal state on restore. Replace the struct with a raw IntPtr buffer (128 bytes) since we only need to save and restore the blob opaquely — no individual fields are read. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The
unixandansidrivers were functionally near-identical on Unix, with theansidriver being a strict superset. This removes theunixdriver entirely and consolidates onansias the sole ANSI-based driver for all platforms, while adding configurable size detection to preserve the one advantage the unix driver had.Deleted (unix-driver-specific)
Drivers/UnixDriver/UnixComponentFactory.cs,UnixInput.cs,UnixInputProcessor.cs,UnixOutput.cs,IUnixInput.csTests/UnitTestsParallelizable/Drivers/Unix/andUnixDriver/Moved (shared infrastructure, still used by ansi driver)
UnixIOHelper.cs,UnixRawModeHelper.cs,UnixTerminalHelper.cs,SuspendHelper.cs,UnixClipboard.cs→Drivers/rootNew:
SizeDetectionModeconfig propertyControls how the ansi driver detects terminal size via
Driver.SizeDetection([ConfigurationProperty]):AnsiQuery(default) usesAnsiSizeMonitor— ANSICSI 18tescape-sequence queries, matching previous ansi-driver behavior.PollingusesSizeMonitorImplwithAnsiOutput.NativeSizeQuery— synchronousioctl(TIOCGWINSZ)on Unix /Console.WindowWidth/Heighton Windows.Driver.SizeDetectionfollows theDriver.Force16Colors[ConfigurationProperty]pattern;SizeDetectionModeis registered inSourceGenerationContextfor AOT.Size detection correctness fixes
AnsiOutputgains aNativeSizeQuerydelegate property;GetSize()calls it when set, enablingSizeMonitorImplto obtain real OS terminal dimensions inPollingmode.SizeMonitorImplnow initialises_lastSizefromconsoleOut.GetSize()in its constructor (previouslySize.Empty), so the firstPoll()is a no-op when the terminal size has not changed — eliminating a spuriousSizeChangedevent that was causing test failures.Registry changes
DriverRegistry.Names.UNIXconstant removed.GetDefaultDriver()returnsansion Unix/macOS.ApplicationImpl.Driver.csand all test references toNames.UNIX/UnixComponentFactoryupdated.Tests
SizeMonitorTests.csrewritten to reflect corrected first-poll semantics.AnsiComponentFactorySizeMonitorTests.csverifies: (1) injected monitor is returned directly, (2)AnsiQueryreturnsAnsiSizeMonitor, (3)PollingreturnsSizeMonitorImplwithNativeSizeQuerywired up, (4) end-to-end resize detection viaNativeSizeQuery.Documentation
docfx/docs/drivers.mdupdated:unixdriver removed from comparison table,ansishown as the Unix/macOS default, auto-selection section corrected, new Size Detection (ANSI Driver) section added documenting theDriver.SizeDetectionconfiguration property.Pull Request checklist:
CTRL-K-Dto automatically reformat your files before committing.dotnet testbefore commit///style comments)Original prompt
This section details on the original issue you should resolve
<issue_title>Remove
unixdriver; augmentansito optionally support polling size detection on Unix</issue_title><issue_description>## Summary
Remove the
unixdriver entirely and consolidate on theansidriver as the sole ANSI-based driver for all platforms. Augment theansidriver to optionally support synchronous (ioctl-based) size detection on Unix, controlled via a newConfigurationProperty.Rationale
A detailed comparison of the
unixandansidrivers reveals they are functionally near-identical on Unix, with theansidriver being a strict superset:What's Identical
InputProcessor:UnixInputProcessorandAnsiInputProcessorare functionally duplicate — same base class (InputProcessorImpl<char>), sameAnsiKeyConverter, sameProcess()body, sameInjectKeyDownEvent/InjectMouseEventimplementations.AnsiResponseParser<char>→AnsiKeyboardParser→AnsiMouseParser.UnixRawModeHelper(termios) on Unix.UnixIOHelper(poll/read/write) on Unix.OutputBase(dirty-cell iteration, ANSI sequence generation).UnixTerminalHelper.Suspend()→SuspendHelper(SIGTSTP).MouseInterpreter→MouseButtonClickTracker.Where the Ansi Driver Is Better
UnixInputowns terminal state (alt screen, cursor, mouse) — architectural smellAnsiOutputowns terminal state — cleaner separationUnixComponentFactoryhas no constructor paramsAnsiComponentFactoryaccepts mockAnsiInput,IOutput,ISizeMonitorAnsiOutput.GetLastBuffer()for test verificationdup()'d fd +FileStream+StreamWriterper callCSI_SetCursorPositionthrough normalWrite()pathEnableKittyKeyboard()/DisableKittyKeyboard()AnsiPlatformenum with well-defined no-op pathstcflushThe One Advantage of the Unix Driver: Synchronous Size Detection
The only functional advantage the Unix driver has is its
SizeMonitorImplusingioctl(TIOCGWINSZ)— a synchronous native syscall that gives immediate, reliable size information. The Ansi driver'sAnsiSizeMonitoruses async ANSI queries (ESC[18t→ESC[8;h;wt), which:This is the concern this issue addresses — making the
ansidriver support both strategies.Proposed Solution
1. Remove the Unix Driver
Delete the
Drivers/UnixDriver/directory entirely:UnixComponentFactory.csIUnixInput.cs,UnixInput.csUnixInputProcessor.csUnixOutput.csUnixIOHelper.cs— keep this (shared by Ansi driver too)UnixRawModeHelper.cs— keep this (shared by Ansi driver too)UnixTerminalHelper.cs— keep this (used byAnsiOutput.Suspend())SuspendHelper.cs— keep thisUnixClipboard.cs— keep this (used byDriverImpl.CreateClipboard())Remove
DriverRegistry.Names.UNIXregistration. UpdateGetDefaultDriver()to return"ansi"on Unix/macOS instead of"unix".2. Add
SizeDetectionModeConfigurationPropertyAdd a new configuration property to control which size detection strategy the Ansi driver uses:
Add the config property on the
Driverclass (which already holds global driver settings likeForce16Colors):The JSON config would be:
{ "Driver.SizeDetection": "AnsiQuery" }3. Update
AnsiComponentFactory.CreateSizeMonitor()Change the current type-based decision to a config-based one:...
unixdriver; augmentansito optionally support polling size detection on Unix #4820✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.