Skip to content

Commit

Permalink
Addon that refreshes xterm upon webfont load
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwoo committed Apr 4, 2018
1 parent 989f587 commit 0c8c85e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
"webpack": "gulp webpack",
"watch": "gulp watch"
},
"dependencies": {}
"dependencies": {
"fontfaceobserver": "*"
}
}
5 changes: 5 additions & 0 deletions src/addons/webfont/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "xterm.webfont",
"main": "webfont.js",
"private": true
}
11 changes: 11 additions & 0 deletions src/addons/webfont/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"rootDir": ".",
"outDir": "../../../lib/addons/webfont/",
"sourceMap": true,
"removeComments": true,
"declaration": true
}
}
26 changes: 26 additions & 0 deletions src/addons/webfont/webfont.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference path="../../../typings/xterm.d.ts"/>

import { Terminal } from 'xterm';
const FontFaceObserver = require('fontfaceobserver')

const loadedFonts = {}

export function apply(terminalConstructor: typeof Terminal): void {
const oldSetup = (<any>terminalConstructor.prototype)._setup;

(<any>terminalConstructor.prototype)._setup = function (): void {
const originalFont = this.options.fontFamily;
if (loadedFonts[originalFont]) return oldSetup.call(this);
delete this.options.fontFamily;
oldSetup.call(this);

const regular = new FontFaceObserver(originalFont).load();
const bold = new FontFaceObserver(originalFont, { weight: 'bold' }).load();

regular.constructor.all([regular, bold]).then(() => {
loadedFonts[originalFont] = true;
this.setOption('fontFamily', originalFont);
this.refresh(0, this.rows - 1);
});
};
}

0 comments on commit 0c8c85e

Please sign in to comment.