Skip to content

Terminal: support SGR 2 (faint) and modified special keys - #2903

Merged
akurtakov merged 1 commit into
eclipse-platform:masterfrom
insjang:sgr-dim-keys
Nov 5, 2026
Merged

akurtakov merged 1 commit into
eclipse-platform:masterfrom
insjang:sgr-dim-keys

Conversation

@insjang

@insjang insjang commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

SGR 2 asks for faint text. The attribute was unknown and logged as unsupported, so programs that use it for secondary text - help lines, timestamps, completed items - showed it at full strength, and SGR 22, which turns both bold and faint off, only turned off bold. TerminalStyle gains a dim attribute (an API addition, hence the version bump), and the style map draws a faint colour half way to the background, which works for any colour rather than only the sixteen named ones.

Special keys were sent only when no modifier was held, so a program was never told about Ctrl+End, Shift+Home, Alt+Left, Ctrl+F5 and the rest. xterm spells a modified special key as the plain one with the modifier as a parameter (2 shift, 3 alt, 5 control, and their sums): the arrows, Home, End and F1-F4 as CSI 1 ; m X, the others as CSI n ; m ~. Keys the existing switch already answered never reach this and keep working as before.

@insjang insjang changed the title Terminal: support SGR 2 (faint), and send special keys held with a mo… Terminal: support SGR 2 (faint) and modified special keys Sep 3, 2026
@insjang
insjang force-pushed the sgr-dim-keys branch 2 times, most recently from 9d27631 to 7d40c21 Compare September 30, 2026 08:06
@insjang

