Fix origin-mode cursor positioning#6
Open
jchristn wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes DEC origin-mode cursor positioning semantics when a scroll region is active, aligning CUP/HVP, VPA, and DECSTBM behavior with expected VT/xterm semantics and adding regression tests to prevent future regressions.
Changes:
- Added a shared origin-mode row translation helper and applied it to
CUP/HVPandVPA. - Updated
DECSTBMhandling to home the cursor after setting the scroll region, and adjusted origin-mode enable/disable homing behavior. - Added regression tests covering origin-relative addressing and cursor homing with scroll regions; added a FIXES.md note describing the behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/XTerm.NET/InputHandler.cs | Implements origin-mode row translation and cursor homing changes for scroll regions and origin mode toggles. |
| src/XTerm.NET.Tests/InputHandlerTests.cs | Adds regression tests for origin-relative CUP/HVP, origin-relative VPA, and scroll-region cursor homing. |
| src/XTerm.NET.Tests/ModeHandlingTests.cs | Adds regression test ensuring enabling origin mode homes to the top margin when a scroll region is set. |
| FIXES.md | Documents the behavioral fixes and provides minimal reproductions and validation notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1280
to
+1288
| private int GetAbsoluteCursorRow(int row) | ||
| { | ||
| if (_terminal.OriginMode) | ||
| { | ||
| return Math.Clamp(_buffer.ScrollTop + row, _buffer.ScrollTop, _buffer.ScrollBottom); | ||
| } | ||
|
|
||
| return Math.Clamp(row, 0, _terminal.Rows - 1); | ||
| } |
Comment on lines
+5
to
+6
| This branch fixes DEC origin-mode cursor positioning with scroll regions. These changes are core terminal emulator behavior and are not specific to Termrig, Avalonia, ConPTY, or any host renderer. | ||
|
|
Comment on lines
+39
to
+41
| var terminal = new Terminal(new TerminalOptions { Cols = 20, Rows = 5 }); | ||
| var handler = new InputHandler(terminal); | ||
| terminal.Buffer.SetCursor(10, 10); |
Comment on lines
+98
to
+112
| ## Validation | ||
|
|
||
| Run from this repository root: | ||
|
|
||
| ```powershell | ||
| dotnet test src/XTerm.NET.slnx --no-restore | ||
| ``` | ||
|
|
||
| Result on this branch: | ||
|
|
||
| ```text | ||
| Passed: 589 | ||
| Failed: 0 | ||
| Skipped: 0 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes DEC origin-mode cursor positioning with scroll regions:
DECSTBM/CSI t;b rnow moves the cursor to home after setting the scroll region.CUP/HVP(CSI row;col H/f) now treat row coordinates as relative to the scroll region whenDECOM/ origin mode is enabled.VPA/CSI row dnow applies the same origin-mode row translation.Why
Terminal UIs that reserve a bottom prompt/status row commonly set a scroll region for the output area and use origin-relative cursor addressing. Without these semantics, content can be written to the wrong absolute rows and preserved into scrollback incorrectly.
This is a core emulator behavior fix only. It intentionally does not include any host-rendering, PTY, ConPTY, or Termrig-specific compatibility shims.
Validation
dotnet test src\XTerm.NET.slnx --no-restoreThe test run still reports the existing compiler warnings about
EscapeSequenceParser.DcsandTerminal.HyperlinkChanged; this PR did not introduce new warnings.