Skip to content

Use absolute positioning after OSC sequences#74

Open
seh wants to merge 1 commit intocharmbracelet:mainfrom
seh:use-abs-positioning-after-osc-seqs
Open

Use absolute positioning after OSC sequences#74
seh wants to merge 1 commit intocharmbracelet:mainfrom
seh:use-abs-positioning-after-osc-seqs

Conversation

@seh
Copy link

@seh seh commented Jan 27, 2026

Sending OSC (Operating System Command) sequences to terminals can induce inconsistency in the expected cursor position. When we write an OSC sequence to the terminal, it may move the cursor unpredictably, leaving ultraviolet's cached cursor position unknowingly incorrect.

To defend against this vulnerability, detect OSC sequences in the TerminalRenderer type's Write and WriteString methods, and, upon detecting such sequences, force the next cursor movement to use absolute positioning (CUP) rather than relative movements. Doing so ensures that we restore proper cursor synchronization after having pushed these OSC sequences through to the terminal.

The material change in behavior only applies when the tRelativeCursor flag is unset (typically in the so-called alternate screen buffer mode), where absolute cursor positioning is available but the consequent inconsistency can cause visible rendering artifacts (such as stale lines not being overwritten as intended).

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

@seh seh requested a review from aymanbagabas as a code owner January 27, 2026 18:54
@seh seh force-pushed the use-abs-positioning-after-osc-seqs branch from da0bcd5 to d0ffe9e Compare January 27, 2026 19:00
Sending OSC (Operating System Command) sequences to terminals can
induce inconsistency in the expected cursor position. When we write an
OSC sequence to the terminal, it may move the cursor unpredictably,
leaving "ultraviolet"'s cached cursor position unknowingly incorrect.

To defend against this vulnerability, detect OSC sequences in the
TerminalRenderer type's "Write" and "WriteString" methods, and, upon
detecting such sequences, force the next cursor movement to use
absolute positioning (CUP) rather than relative movements. Doing so
ensures that we restore proper cursor synchronization after having
pushed these OSC sequences through to the terminal.

The material change in behavior only applies when the
"tRelativeCursor" flag is unset (typically in the so-called alternate
screen buffer mode), where absolute cursor positioning is available
but the consequent inconsistency can cause visible rendering
artifacts (such as stale lines not being overwritten as intended).
@seh seh force-pushed the use-abs-positioning-after-osc-seqs branch from d0ffe9e to dee387f Compare January 27, 2026 19:06
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