From 84235c20fa12492228cb7d9c045f51eede7d63fb Mon Sep 17 00:00:00 2001 From: Will Owens Date: Sun, 27 Feb 2022 21:36:46 -0500 Subject: [PATCH] Add WebGL support --- .gotty | 3 +++ README.md | 13 +++++++++++++ js/package-lock.json | 17 ++++++++++++++++- js/package.json | 3 ++- js/src/hterm.ts | 8 +++++--- js/src/xterm.ts | 6 ++++++ server/options.go | 2 ++ 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/.gotty b/.gotty index c97448f..3975963 100644 --- a/.gotty +++ b/.gotty @@ -201,6 +201,9 @@ // [bool] Respect the host's attempt to change the cursor blink status using DEC Private Mode 12. // enable_dec12 = false + // [bool] Enable webgl rendering in the browser client terminal(hterm) + // enable_webgl = false + // [map[string]string] The default environment variables, as an object. // environment = {"TERM" = "xterm-256color"} diff --git a/README.md b/README.md index da1134f..9258264 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,19 @@ preferences { See the [`.gotty`](https://github.com/ghthor/gotty/blob/master/.gotty) file in this repository for the list of configuration options. +#### Enable WebGL + +The WebGL renderer is much better than the default canvas renderer for text; it +can handle italics without clipping the letters. I think this is because +upstream xtermjs is focusing on the WebGL renderer. To enable WebGL you need to +add the following to your `~/.gotty` config file. + +```hcl +preferences { + enable_webgl = true +} +``` + ### Security Options By default, GoTTY doesn't allow clients to send any keystrokes or commands except terminal window resizing. When you want to permit clients to write input to the TTY, add the `-w` option. However, accepting input from remote clients is dangerous for most commands. When you need interaction with the TTY for some reasons, consider starting GoTTY with tmux or GNU Screen and run your command on it (see "Sharing with Multiple Clients" section for detail). diff --git a/js/package-lock.json b/js/package-lock.json index c7dd0a8..df24ca4 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -7,7 +7,8 @@ "dependencies": { "libapps": "github:yudai/libapps#release-hterm-1.70", "xterm": "^4.17", - "xterm-addon-fit": "^0.5.0" + "xterm-addon-fit": "^0.5.0", + "xterm-addon-webgl": "^0.11.4" }, "devDependencies": { "license-loader": "^0.5.0", @@ -1568,6 +1569,14 @@ "peerDependencies": { "xterm": "^4.0.0" } + }, + "node_modules/xterm-addon-webgl": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/xterm-addon-webgl/-/xterm-addon-webgl-0.11.4.tgz", + "integrity": "sha512-/a/VFeftc+etGXQYWaaks977j1P7/wickBXn15zDxZzXYYMT9RN17ztqyIDVLXg9krtg28+icKK6lvgIYghJ0w==", + "peerDependencies": { + "xterm": "^4.0.0" + } } }, "dependencies": { @@ -2740,6 +2749,12 @@ "resolved": "https://registry.npmjs.org/xterm-addon-fit/-/xterm-addon-fit-0.5.0.tgz", "integrity": "sha512-DsS9fqhXHacEmsPxBJZvfj2la30Iz9xk+UKjhQgnYNkrUIN5CYLbw7WEfz117c7+S86S/tpHPfvNxJsF5/G8wQ==", "requires": {} + }, + "xterm-addon-webgl": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/xterm-addon-webgl/-/xterm-addon-webgl-0.11.4.tgz", + "integrity": "sha512-/a/VFeftc+etGXQYWaaks977j1P7/wickBXn15zDxZzXYYMT9RN17ztqyIDVLXg9krtg28+icKK6lvgIYghJ0w==", + "requires": {} } } } diff --git a/js/package.json b/js/package.json index 6b24047..e345150 100644 --- a/js/package.json +++ b/js/package.json @@ -9,6 +9,7 @@ "dependencies": { "libapps": "github:yudai/libapps#release-hterm-1.70", "xterm": "^4.17", - "xterm-addon-fit": "^0.5.0" + "xterm-addon-fit": "^0.5.0", + "xterm-addon-webgl": "^0.11.4" } } diff --git a/js/src/hterm.ts b/js/src/hterm.ts index b49a22f..0bdec30 100644 --- a/js/src/hterm.ts +++ b/js/src/hterm.ts @@ -52,9 +52,11 @@ export class Hterm { }; setPreferences(value: object) { - Object.keys(value).forEach((key) => { - this.term.getPrefs().set(key, value[key]); - }); + Object.keys(value).forEach((key) => { + if (key != "enable-webgl") { + this.term.getPrefs().set(key, value[key]); + } + }); }; onInput(callback: (input: string) => void) { diff --git a/js/src/xterm.ts b/js/src/xterm.ts index bd4a60f..9158994 100644 --- a/js/src/xterm.ts +++ b/js/src/xterm.ts @@ -2,6 +2,7 @@ import {lib} from "libapps"; import {IDisposable, Terminal} from 'xterm'; import {FitAddon} from "xterm-addon-fit"; +import {WebglAddon} from "xterm-addon-webgl"; export class Xterm { @@ -84,6 +85,11 @@ export class Xterm { }; setPreferences(value: object) { + Object.keys(value).forEach((key) => { + if (key && key == "enable-webgl") { + this.term.loadAddon(new WebglAddon()); + } + }); }; onInput(callback: (input: string) => void) { diff --git a/server/options.go b/server/options.go index 3d7f69c..69b8203 100644 --- a/server/options.go +++ b/server/options.go @@ -41,6 +41,7 @@ func (options *Options) Validate() error { return nil } +// TODO(ghthor): add defaults to all these options that match the example .gotty file type HtermPrefernces struct { AltGrMode *string `hcl:"alt_gr_mode" json:"alt-gr-mode,omitempty"` AltBackspaceIsMetaBackspace bool `hcl:"alt_backspace_is_meta_backspace" json:"alt-backspace-is-meta-backspace,omitempty"` @@ -72,6 +73,7 @@ type HtermPrefernces struct { EnableClipboardNotice bool `hcl:"enable_clipboard_notice" json:"enable-clipboard-notice,omitempty"` EnableClipboardWrite bool `hcl:"enable_clipboard_write" json:"enable-clipboard-write,omitempty"` EnableDec12 bool `hcl:"enable_dec12" json:"enable-dec12,omitempty"` + EnableWebGL bool `hcl:"enable_webgl" json:"enable-webgl,omitempty"` Environment map[string]string `hcl:"environment" json:"environment,omitempty"` FontFamily string `hcl:"font_family" json:"font-family,omitempty"` FontSize int `hcl:"font_size" json:"font-size,omitempty"`