Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon that refreshes xterm upon webfont load #1368

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions demo/webfont/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,700" rel="stylesheet">
<link rel="stylesheet" href="../../build/xterm.css" />
<script src="../../build/xterm.js"></script>
<script src="../../build/addons/webfont/webfont.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fontfaceobserver/2.0.13/fontfaceobserver.standalone.js"></script>
</head>

<body>
<div id="term"></div>

<script>
Terminal.applyAddon(webfont)
const term = new Terminal({ fontFamily: 'Roboto Mono', lineHeight: 0.9, fontSize: 15 })
term.loadWebfontAndOpen(document.getElementById('term'));
term.write("Python 2.7.14\r\n \r\nEveryone can modify this shell in real time.\r\nIt's a sandbox that works exactly like a native shell.\r\n\r\n\u001b]0;IPython: home/coderpad\u0007\r\n\u001b[?1l\u001b[6n\u001b[?2004h\u001b[?25l\u001b[0m\u001b[?7l\u001b[0m\u001b[J\u001b[0;38;5;2m>>> \u001b[4D\u001b[4C\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[0m\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\u001b[12A\u001b[4C\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b]0;IPython: home/coderpad\u0007\u001b[1;36m File \u001b[1;32m\"/home/coderpad/solution.py\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\r\n\u001b[1;33m print 'Hello, World\u001b[0m\r\n\u001b[1;37m ^\u001b[0m\r\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\r\n\r\n\r\n\u001b[?1l\u001b[6n\u001b[?2004h\u001b[?25l\u001b[0m\u001b[?7l\u001b[0m\u001b[J\u001b[0;38;5;2m>>> \u001b[4D\u001b[4C\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[0m\r\r\n\r\r\n\u001b[2A\u001b[4C\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[0m\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\r\r\n\u001b[6A\u001b[4C\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h\u001b[?25l\u001b[?7l\u001b[?7h\u001b[0m\u001b[?12l\u001b[?25h")
</script>
</body>
</html>
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
}
}
20 changes: 20 additions & 0 deletions src/addons/webfont/webfont.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="../../../typings/xterm.d.ts"/>

import { Terminal } from 'xterm';

export function apply(terminalConstructor: typeof Terminal): void {
(<any>terminalConstructor.prototype).loadWebfontAndOpen = function (element: HTMLElement): void {
const FontFaceObserver = (typeof window === 'object' && (<any>window).FontFaceObserver);
if (!FontFaceObserver) {
console.warn('FontFaceObserver not available, opening xterm normally!');
return this.open(element);
}
const regular = new FontFaceObserver(this.options.fontFamily).load();
const bold = new FontFaceObserver(this.options.fontFamily, { weight: 'bold' }).load();

return regular.constructor.all([regular, bold]).then(() => {
this.open(element);
return this;
});
};
}