insjang commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on master (with #2894 in), one commit, 88c7808, the three earlier commits squashed; all terminal tests pass. The only conflict was the bundle version: this PR adds API to TerminalStyle (@SInCE 1.2), so the bundle goes to 1.2.0 rather than master's 1.1.300.

How to test, in a runtime Eclipse with this org.eclipse.terminal.control, Terminal view, local shell:

  1. Faint text: printf 'normal \e[2mfaint\e[22m normal\n'
    Expected: "faint" is drawn in a colour half way to the background, and the text after SGR 22 is normal again. Before this change it was full strength and an "unsupported" message went to the log.
  2. Faint on a colour: printf '\e[31mred \e[2mfaint red\e[0m\n'
    Expected: a dimmer red, not grey.
  3. Bold and faint: printf '\e[1mbold \e[2mboth\e[22m none\n'
    Expected: SGR 22 turns both off.
  4. Modified special keys: cat -v, then press Ctrl+Right, Shift+Home, Alt+Up, Ctrl+F5, Shift+PageUp.
    Expected: ^[[1;5C, ^[[1;2H, ^[[1;3A, ^[[15;5~, ^[[5;2~. Before this change nothing was sent for them. Ctrl+C to leave cat.
  5. In a shell or editor that uses them: in bash, Ctrl+Left and Ctrl+Right move by word; in vim or nano, Shift+arrows or Ctrl+Home/End work as they do in xterm.
  6. Keys without a modifier and the keys the terminal already handled (plain arrows, Ctrl+C, the view's own shortcuts) work as before.

Unit tests: StyleTest (dim) and VT100EmulatorTest (SGR 2 and 22, and the modified special keys).

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   39m 40s ⏱️ + 4m 9s
 4 985 tests +3   4 963 ✅ +3   22 💤 ±0  0 ❌ ±0 
12 846 runs  +9  12 692 ✅ +9  154 💤 ±0  0 ❌ ±0 

Results for commit 172bccd. ± Comparison against base commit e85e581.

♻️ This comment has been updated with latest results.

Copilot AI 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.

🟡 Changes recommended

Unresolved regressions send combined Command-modified arrow keys remotely, intercept existing Alt shortcuts, and incorrectly clear faint styling for SGR 21.

3 open issues
What changed in this PR

This PR adds faint-text rendering and xterm-style modified special-key sequences to Eclipse’s terminal, extending its styling API and keyboard handling.

Changes:

  • Adds a dim attribute, faint-colour rendering, and SGR intensity handling.
  • Encodes modified navigation and function keys as terminal escape sequences.
  • Adds regression tests and increments bundle and exported-package versions.
File Description
terminal/​tests/​org.eclipse.terminal.test/​src/​org/​eclipse/​terminal/​model/​StyleTest.java Tests dim-state changes and style reuse.
terminal/​tests/​org.eclipse.terminal.test/​src/​org/​eclipse/​terminal/​internal/​emulator/​VT100EmulatorTest.java Tests faint attributes and modified-key encoding.
terminal/​bundles/​org.eclipse.terminal.control/​src/​org/​eclipse/​terminal/​model/​TerminalStyle.java Adds dim state while preserving existing style attributes.
terminal/​bundles/​org.eclipse.terminal.control/​src/​org/​eclipse/​terminal/​internal/​textcanvas/​StyleMap.java Blends faint foreground colours toward the background.
terminal/​bundles/​org.eclipse.terminal.control/​src/​org/​eclipse/​terminal/​internal/​emulator/​VT100TerminalControl.java Adds modified special-key encoding and dispatch.
terminal/​bundles/​org.eclipse.terminal.control/​src/​org/​eclipse/​terminal/​internal/​emulator/​VT100Emulator.java Handles SGR 2 and updates intensity resets.
terminal/​bundles/​org.eclipse.terminal.control/​META-INF/​MANIFEST.MF Increments versions for the styling API addition.

Review effort: Balanced

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the terminal’s faint-text rendering and modified special-key changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@akurtakov akurtakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick fixes. Tested in a runtime: with the terminal focused, Ctrl+F7 opens the view switcher and Alt+Up maximizes the view again, so Eclipse's bindings win over the new sequences, and the tests cover Cmd and SGR 21. Two more changes, please:

  • modifiedSpecialKey should be a table instead of the switch, with SWT's constants (SWT.ARROW_UP, SWT.F5, …) instead of the hex codes: every key is CSI number ; modifier final, e.g. Map.entry(SWT.F5, new XtermKey(15, '~')), so the method shrinks to a lookup and the test can loop over the map. The code is inline.
  • StyleMap.dimmed() should use RGB.blend(background, 0.5) from SWT 3.136 (adding org.eclipse.swt;bundle-version="[3.136.0,4.0.0)" to the manifest, as master did for DiffColors and BreadcrumbViewer in 164c81a) instead of its own formula, and cache the blended colours, as a faint colour is now a new Color on every call.

…difier

SGR 2 asks for faint text. The attribute was unknown and logged as
unsupported, so programs that use it for secondary text - help lines,
timestamps, completed items - showed it at full strength, and SGR 22,
which turns both bold and faint off, only turned off bold. TerminalStyle
gains a dim attribute (an API addition, hence the version bump), and
the style map draws a faint colour half way to the background with
SWT's RGB.blend, which works for any colour rather than only the sixteen
named ones. Blended colours are cached per colour and background; a
program in 24-bit colour could ask for any number of them, so the cache
starts over at 1024 entries. RGB.blend rounds, so a channel may differ
by one from a plain average. SGR 21 stays apart from 22: ECMA-48 makes
it double underline, not normal intensity, so it takes bold off as
before and leaves faint alone.

Special keys were sent only when no modifier was held, so a program was
never told about Ctrl+End, Shift+Home, Alt+Left, Ctrl+F5 and the rest.
xterm spells a modified special key as the plain one with the modifier
as a parameter (2 shift, 3 alt, 5 control, and their sums): the arrows,
Home, End and F1-F4 as CSI 1 ; m X, the others as CSI n ; m ~. A table
keyed by SWT's key constants holds each key's number and final
character. Keys the existing switch in keyPressed already answered never
reach this and keep working as before. A key Eclipse has a binding for
stays with Eclipse, as Alt+Right (Quick Access) and Alt+Up (Maximize)
bound in this terminal do, and so does any combination with the Mac's
Cmd, which xterm has no spelling for.

TerminalStyle.isDim() and setDim() are new API: the bundle goes to 1.2.0 and the
org.eclipse.terminal.model export to 1.1.0. RGB.blend is new in SWT 3.136, so the
bundle now requires org.eclipse.swt [3.136.0,4.0.0). VT100TerminalControl.modifiedSpecialKey
is public, as the test bundle calls it across the bundle boundary.

@akurtakov akurtakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, both done as asked: the table with SWT's constants reads much better and the test now loops over every key and modifier, and faint colours come from RGB.blend and are cached. Good to merge once CI is green.

@insjang

insjang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The three red checks all come from org.eclipse.tips.tests TipImageURLTest, which downloads dummy.png from github.com; the terminal tests pass, and the same test passed on master e85e581 today. Could you re-run the failed jobs?

@akurtakov
akurtakov merged commit 8ddb1eb into eclipse-platform:master Nov 5, 2026
20 of 22 checks passed
insjang added a commit to insjang/eclipse-modern-terminal that referenced this pull request Nov 7, 2026
…md combinations stay in Eclipse, and a modified special key Eclipse has a binding for (Alt+Right Quick Access, Alt+Up Maximize) is not sent. As reviewed for eclipse-platform/eclipse.platform#2903.
insjang added a commit to insjang/eclipse-modern-terminal that referenced this pull request Nov 7, 2026
… and faint colours are cached per colour and background (cleared at 1024 for 24-bit colour). As reviewed for eclipse-platform/eclipse.platform#2903.
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.

3 participants