Skip to content

Fixed(terminal-emulator): Make VPA, VPR and HPA respect origin mode - #5355

Open
matthematics1137 wants to merge 1 commit into
termux:masterfrom
matthematics1137:fix-origin-mode-hpa-vpa-vpr
Open

matthematics1137 wants to merge 1 commit into
termux:masterfrom
matthematics1137:fix-origin-mode-hpa-vpa-vpr

Conversation

@matthematics1137

Copy link
Copy Markdown

These bugs show with origin mode (DECOM, CSI ? 6 h) on and a top margin
below the first line:

  • VPA (CSI Pn d) ignores origin mode. It counts from the first line of
    the screen and is not limited to the scroll region.
  • VPR (CSI Pn e) and HPA (CSI Pn `) pass the absolute cursor
    row to setCursorPosition(). That function takes a row relative to the top
    margin in origin mode, so the top margin is added twice and the cursor jumps
    down. HPA even moves the cursor to another row.

To reproduce:

printf '\033[2J\033[3;5r\033[?6h\033[1dV\033[1;1H\033[3`H\033[?6l\033[r\033[8;1H'

In xterm, V and H both land on line 3, the first line of the region. In
Termux, V lands on line 1 and H on line 5.

After this change, VPA and VPR count from the top margin and stop at the
margins in origin mode, and HPA changes only the column. This matches xterm
(CursorSet() with the origin flag for VPA, VPR and HPA). tmux does the same
for VPA and HPA.

Test: CursorAndScreenTest.testCursorPositionWithOriginModeAndTopMargin.

With origin mode (DECOM) on and a top margin below the first line:

- VPA (`CSI Pn d`) ignored origin mode: it counted from the first line of
  the screen and was not limited to the scroll region.
- VPR (`CSI Pn e`) and HPA (`CSI Pn \``) passed the absolute cursor row to
  setCursorPosition(), which takes a row relative to the top margin in
  origin mode, so the top margin was added a second time and the cursor
  jumped down (HPA moved it to another row altogether).

VPA and VPR now count from the top margin and stop at the margins in origin
mode, and HPA changes only the column, as in xterm (CursorSet). tmux
does the same for VPA and HPA.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

1 participant