hterm: Improved 8-bit control and unterminated sequence handling.
* Add 'enable-8-bit-control' preference to enable eight bit control sequences.
This is off by default (which matches xterm) in order to avoid accidental
usage of some sequences that require termination. If you encounter one of
these on accident (while cat'ing binary data, for example) the terminal
will appear to lock up while waiting for the terminator byte.
* Add 'max-unterminated-sequence' preference to prevent sequences that require
a terminator from running away forever.
* Squelch warning that used to appear when clearing an empty screen.
* Refactor the parser logic a bit to make it easier to back up when
we fail to find the end of a string sequence.
Internal bug:
6375936 hterm hangs when \x90, \x9D, or \x9E is printed
BUG=none
TEST=test_harness.html, tests passed.
Change-Id: Icb302dfaa22f9cbe7c607d28ff6d9e468a2d989a
Reviewed-on: https://gerrit.chromium.org/gerrit/21072
Commit-Ready: Robert Ginda <rginda@chromium.org>
Reviewed-by: Robert Ginda <rginda@chromium.org>
Tested-by: Robert Ginda <rginda@chromium.org>
Commit-Ready: Marius Schilder <mschilder@google.com>
Reviewed-by: Marius Schilder <mschilder@google.com>
diff --git a/hterm/js/terminal.js b/hterm/js/terminal.js
index c0e00d8..45ebee4 100644
--- a/hterm/js/terminal.js
+++ b/hterm/js/terminal.js
@@ -88,6 +88,8 @@
// The VT escape sequence interpreter.
this.vt = new hterm.VT(this);
+ this.vt.enable8BitControl = this.prefs_.get('enable-8-bit-control');
+ this.vt.maxStringSequence = this.prefs_.get('max-string-sequence');
// The keyboard hander.
this.keyboard = new hterm.Keyboard(this);
@@ -216,6 +218,17 @@
],
/**
+ * True to enable 8-bit control characters, false to ignore them.
+ *
+ * We'll respect the two-byte versions of these control characters
+ * regardless of this setting.
+ */
+ ['enable-8-bit-control', false, function(v) {
+ self.vt.enable8BitControl = !!v;
+ }
+ ],
+
+ /**
* True if we should use bold weight font for text with the bold/bright
* attribute. False to use bright colors only. Null to autodetect.
*/
@@ -267,6 +280,15 @@
],
/**
+ * Max length of a DCS, OSC, PM, or APS sequence before we give up and
+ * ignore the code.
+ */
+ ['max-string-sequence', 1024, function(v) {
+ self.vt.maxStringSequence = v;
+ }
+ ],
+
+ /**
* Set whether the meta key sends a leading escape or not.
*/
['meta-sends-escape', true, function(v) {
@@ -1312,6 +1334,11 @@
var screen = opt_screen || this.screen_;
var bottom = screen.getHeight();
+ if (bottom == 0) {
+ // Empty screen, nothing to do.
+ return;
+ }
+
for (var i = 0; i < bottom; i++) {
screen.setCursorPosition(i, 0);
screen.clearCursorRow();