Skip to content

Commit e9b0593

Browse files
authored
Merge pull request #4525 from Tyriar/4161_dim
Don't apply dim to background color
2 parents a0493a6 + d5c47ec commit e9b0593

File tree

8 files changed

+61
-17
lines changed

8 files changed

+61
-17
lines changed

addons/xterm-addon-canvas/src/CanvasAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, ISelectionService, IThemeService } from 'browser/services/Services';
7-
import { IColorSet, ITerminal } from 'browser/Types';
7+
import { ITerminal } from 'browser/Types';
88
import { CanvasRenderer } from './CanvasRenderer';
99
import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
1010
import { ITerminalAddon, Terminal } from 'xterm';

addons/xterm-addon-canvas/src/TextRenderLayer.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ export class TextRenderLayer extends BaseRenderLayer {
188188
nextFillStyle = this._themeService.colors.ansi[cell.getBgColor()].css;
189189
}
190190

191-
// Apply dim to the background, this is relatively slow as the CSS is re-parsed but dim is
192-
// rarely used
193-
if (nextFillStyle && cell.isDim()) {
194-
nextFillStyle = color.multiplyOpacity(css.toColor(nextFillStyle), 0.5).css;
195-
}
196-
197191
// Get any decoration foreground/background overrides, this must be fetched before the early
198192
// exist but applied after inverse
199193
let isTop = false;

addons/xterm-addon-webgl/src/RectangleRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class RectangleRenderer extends Disposable {
270270
$r = (($rgba >> 24) & 0xFF) / 255;
271271
$g = (($rgba >> 16) & 0xFF) / 255;
272272
$b = (($rgba >> 8 ) & 0xFF) / 255;
273-
$a = (!$isDefault && bg & BgFlags.DIM) ? DIM_OPACITY : 1;
273+
$a = 1;
274274

275275
this._addRectangle(vertices.attributes, offset, $x1, $y1, (endX - startX) * this._dimensions.device.cell.width, this._dimensions.device.cell.height, $r, $g, $b, $a);
276276
}

addons/xterm-addon-webgl/test/WebglRenderer.api.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,55 @@ describe('WebGL Renderer Integration Tests', async () => {
364364
}
365365
});
366366

