Skip to content

wolfterm: fix CSI erase modes and SGR on Windows - #1390

Merged
philljj merged 4 commits into
wolfSSL:masterfrom
ejohnstown:wolfterm-csi
Dec 2, 2026
Merged

philljj merged 4 commits into
wolfSSL:masterfrom
ejohnstown:wolfterm-csi

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

The Windows console translator handles ED and EL modes 0-2 as ECMA-48
does, erases in the current attributes, and parses every SGR argument
in one sequence, extended colours included.

  • ED clears from buffer row 0, the rows CSI H addresses, so no old
    text is left where the cursor can go
  • Erased cells take the current attributes, not the old background
  • ESC[1;31m keeps the bold; SGR 0 resets mid-sequence; SGR 39 restores
    the default foreground
  • SGR 38 and 48 map 5;N and 2;R;G;B to the nearest console colour
  • api-test checks the cells and attributes on an off-screen buffer

Issue: F-10556, F-11663, F-12549, F-15506

@ejohnstown

Copy link
Copy Markdown
Contributor Author

@claude review

Comment thread src/wolfterm.c Resolved
Comment thread src/wolfterm.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #1390

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@philljj

philljj commented Dec 2, 2026

Copy link
Copy Markdown

@claude review

Comment thread src/wolfterm.c Resolved
Comment thread src/wolfterm.c Resolved
Comment thread src/wolfterm.c Resolved
@philljj philljj assigned ejohnstown and unassigned wolfSSL-Bot Dec 2, 2026

@philljj philljj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just a few small nits

The Windows console translator handles ED and EL modes as ECMA-48 does:
an omitted mode is 0, mode 0 erases from the cursor to the end, mode 1
from the start through the cursor cell, and mode 2 the whole display or
line. Mode 1J now clears the rows above the cursor too.

- ED 0-2 take the display as the whole buffer, the rows CSI H
  addresses, so no old text is left where the cursor can go
- Erased cells take the current attributes, so an old background
  colour does not survive the erase
- wolfSSH_ClearScreen() wraps at the buffer width, not the maximum
  window width

Issue: F-10556, F-12549
doDisplayAttributes() starts from the current console attributes,
applies each SGR argument to that value in order, and sets the result
once, so ESC[1;31m keeps the bold. SGR 0 resets to the default
attributes mid-sequence.

- SGR 25 (blink off) is a no-op; there is no blink to turn off
- SGR 39 restores the default foreground colour and keeps the bold

Issue: F-11663, F-15506
test_wolfSSH_ConvertConsole_csi() runs ED, EL and SGR sequences against
an off-screen console buffer and reads back the cells and attributes.
It returns early when no console is attached.

- ED 0-2 run again with the window scrolled down, with the cursor
  inside and below it, and with 2J before and after CSI H
- Erased cells are checked for the current attributes
- SGR 39 is checked with and without bold

Issue: F-10556, F-12549, F-11663, F-15506
doDisplayAttributes() takes the 5;N or 2;R;G;B after SGR 38 or 48 as
one colour and sets the nearest console colour, rather than reading
each sub-parameter as an SGR code of its own.

- Indexes 0-15 map directly; the 6x6x6 cube, the grey ramp and RGB go
  to the nearest of the 16 console colours
- An incomplete colour is skipped and leaves the attributes alone
- api-test checks indexed, RGB, background and incomplete colours
@philljj
philljj merged commit b3c551d into wolfSSL:master Dec 2, 2026
222 checks passed
@ejohnstown
ejohnstown deleted the wolfterm-csi branch December 2, 2026 22:20
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.

4 participants