Repository navigation
Terminal: support SGR 2 (faint) and modified special keys - #2903
Conversation
9d27631 to
7d40c21
Compare
|
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:
Unit tests: StyleTest (dim) and VT100EmulatorTest (SGR 2 and 22, and the modified special keys). |
1f95299 to
232c47d
Compare
There was a problem hiding this comment.
🟡 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
akurtakov
left a comment
There was a problem hiding this comment.
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:
modifiedSpecialKeyshould be a table instead of the switch, with SWT's constants (SWT.ARROW_UP,SWT.F5, …) instead of the hex codes: every key isCSI 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 useRGB.blend(background, 0.5)from SWT 3.136 (addingorg.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 newColoron 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
left a comment
There was a problem hiding this comment.
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.
|
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? |
…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.
… and faint colours are cached per colour and background (cleared at 1024 for 24-bit colour). As reviewed for eclipse-platform/eclipse.platform#2903.

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.