From 397b24f13830dac8f615d46dca2482c38bdb8edc Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 8 Dec 2019 23:21:01 +0800 Subject: [PATCH] html: webgl renderer support --- html/package.json | 3 ++- html/src/components/terminal/index.tsx | 10 ++++++++-- html/yarn.lock | 7 ++++++- src/index.html | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/html/package.json b/html/package.json index 4ea034a..033074a 100644 --- a/html/package.json +++ b/html/package.json @@ -62,9 +62,10 @@ "decko": "^1.2.0", "file-saver": "^2.0.2", "preact": "^10.0.5", - "xterm": "^4.2.0", + "xterm": "^4.3.0", "xterm-addon-fit": "^0.3.0", "xterm-addon-web-links": "^0.2.1", + "xterm-addon-webgl": "^0.4.0", "zmodem.js": "^0.1.9" } } diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx index d34efc6..7669975 100644 --- a/html/src/components/terminal/index.tsx +++ b/html/src/components/terminal/index.tsx @@ -3,6 +3,7 @@ import * as backoff from 'backoff'; import { Component, h } from 'preact'; import { ITerminalOptions, Terminal } from 'xterm'; import { FitAddon } from 'xterm-addon-fit'; +import { WebglAddon } from 'xterm-addon-webgl'; import { WebLinksAddon } from 'xterm-addon-web-links'; import { OverlayAddon } from './overlay'; @@ -221,8 +222,13 @@ export class Xterm extends Component { case Command.SET_PREFERENCES: const preferences = JSON.parse(textDecoder.decode(data)); Object.keys(preferences).forEach(key => { - console.log(`[ttyd] setting ${key}: ${preferences[key]}`); - terminal.setOption(key, preferences[key]); + if (key === 'rendererType' && preferences[key] === 'webgl') { + terminal.loadAddon(new WebglAddon()); + console.log(`[ttyd] WebGL renderer enabled`); + } else { + console.log(`[ttyd] option: ${key}=${preferences[key]}`); + terminal.setOption(key, preferences[key]); + } }); break; default: diff --git a/html/yarn.lock b/html/yarn.lock index f6c4687..50b8ced 100644 --- a/html/yarn.lock +++ b/html/yarn.lock @@ -8623,7 +8623,12 @@ xterm-addon-web-links@^0.2.1: resolved "https://registry.yarnpkg.com/xterm-addon-web-links/-/xterm-addon-web-links-0.2.1.tgz#6d1f2ce613e09870badf17615e7a1170a31542b2" integrity sha512-2KnHtiq0IG7hfwv3jw2/jQeH1RBk2d5CH4zvgwQe00rLofSJqSfgnJ7gwowxxpGHrpbPr6Lv4AmH/joaNw2+HQ== -xterm@^4.2.0: +xterm-addon-webgl@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.4.0.tgz#7b7cdbdbf9b0d06189af20d468d8ea2798382e0f" + integrity sha512-2ExOKJQcyv4hUo/d41uMDe7fNZCi42kPtbvG/v+dVj1NwqGD7g1bhuoH2j1iA1vTP5O1fClc6pU9nLBpbwrdZQ== + +xterm@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.3.0.tgz#9a302efefe75172d4f7ea3afc20f9bd983f05027" integrity sha512-6dnrC4nxgnRKQzIWwC5HA0mnT9/rpDPZflUIr24gdcdSMTKM1QQcor4qQ/xz4Zerz6AIL/CuuBPypFfzsB63dQ== diff --git a/src/index.html b/src/index.html index e2243bc..5221764 100644 --- a/src/index.html +++ b/src/index.html @@ -1 +1 @@ -ttyd - Terminal \ No newline at end of file +ttyd - Terminal \ No newline at end of file -- 2.43.4