Skip to content

Commit 33bba35

Browse files
authored
Merge pull request #4291 from jerch/fix_4223
fix demo in epiphany
2 parents c7660fb + d2298d8 commit 33bba35

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
373373
} else {
374374
glyph = this._charAtlas.getRasterizedGlyph(cell.getCode() || WHITESPACE_CELL_CODE, this._cellColorResolver.result.bg, this._cellColorResolver.result.fg, this._cellColorResolver.result.ext);
375375
}
376+
if (!glyph.size.x || !glyph.size.y) {
377+
return;
378+
}
376379
this._ctx.save();
377380
this._clipRow(y);
378381
// Draw the image, use the bitmap if it's available

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ export class TextRenderLayer extends BaseRenderLayer {
9595
continue;
9696
}
9797

98+
// exit early for NULL and SP
99+
const code = cell.getCode();
100+
if (code === 0 || code === 32) {
101+
continue;
102+
}
103+
98104
// Process any joined character ranges as needed. Because of how the
99105
// ranges are produced, we know that they are valid for the characters
100106
// and attributes of our input.

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { EventEmitter, forwardEvent } from 'common/EventEmitter';
99
import { Disposable, toDisposable } from 'common/Lifecycle';
1010
import { getSafariVersion, isSafari } from 'common/Platform';
1111
import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
12-
import { ICoreTerminal } from 'common/Types';
1312
import { ITerminalAddon, Terminal } from 'xterm';
1413
import { WebglRenderer } from './WebglRenderer';
1514

@@ -29,14 +28,13 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
2928
constructor(
3029
private _preserveDrawingBuffer?: boolean
3130
) {
32-
super();
33-
}
34-
35-
public activate(terminal: Terminal): void {
3631
if (isSafari && getSafariVersion() < 16) {
3732
throw new Error('Webgl2 is only supported on Safari 16 and above');
3833
}
34+
super();
35+
}
3936

37+
public activate(terminal: Terminal): void {
4038
const core = (terminal as any)._core as ITerminal;
4139
if (!terminal.element) {
4240
this.register(core.onWillOpen(() => this.activate(terminal)));

demo/client.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ function createTerminal(): void {
250250
addons.serialize.instance = new SerializeAddon();
251251
addons.fit.instance = new FitAddon();
252252
addons.unicode11.instance = new Unicode11Addon();
253-
addons.webgl.instance = new WebglAddon();
253+
try { // try to start with webgl renderer (might throw on older safari/webkit)
254+
addons.webgl.instance = new WebglAddon();
255+
} catch (e) {
256+
console.warn(e);
257+
}
254258
addons['web-links'].instance = new WebLinksAddon();
255259
typedTerm.loadAddon(addons.fit.instance);
256260
typedTerm.loadAddon(addons.search.instance);
@@ -273,22 +277,26 @@ function createTerminal(): void {
273277
socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/terminals/';
274278

275279
addons.fit.instance!.fit();
276-
typedTerm.loadAddon(addons.webgl.instance);
277-
setTimeout(() => {
278-
if (addons.webgl.instance !== undefined) {
280+
281+
if (addons.webgl.instance) {
282+
try {
283+
typedTerm.loadAddon(addons.webgl.instance);
284+
term.open(terminalContainer);
279285
setTextureAtlas(addons.webgl.instance.textureAtlas);
280286
addons.webgl.instance.onChangeTextureAtlas(e => setTextureAtlas(e));
281287
addons.webgl.instance.onAddTextureAtlasCanvas(e => appendTextureAtlas(e));
282288
addons.webgl.instance.onRemoveTextureAtlasCanvas(e => removeTextureAtlas(e));
289+
} catch (e) {
290+
console.warn('error during loading webgl addon:', e);
291+
addons.webgl.instance.dispose();
292+
addons.webgl.instance = undefined;
283293
}
284-
}, 0);
285-
286-
try { // try-catch to allow the demo to load if webgl is not supported
287-
term.open(terminalContainer);
288294
}
289-
catch {
290-
addons.webgl.instance = undefined;
295+
if (!typedTerm.element) {
296+
// webgl loading failed for some reason, attach with DOM renderer
297+
term.open(terminalContainer);
291298
}
299+
292300
term.focus();
293301

294302
addDomListener(paddingElement, 'change', setPadding);

0 commit comments

Comments
 (0)