terminal: supports setting scroll-on-output for xterm.js

Bug: b/236205389
Change-Id: I06143cc3a9d95cdc29c489136946f9d2c034bdd2
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/3949413
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 53752dc..294e254 100644
--- a/terminal/js/terminal_emulator.js
+++ b/terminal/js/terminal_emulator.js
@@ -394,6 +394,7 @@
     this.htermA11yReader_ = null;
     this.a11yButtons_ = null;
     this.copyNotice_ = null;
+    this.scrollOnOutputListener_ = null;
 
     this.term.options.linkHandler = new LinkHandler(this.term);
     this.term.options.theme = {
@@ -710,6 +711,17 @@
         setHtermColorCSSVariable('foreground-color', v);
       },
       'line-height': (v) => this.updateOption_('lineHeight', v, true),
+      'scroll-on-output': (v) => {
+        if (!v) {
+          this.scrollOnOutputListener_?.dispose();
+          this.scrollOnOutputListener_ = null;
+          return;
+        }
+        if (!this.scrollOnOutputListener_) {
+          this.scrollOnOutputListener_ = this.term.onWriteParsed(
+              () => this.term.scrollToBottom());
+        }
+      },
     });
 
     for (const name of ['keybindings-os-defaults', 'pass-ctrl-n', 'pass-ctrl-t',