Skip to content

Support HPR (CSI a) and VPR (CSI e) relative positioning #7

Closed

Description

@tony

Summary

Terminal._on_csi() in src/libvt/terminal.py (#2) has no dispatch branches for ECMA-48 HPR (CSI Ps a, Character Position Relative) or VPR (CSI Ps e, Line Position Relative), recording both as unhandled and leaving the cursor stationary ('AB' at (0, 2) instead of 'A B' at (1, 4)).

Reproduction

  1. Feed A, CSI 2 a, B, CSI 1 e on a fresh 8x3 DEFAULT_PROFILE terminal:
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=3, cols=8); vt.feed(b"A\x1b[2aB\x1b[1e"); print(vt.lines, vt.cursor)'

Expected

  • Under DEFAULT_PROFILE and XTERM_PROFILE, vt.lines starts with 'A B' and 0-based vt.cursor sits at (row=1, col=4, pending_wrap=False).
  • When Origin Mode DECOM (?6) is reset and the cursor starts inside DECLRMM or DECSTBM margins, HPR and VPR pass through those margins and clamp only at physical screen edges (cols - 1, rows - 1), unlike CUF and CUD.
  • When DECOM (?6h) is set, HPR and VPR advance from the current cell once and clamp at (bottom_margin, right_margin) without applying left_margin/top_margin a second time.
  • Under inner-pane TMUX_PROFILE, CSI a and CSI e remain ignored to match tmux input_csi_table (3.8).

Actual

('AB',) and Cursor(row=0, col=2, ...) across all profiles.

Environment
  • libvt: #2 (feat/v2-architecture, 0.1.0a0)
  • Python: 3.15.0 (unicodedata 17.0.0)
  • Reference tmux: 3.8a (tmux -f /dev/null)
  • OS: Linux x86_64

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • Pn of 0 or omitted defaults to 1, neither HPR nor VPR scrolls the screen, and both cancel pending_wrap (even when clipped at the right edge).
  • HPR and VPR never alias CUF/CUD when DECOM is reset (which would wrongly stop at right_margin/bottom_margin), and never pass physical cur_col + n / cur_row + n into HPA/VPA when DECOM is set (which would double-add left_margin/top_margin).
  • codec.py (explain) disassembles CSI Ps a (HPR) and CSI Ps e (VPR) alongside HPA (CSI Ps ` / CSI Ps G) and VPA (CSI Ps d).

Intent (non-binding)

  • Compute max_col = right if decom else scr.cols - 1 and max_row = bottom if decom else scr.rows - 1 (clamping into left..right / top..bottom when decom is set), mirroring Ghostty cursorColRelative and cursorRowRelative (vt-1.0.1) and xterm charproc.c (xterm-412).
  • Gate HPR/VPR execution off when Profile emulates an inner tmux pane (tmux_version is not None).

Not doing

  • Changing CUF (CSI C) or CUD (CSI B) margin-stop rules.

References

Activity

  1. added
    bug
    on Nov 22, 2026
  2. tony commented on Nov 23, 2026

    @tony
    MemberAuthor

    Resolved in #2 (0c7ee41).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions