terminal: respect user css prefs for xterm.js
Bug: b/236205389
Change-Id: Iea10cf9655afed18427f90b498fe6105841fe542
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/3998392
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/terminal/js/terminal_emulator.js b/terminal/js/terminal_emulator.js
index a026ec8..bf59cc9 100644
--- a/terminal/js/terminal_emulator.js
+++ b/terminal/js/terminal_emulator.js
@@ -483,6 +483,8 @@
this.backgroundImageWatcher_ = new BackgroundImageWatcher(this.prefs_,
this.setBackgroundImage.bind(this));
this.webglAddon_ = null;
+ this.userCSSElement_ = null;
+ this.userCSSTextElement_ = null;
this.term.options.linkHandler = new LinkHandler(this.term);
this.term.options.theme = {
@@ -845,6 +847,24 @@
() => this.term.scrollToBottom());
}
},
+ 'user-css': (v) => {
+ if (this.userCSSElement_) {
+ this.userCSSElement_.remove();
+ }
+ if (v) {
+ this.userCSSElement_ = document.createElement('link');
+ this.userCSSElement_.setAttribute('rel', 'stylesheet');
+ this.userCSSElement_.setAttribute('href', v);
+ document.head.appendChild(this.userCSSElement_);
+ }
+ },
+ 'user-css-text': (v) => {
+ if (!this.userCSSTextElement_) {
+ this.userCSSTextElement_ = document.createElement('style');
+ document.head.appendChild(this.userCSSTextElement_);
+ }
+ this.userCSSTextElement_.textContent = v;
+ },
});
for (const name of ['keybindings-os-defaults', 'pass-ctrl-n', 'pass-ctrl-t',