367+
itWebgl('foreground 16-255 dim', async () => {
368+
let data = '';
369+
for (let y = 0; y < 240 / 16; y++) {
370+
for (let x = 0; x < 16; x++) {
371+
data += `\\x1b[2;38;5;${16 + y * 16 + x}m█\x1b[0m`;
372+
}
373+
data += '\\r\\n';
374+
}
375+
await writeSync(page, data);
376+
for (let y = 0; y < 240 / 16; y++) {
377+
for (let x = 0; x < 16; x++) {
378+
const cssColor = COLORS_16_TO_255[y * 16 + x];
379+
const r = parseInt(cssColor.slice(1, 3), 16);
380+
const g = parseInt(cssColor.slice(3, 5), 16);
381+
const b = parseInt(cssColor.slice(5, 7), 16);
382+
// It's difficult to assert the exact color due to rounding, just ensure the color differs
383+
// to the regular color
384+
await pollFor(page, async () => {
385+
const c = await getCellColor(x + 1, y + 1);
386+
return (
387+
(c[0] === 0 || c[0] !== r) &&
388+
(c[1] === 0 || c[1] !== g) &&
389+
(c[2] === 0 || c[2] !== b)
390+
);
391+
}, true);
392+
}
393+
}
394+
});
395+
396+
itWebgl('background 16-255 dim', async () => {
397+
let data = '';
398+
for (let y = 0; y < 240 / 16; y++) {
399+
for (let x = 0; x < 16; x++) {
400+
data += `\\x1b[2;48;5;${16 + y * 16 + x}m \\x1b[0m`;
401+
}
402+
data += '\\r\\n';
403+
}
404+
await writeSync(page, data);
405+
for (let y = 0; y < 240 / 16; y++) {
406+
for (let x = 0; x < 16; x++) {
407+
const cssColor = COLORS_16_TO_255[y * 16 + x];
408+
const r = parseInt(cssColor.slice(1, 3), 16);
409+
const g = parseInt(cssColor.slice(3, 5), 16);
410+
const b = parseInt(cssColor.slice(5, 7), 16);
411+
await pollFor(page, () => getCellColor(x + 1, y + 1), [r, g, b, 255]);
412+
}
413+
}
414+
});
415+
367416
itWebgl('foreground true color red', async () => {
368417
let data = '';
369418
for (let y = 0; y < 16; y++) {

css/xterm.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@
161161
}
162162

163163
.xterm-dim {
164-
opacity: 0.5;
164+
/* Dim should not apply to background, so the opacity of the foreground color is applied
165+
* explicitly in the generated class and reset to 1 here */
166+
opacity: 1 !important;
165167
}
166168

167169
.xterm-underline-1 { text-decoration: underline; }

src/browser/renderer/dom/DomRenderer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55

6-
import { BOLD_CLASS, CURSOR_BLINK_CLASS, CURSOR_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DomRendererRowFactory, ITALIC_CLASS } from 'browser/renderer/dom/DomRendererRowFactory';
6+
import { BOLD_CLASS, CURSOR_BLINK_CLASS, CURSOR_CLASS, CURSOR_STYLE_BAR_CLASS, CURSOR_STYLE_BLOCK_CLASS, CURSOR_STYLE_UNDERLINE_CLASS, DIM_CLASS, DomRendererRowFactory, ITALIC_CLASS } from 'browser/renderer/dom/DomRendererRowFactory';
77
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/shared/Constants';
88
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
99
import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
@@ -149,6 +149,10 @@ export class DomRenderer extends Disposable implements IRenderer {
149149
` font-family: ${this._optionsService.rawOptions.fontFamily};` +
150150
` font-size: ${this._optionsService.rawOptions.fontSize}px;` +
151151
`}`;
152+
styles +=
153+
`${this._terminalSelector} .${ROW_CONTAINER_CLASS} .xterm-dim {` +
154+
` color: ${color.multiplyOpacity(colors.foreground, 0.5).css};` +
155+
`}`;
152156
// Text styles
153157
styles +=
154158
`${this._terminalSelector} span:not(.${BOLD_CLASS}) {` +
@@ -224,10 +228,12 @@ export class DomRenderer extends Disposable implements IRenderer {
224228
for (const [i, c] of colors.ansi.entries()) {
225229
styles +=
226230
`${this._terminalSelector} .${FG_CLASS_PREFIX}${i} { color: ${c.css}; }` +
231+
`${this._terminalSelector} .${FG_CLASS_PREFIX}${i}.${DIM_CLASS} { color: ${color.multiplyOpacity(c, 0.5).css}; }` +
227232
`${this._terminalSelector} .${BG_CLASS_PREFIX}${i} { background-color: ${c.css}; }`;
228233
}
229234
styles +=
230235
`${this._terminalSelector} .${FG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { color: ${color.opaque(colors.background).css}; }` +
236+
`${this._terminalSelector} .${FG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR}.${DIM_CLASS} { color: ${color.multiplyOpacity(color.opaque(colors.background), 0.5).css}; }` +
231237
`${this._terminalSelector} .${BG_CLASS_PREFIX}${INVERTED_DEFAULT_COLOR} { background-color: ${colors.foreground.css}; }`;
232238

233239
this._themeStyleElement.textContent = styles;

src/browser/renderer/dom/DomRendererRowFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { NULL_CELL_CODE, WHITESPACE_CELL_CHAR, Attributes } from 'common/buffer/
99
import { CellData } from 'common/buffer/CellData';
1010
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
1111
import { color, rgba } from 'common/Color';
12-
import { IColorSet, ReadonlyColorSet } from 'browser/Types';
1312
import { ICharacterJoinerService, ICoreBrowserService, IThemeService } from 'browser/services/Services';
1413
import { JoinedCellData } from 'browser/services/CharacterJoinerService';
1514
import { excludeFromContrastRatioDemands } from 'browser/renderer/shared/RendererUtils';

src/browser/renderer/shared/TextureAtlas.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ export class TextureAtlas implements ITextureAtlas {
304304
break;
305305
}
306306

307-
if (dim) {
308-
// Blend here instead of using opacity because transparent colors mess with clipping the
309-
// glyph's bounding box
310-
result = color.blend(this._config.colors.background, color.multiplyOpacity(result, DIM_OPACITY));
311-
}
312-
313307
return result;
314308
}
315309

0 commit comments

Comments
 (0)