-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addon that refreshes xterm upon webfont load
- Loading branch information
1 parent
989f587
commit 0c8c85e
Showing
5 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "xterm.webfont", | ||
"main": "webfont.js", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; | ||
} |