Skip to content

Commit

Permalink
Support opaque inverse background in webgl, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Nov 25, 2019
1 parent ef05a6a commit 89b4baf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 18 additions & 4 deletions addons/xterm-addon-webgl/src/WebglRenderer.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,22 @@ describe('WebGL Renderer Integration Tests', function(): void {
await pollFor(page, () => getCellColor(8, 2), [64, 64, 64, 255]);
});
});

describe('allowTransparency', async () => {
before(async () => setupBrowser({ rendererType: 'dom', allowTransparency: true}));
after(async () => browser.close());
beforeEach(async () => page.evaluate(`window.term.reset()`));
it('transparent background inverse', async () => {
const theme: ITheme = {
background: '#ff000080'
};
await page.evaluate(`window.term.setOption('theme', ${JSON.stringify(theme)});`);
const data = `\\x1b[7m█\x1b[0m`;
await writeSync(data);
// Inverse background should be opaque
await pollFor(page, () => getCellColor(1, 1), [255, 0, 0, 255]);
});
});
});

async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
Expand Down Expand Up @@ -732,17 +748,15 @@ async function getCellColor(col: number, row: number): Promise<number[]> {
return await page.evaluate(`Array.from(window.result)`);
}

async function setupBrowser(): Promise<void> {
async function setupBrowser(options: ITerminalOptions = { rendererType: 'dom' }): Promise<void> {
browser = await puppeteer.launch({
headless: process.argv.indexOf('--headless') !== -1,
args: [`--window-size=${width},${height}`, `--no-sandbox`]
});
page = (await browser.pages())[0];
await page.setViewport({ width, height });
await page.goto(APP);
await openTerminal({
rendererType: 'dom'
});
await openTerminal(options);
await page.evaluate(`
window.addon = new WebglAddon(true);
window.term.loadAddon(window.addon);
Expand Down
7 changes: 6 additions & 1 deletion addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ export class WebglCharAtlas implements IDisposable {
case Attributes.CM_DEFAULT:
default:
if (inverse) {
return this._config.colors.background.css;
const bg = this._config.colors.background.css;
if (bg.length === 9) {
// Remove bg alpha channel if present
return bg.substr(0, 7);
}
return bg;
}
return this._config.colors.foreground.css;
}
Expand Down

0 comments on commit 89b4baf

Please sign in to comment.