blob: 16cd3523ba5fe6ece232781bdc68ed7d2150adff [file] [log] [blame]
rginda87b86462011-12-14 13:48:03 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
rginda8ba33642011-12-14 12:31:31 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * Constructor for the Terminal class.
7 *
8 * A Terminal pulls together the hterm.ScrollPort, hterm.Screen and hterm.VT100
9 * classes to provide the complete terminal functionality.
10 *
11 * There are a number of lower-level Terminal methods that can be called
12 * directly to manipulate the cursor, text, scroll region, and other terminal
13 * attributes. However, the primary method is interpret(), which parses VT
14 * escape sequences and invokes the appropriate Terminal methods.
15 *
16 * This class was heavily influenced by Cory Maccarrone's Framebuffer class.
17 *
18 * TODO(rginda): Eventually we're going to need to support characters which are
19 * displayed twice as wide as standard latin characters. This is to support
20 * CJK (and possibly other character sets).
rginda9f5222b2012-03-05 11:53:28 -080021 *
22 * @param {string} opt_profileName Optional preference profile name. If not
23 * provided, defaults to 'default'.
rginda8ba33642011-12-14 12:31:31 -080024 */
rginda9f5222b2012-03-05 11:53:28 -080025hterm.Terminal = function(opt_profileName) {
26 this.profileName_ = null;
27 this.setProfile(opt_profileName || 'default');
28
rginda8ba33642011-12-14 12:31:31 -080029 // Two screen instances.
30 this.primaryScreen_ = new hterm.Screen();
31 this.alternateScreen_ = new hterm.Screen();
32
33 // The "current" screen.
34 this.screen_ = this.primaryScreen_;
35
rginda8ba33642011-12-14 12:31:31 -080036 // The local notion of the screen size. ScreenBuffers also have a size which
37 // indicates their present size. During size changes, the two may disagree.
38 // Also, the inactive screen's size is not altered until it is made the active
39 // screen.
40 this.screenSize = new hterm.Size(0, 0);
41
rginda8ba33642011-12-14 12:31:31 -080042 // The scroll port we'll be using to display the visible rows.
rginda35c456b2012-02-09 17:29:05 -080043 this.scrollPort_ = new hterm.ScrollPort(this);
rginda8ba33642011-12-14 12:31:31 -080044 this.scrollPort_.subscribe('resize', this.onResize_.bind(this));
45 this.scrollPort_.subscribe('scroll', this.onScroll_.bind(this));
rginda9846e2f2012-01-27 13:53:33 -080046 this.scrollPort_.subscribe('paste', this.onPaste_.bind(this));
rginda8ba33642011-12-14 12:31:31 -080047
rginda87b86462011-12-14 13:48:03 -080048 // The div that contains this terminal.
49 this.div_ = null;
50
rgindac9bc5502012-01-18 11:48:44 -080051 // The document that contains the scrollPort. Defaulted to the global
52 // document here so that the terminal is functional even if it hasn't been
53 // inserted into a document yet, but re-set in decorate().
54 this.document_ = window.document;
rginda87b86462011-12-14 13:48:03 -080055
rginda8ba33642011-12-14 12:31:31 -080056 // The rows that have scrolled off screen and are no longer addressable.
57 this.scrollbackRows_ = [];
58
rgindac9bc5502012-01-18 11:48:44 -080059 // Saved tab stops.
60 this.tabStops_ = [];
61
David Benjamin66e954d2012-05-05 21:08:12 -040062 // Keep track of whether default tab stops have been erased; after a TBC
63 // clears all tab stops, defaults aren't restored on resize until a reset.
64 this.defaultTabStops = true;
65
rginda8ba33642011-12-14 12:31:31 -080066 // The VT's notion of the top and bottom rows. Used during some VT
67 // cursor positioning and scrolling commands.
68 this.vtScrollTop_ = null;
69 this.vtScrollBottom_ = null;
70
71 // The DIV element for the visible cursor.
72 this.cursorNode_ = null;
73
rginda9f5222b2012-03-05 11:53:28 -080074 // These prefs are cached so we don't have to read from local storage with
75 // each output and keystroke.
76 this.scrollOnOutput_ = this.prefs_.get('scroll-on-output');
77 this.scrollOnKeystroke_ = this.prefs_.get('scroll-on-keystroke');
78
rgindaf0090c92012-02-10 14:58:52 -080079 // Terminal bell sound.
80 this.bellAudio_ = this.document_.createElement('audio');
rginda9f5222b2012-03-05 11:53:28 -080081 this.bellAudio_.setAttribute('src', this.prefs_.get('audible-bell-sound'));
rgindaf0090c92012-02-10 14:58:52 -080082 this.bellAudio_.setAttribute('preload', 'auto');
83
rginda6d397402012-01-17 10:58:29 -080084 // Cursor position and attributes saved with DECSC.
85 this.savedOptions_ = {};
86
rginda8ba33642011-12-14 12:31:31 -080087 // The current mode bits for the terminal.
88 this.options_ = new hterm.Options();
89
90 // Timeouts we might need to clear.
91 this.timeouts_ = {};
rginda87b86462011-12-14 13:48:03 -080092
93 // The VT escape sequence interpreter.
rginda0f5c0292012-01-13 11:00:13 -080094 this.vt = new hterm.VT(this);
rginda11057d52012-04-25 12:29:56 -070095 this.vt.enable8BitControl = this.prefs_.get('enable-8-bit-control');
96 this.vt.maxStringSequence = this.prefs_.get('max-string-sequence');
rginda87b86462011-12-14 13:48:03 -080097
rgindafeaf3142012-01-31 15:14:20 -080098 // The keyboard hander.
99 this.keyboard = new hterm.Keyboard(this);
100
rginda87b86462011-12-14 13:48:03 -0800101 // General IO interface that can be given to third parties without exposing
102 // the entire terminal object.
103 this.io = new hterm.Terminal.IO(this);
rgindac9bc5502012-01-18 11:48:44 -0800104
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400105 this.realizeSize_(80, 24);
rgindac9bc5502012-01-18 11:48:44 -0800106 this.setDefaultTabStops();
rginda87b86462011-12-14 13:48:03 -0800107};
108
109/**
rginda35c456b2012-02-09 17:29:05 -0800110 * Default tab with of 8 to match xterm.
111 */
112hterm.Terminal.prototype.tabWidth = 8;
113
114/**
rginda35c456b2012-02-09 17:29:05 -0800115 * The assumed width of a scrollbar.
116 */
117hterm.Terminal.prototype.scrollbarWidthPx = 16;
118
119/**
rginda9f5222b2012-03-05 11:53:28 -0800120 * Select a preference profile.
121 *
122 * This will load the terminal preferences for the given profile name and
123 * associate subsequent preference changes with the new preference profile.
124 *
125 * @param {string} newName The name of the preference profile. Forward slash
126 * characters will be removed from the name.
127 */
128hterm.Terminal.prototype.setProfile = function(profileName) {
129 // If we already have a profile selected, we're going to need to re-sync
130 // with the new profile.
131 var needSync = !!this.profileName_;
132
133 this.profileName_ = profileName.replace(/\//g, '');
134
135 this.prefs_ = new hterm.PreferenceManager(
136 '/hterm/prefs/profiles/' + this.profileName_);
137
138 var self = this;
139 this.prefs_.definePreferences
rginda30f20f62012-04-05 16:36:19 -0700140 ([
141 /**
142 * Set whether the alt key acts as a meta key or as a distinct alt key.
rginda9f5222b2012-03-05 11:53:28 -0800143 */
rginda30f20f62012-04-05 16:36:19 -0700144 ['alt-is-meta', false, function(v) {
rgindaf9c36852012-05-09 11:08:39 -0700145 self.keyboard.altIsMeta = v;
rginda9f5222b2012-03-05 11:53:28 -0800146 }
147 ],
148
rginda30f20f62012-04-05 16:36:19 -0700149 /**
rginda39bdf6f2012-04-10 16:50:55 -0700150 * Controls how the alt key is handled.
151 *
152 * escape....... Send an ESC prefix.
153 * 8-bit........ Add 128 to the unshifted character as in xterm.
154 * browser-key.. Wait for the keypress event and see what the browser says.
155 * (This won't work well on platforms where the browser
156 * performs a default action for some alt sequences.)
rginda30f20f62012-04-05 16:36:19 -0700157 */
rginda39bdf6f2012-04-10 16:50:55 -0700158 ['alt-sends-what', 'escape', function(v) {
159 if (!/^(escape|8-bit|browser-key)$/.test(v))
160 v = 'escape';
161
rgindaf9c36852012-05-09 11:08:39 -0700162 self.keyboard.altSendsWhat = v;
rginda30f20f62012-04-05 16:36:19 -0700163 }
164 ],
165
166 /**
167 * Terminal bell sound. Empty string for no audible bell.
168 */
169 ['audible-bell-sound', '../audio/bell.ogg', function(v) {
170 self.bellAudio_.setAttribute('src', v);
171 }
172 ],
173
174 /**
175 * The background color for text with no other color attributes.
176 */
177 ['background-color', 'rgb(16, 16, 16)', function(v) {
rginda9f5222b2012-03-05 11:53:28 -0800178 self.scrollPort_.setBackgroundColor(v);
179 }
180 ],
181
182 /**
rginda30f20f62012-04-05 16:36:19 -0700183 * The background image.
184 *
185 * Defaults to a subtle light-to-transparent-to-dark gradient that is
186 * mostly transparent.
187 */
188 ['background-image',
189 ('-webkit-linear-gradient(bottom, ' +
190 'rgba(0,0,0,0.01) 0%, ' +
191 'rgba(0,0,0,0) 30%, ' +
192 'rgba(255,255,255,0) 70%, ' +
193 'rgba(255,255,255,0.05) 100%)'),
194 function(v) {
195 self.scrollPort_.setBackgroundImage(v);
196 }
197 ],
198
199 /**
Philip Douglass959b49d2012-05-30 13:29:29 -0400200 * The background image size,
201 *
202 * Defaults to none.
203 */
204 ['background-size', '', function(v) {
205 self.scrollPort_.setBackgroundSize(v);
206 }
207 ],
208
209 /**
210 * The background image position,
211 *
212 * Defaults to none.
213 */
214 ['background-position', '', function(v) {
215 self.scrollPort_.setBackgroundPosition(v);
216 }
217 ],
218
219 /**
rginda30f20f62012-04-05 16:36:19 -0700220 * If true, the backspace should send BS ('\x08', aka ^H). Otherwise
221 * the backspace key should send '\x7f'.
222 */
223 ['backspace-sends-backspace', false, function(v) {
224 self.keyboard.backspaceSendsBackspace = v;
225 }
226 ],
227
228 /**
rgindade84e382012-04-20 15:39:31 -0700229 * Whether or not to blink the cursor by default.
230 */
231 ['cursor-blink', false, function(v) {
232 self.setCursorBlink(!!v);
233 }
234 ],
235
236 /**
rginda30f20f62012-04-05 16:36:19 -0700237 * The color of the visible cursor.
238 */
239 ['cursor-color', 'rgba(255,0,0,0.5)', function(v) {
240 self.cursorNode_.style.backgroundColor = v;
241 }
242 ],
243
244 /**
rginda11057d52012-04-25 12:29:56 -0700245 * True to enable 8-bit control characters, false to ignore them.
246 *
247 * We'll respect the two-byte versions of these control characters
248 * regardless of this setting.
249 */
250 ['enable-8-bit-control', false, function(v) {
251 self.vt.enable8BitControl = !!v;
252 }
253 ],
254
255 /**
rginda30f20f62012-04-05 16:36:19 -0700256 * True if we should use bold weight font for text with the bold/bright
257 * attribute. False to use bright colors only. Null to autodetect.
258 */
259 ['enable-bold', null, function(v) {
260 self.syncBoldSafeState();
261 }
262 ],
263
264 /**
rginda9f5222b2012-03-05 11:53:28 -0800265 * Default font family for the terminal text.
266 */
267 ['font-family', ('"DejaVu Sans Mono", "Everson Mono", ' +
268 'FreeMono, "Menlo", "Lucida Console", ' +
269 'monospace'),
270 function(v) { self.syncFontFamily() }
271 ],
272
273 /**
rginda30f20f62012-04-05 16:36:19 -0700274 * The default font size in pixels.
275 */
276 ['font-size', 15, function(v) {
277 self.setFontSize(v);
278 }
279 ],
280
281 /**
rginda9f5222b2012-03-05 11:53:28 -0800282 * Anti-aliasing.
283 */
284 ['font-smoothing', 'antialiased',
285 function(v) { self.syncFontFamily() }
286 ],
287
288 /**
rginda30f20f62012-04-05 16:36:19 -0700289 * The foreground color for text with no other color attributes.
rginda9f5222b2012-03-05 11:53:28 -0800290 */
rginda30f20f62012-04-05 16:36:19 -0700291 ['foreground-color', 'rgb(240, 240, 240)', function(v) {
292 self.scrollPort_.setForegroundColor(v);
rginda9f5222b2012-03-05 11:53:28 -0800293 }
294 ],
295
296 /**
rginda30f20f62012-04-05 16:36:19 -0700297 * If true, home/end will control the terminal scrollbar and shift home/end
298 * will send the VT keycodes. If false then home/end sends VT codes and
299 * shift home/end scrolls.
rginda9f5222b2012-03-05 11:53:28 -0800300 */
rginda30f20f62012-04-05 16:36:19 -0700301 ['home-keys-scroll', false, function(v) {
302 self.keyboard.homeKeysScroll = v;
303 }
304 ],
305
306 /**
rginda11057d52012-04-25 12:29:56 -0700307 * Max length of a DCS, OSC, PM, or APS sequence before we give up and
308 * ignore the code.
309 */
310 ['max-string-sequence', 1024, function(v) {
311 self.vt.maxStringSequence = v;
312 }
313 ],
314
315 /**
rginda30f20f62012-04-05 16:36:19 -0700316 * Set whether the meta key sends a leading escape or not.
317 */
318 ['meta-sends-escape', true, function(v) {
319 self.keyboard.metaSendsEscape = v;
rginda9f5222b2012-03-05 11:53:28 -0800320 }
321 ],
322
323 /**
324 * If true, scroll to the bottom on any keystroke.
325 */
326 ['scroll-on-keystroke', true, function(v) {
327 self.scrollOnKeystroke_ = v;
328 }
329 ],
330
331 /**
332 * If true, scroll to the bottom on terminal output.
333 */
334 ['scroll-on-output', false, function(v) {
335 self.scrollOnOutput_ = v;
336 }
337 ],
338
339 /**
David Reveman8f552492012-03-28 12:18:41 -0400340 * The vertical scrollbar mode.
341 */
342 ['scrollbar-visible', true, function(v) {
343 self.setScrollbarVisible(v);
344 }
345 ],
rginda30f20f62012-04-05 16:36:19 -0700346
347 /**
rgindaf522ce02012-04-17 17:49:17 -0700348 * The default environment variables.
349 */
350 ['environment', {TERM: 'xterm-256color'}, null],
351
352 /**
rginda30f20f62012-04-05 16:36:19 -0700353 * If true, page up/down will control the terminal scrollbar and shift
354 * page up/down will send the VT keycodes. If false then page up/down
355 * sends VT codes and shift page up/down scrolls.
356 */
357 ['page-keys-scroll', false, function(v) {
358 self.keyboard.pageKeysScroll = v;
359 }
360 ],
361
rginda9f5222b2012-03-05 11:53:28 -0800362 ]);
363
364 if (needSync)
365 this.prefs_.notifyAll();
366};
367
368/**
369 * Return the current terminal background color.
370 *
371 * Intended for use by other classes, so we don't have to expose the entire
372 * prefs_ object.
373 */
374hterm.Terminal.prototype.getBackgroundColor = function() {
375 return this.prefs_.get('background-color');
376};
377
378/**
379 * Return the current terminal foreground color.
380 *
381 * Intended for use by other classes, so we don't have to expose the entire
382 * prefs_ object.
383 */
384hterm.Terminal.prototype.getForegroundColor = function() {
385 return this.prefs_.get('foreground-color');
386};
387
388/**
rginda87b86462011-12-14 13:48:03 -0800389 * Create a new instance of a terminal command and run it with a given
390 * argument string.
391 *
392 * @param {function} commandClass The constructor for a terminal command.
393 * @param {string} argString The argument string to pass to the command.
394 */
395hterm.Terminal.prototype.runCommandClass = function(commandClass, argString) {
rgindaf522ce02012-04-17 17:49:17 -0700396 var environment = this.prefs_.get('environment');
397 if (typeof environment != 'object' || environment == null)
398 environment = {};
399
rginda87b86462011-12-14 13:48:03 -0800400 var self = this;
401 this.command = new commandClass(
402 { argString: argString || '',
403 io: this.io.push(),
rgindaf522ce02012-04-17 17:49:17 -0700404 environment: environment,
rginda87b86462011-12-14 13:48:03 -0800405 onExit: function(code) {
406 self.io.pop();
407 self.io.println(hterm.msg('COMMAND_COMPLETE',
408 [self.command.commandName, code]));
rgindafeaf3142012-01-31 15:14:20 -0800409 self.uninstallKeyboard();
rginda87b86462011-12-14 13:48:03 -0800410 }
411 });
412
rgindafeaf3142012-01-31 15:14:20 -0800413 this.installKeyboard();
rginda87b86462011-12-14 13:48:03 -0800414 this.command.run();
415};
416
417/**
rgindafeaf3142012-01-31 15:14:20 -0800418 * Returns true if the current screen is the primary screen, false otherwise.
419 */
420hterm.Terminal.prototype.isPrimaryScreen = function() {
rgindaf522ce02012-04-17 17:49:17 -0700421 return this.screen_ == this.primaryScreen_;
rgindafeaf3142012-01-31 15:14:20 -0800422};
423
424/**
425 * Install the keyboard handler for this terminal.
426 *
427 * This will prevent the browser from seeing any keystrokes sent to the
428 * terminal.
429 */
430hterm.Terminal.prototype.installKeyboard = function() {
431 this.keyboard.installKeyboard(this.document_.body.firstChild);
432}
433
434/**
435 * Uninstall the keyboard handler for this terminal.
436 */
437hterm.Terminal.prototype.uninstallKeyboard = function() {
438 this.keyboard.installKeyboard(null);
439}
440
441/**
rginda35c456b2012-02-09 17:29:05 -0800442 * Set the font size for this terminal.
rginda9f5222b2012-03-05 11:53:28 -0800443 *
444 * Call setFontSize(0) to reset to the default font size.
445 *
446 * This function does not modify the font-size preference.
447 *
448 * @param {number} px The desired font size, in pixels.
rginda35c456b2012-02-09 17:29:05 -0800449 */
450hterm.Terminal.prototype.setFontSize = function(px) {
rginda9f5222b2012-03-05 11:53:28 -0800451 if (px === 0)
452 px = this.prefs_.get('font-size');
453
rginda35c456b2012-02-09 17:29:05 -0800454 this.scrollPort_.setFontSize(px);
455};
456
457/**
458 * Get the current font size.
459 */
460hterm.Terminal.prototype.getFontSize = function() {
461 return this.scrollPort_.getFontSize();
462};
463
464/**
465 * Set the CSS "font-family" for this terminal.
466 */
rginda9f5222b2012-03-05 11:53:28 -0800467hterm.Terminal.prototype.syncFontFamily = function() {
468 this.scrollPort_.setFontFamily(this.prefs_.get('font-family'),
469 this.prefs_.get('font-smoothing'));
470 this.syncBoldSafeState();
471};
472
473hterm.Terminal.prototype.syncBoldSafeState = function() {
474 var enableBold = this.prefs_.get('enable-bold');
475 if (enableBold !== null) {
476 this.screen_.textAttributes.enableBold = enableBold;
477 return;
478 }
479
rgindaf7521392012-02-28 17:20:34 -0800480 var normalSize = this.scrollPort_.measureCharacterSize();
481 var boldSize = this.scrollPort_.measureCharacterSize('bold');
482
483 var isBoldSafe = normalSize.equals(boldSize);
rgindaf7521392012-02-28 17:20:34 -0800484 if (!isBoldSafe) {
485 console.warn('Bold characters disabled: Size of bold weight differs ' +
rgindac9759de2012-03-19 13:21:41 -0700486 'from normal. Font family is: ' +
487 this.scrollPort_.getFontFamily());
rgindaf7521392012-02-28 17:20:34 -0800488 }
rginda9f5222b2012-03-05 11:53:28 -0800489
490 this.screen_.textAttributes.enableBold = isBoldSafe;
rginda35c456b2012-02-09 17:29:05 -0800491};
492
493/**
rginda87b86462011-12-14 13:48:03 -0800494 * Return a copy of the current cursor position.
495 *
496 * @return {hterm.RowCol} The RowCol object representing the current position.
497 */
498hterm.Terminal.prototype.saveCursor = function() {
499 return this.screen_.cursorPosition.clone();
500};
501
rgindaa19afe22012-01-25 15:40:22 -0800502hterm.Terminal.prototype.getTextAttributes = function() {
503 return this.screen_.textAttributes;
504};
505
rginda87b86462011-12-14 13:48:03 -0800506/**
rgindaf522ce02012-04-17 17:49:17 -0700507 * Return the current browser zoom factor applied to the terminal.
508 *
509 * @return {number} The current browser zoom factor.
510 */
511hterm.Terminal.prototype.getZoomFactor = function() {
512 return this.scrollPort_.characterSize.zoomFactor;
513};
514
515/**
rginda9846e2f2012-01-27 13:53:33 -0800516 * Change the title of this terminal's window.
517 */
518hterm.Terminal.prototype.setWindowTitle = function(title) {
rgindafeaf3142012-01-31 15:14:20 -0800519 window.document.title = title;
rginda9846e2f2012-01-27 13:53:33 -0800520};
521
522/**
rginda87b86462011-12-14 13:48:03 -0800523 * Restore a previously saved cursor position.
524 *
525 * @param {hterm.RowCol} cursor The position to restore.
526 */
527hterm.Terminal.prototype.restoreCursor = function(cursor) {
rginda35c456b2012-02-09 17:29:05 -0800528 var row = hterm.clamp(cursor.row, 0, this.screenSize.height - 1);
529 var column = hterm.clamp(cursor.column, 0, this.screenSize.width - 1);
530 this.screen_.setCursorPosition(row, column);
531 if (cursor.column > column ||
532 cursor.column == column && cursor.overflow) {
533 this.screen_.cursorPosition.overflow = true;
534 }
rginda87b86462011-12-14 13:48:03 -0800535};
536
537/**
David Benjamin54e8bf62012-06-01 22:31:40 -0400538 * Clear the cursor's overflow flag.
539 */
540hterm.Terminal.prototype.clearCursorOverflow = function() {
541 this.screen_.cursorPosition.overflow = false;
542};
543
544/**
rginda87b86462011-12-14 13:48:03 -0800545 * Set the width of the terminal, resizing the UI to match.
546 */
547hterm.Terminal.prototype.setWidth = function(columnCount) {
rgindaf0090c92012-02-10 14:58:52 -0800548 if (columnCount == null) {
549 this.div_.style.width = '100%';
550 return;
551 }
552
rginda35c456b2012-02-09 17:29:05 -0800553 this.div_.style.width = this.scrollPort_.characterSize.width *
554 columnCount + this.scrollbarWidthPx + 'px';
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400555 this.realizeSize_(columnCount, this.screenSize.height);
rgindac9bc5502012-01-18 11:48:44 -0800556 this.scheduleSyncCursorPosition_();
557};
rginda87b86462011-12-14 13:48:03 -0800558
rgindac9bc5502012-01-18 11:48:44 -0800559/**
rginda35c456b2012-02-09 17:29:05 -0800560 * Set the height of the terminal, resizing the UI to match.
561 */
562hterm.Terminal.prototype.setHeight = function(rowCount) {
rgindaf0090c92012-02-10 14:58:52 -0800563 if (rowCount == null) {
564 this.div_.style.height = '100%';
565 return;
566 }
567
rginda35c456b2012-02-09 17:29:05 -0800568 this.div_.style.height =
rginda30f20f62012-04-05 16:36:19 -0700569 this.scrollPort_.characterSize.height * rowCount + 'px';
rginda35c456b2012-02-09 17:29:05 -0800570 this.realizeSize_(this.screenSize.width, rowCount);
571 this.scheduleSyncCursorPosition_();
572};
573
574/**
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400575 * Deal with terminal size changes.
576 *
577 */
578hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) {
579 if (columnCount != this.screenSize.width)
580 this.realizeWidth_(columnCount);
581
582 if (rowCount != this.screenSize.height)
583 this.realizeHeight_(rowCount);
584
585 // Send new terminal size to plugin.
586 this.io.onTerminalResize(columnCount, rowCount);
587};
588
589/**
rgindac9bc5502012-01-18 11:48:44 -0800590 * Deal with terminal width changes.
591 *
592 * This function does what needs to be done when the terminal width changes
593 * out from under us. It happens here rather than in onResize_() because this
594 * code may need to run synchronously to handle programmatic changes of
595 * terminal width.
596 *
597 * Relying on the browser to send us an async resize event means we may not be
598 * in the correct state yet when the next escape sequence hits.
599 */
600hterm.Terminal.prototype.realizeWidth_ = function(columnCount) {
601 var deltaColumns = columnCount - this.screen_.getWidth();
602
rginda87b86462011-12-14 13:48:03 -0800603 this.screenSize.width = columnCount;
604 this.screen_.setColumnCount(columnCount);
rgindac9bc5502012-01-18 11:48:44 -0800605
606 if (deltaColumns > 0) {
David Benjamin66e954d2012-05-05 21:08:12 -0400607 if (this.defaultTabStops)
608 this.setDefaultTabStops(this.screenSize.width - deltaColumns);
rgindac9bc5502012-01-18 11:48:44 -0800609 } else {
610 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
David Benjamin66e954d2012-05-05 21:08:12 -0400611 if (this.tabStops_[i] < columnCount)
rgindac9bc5502012-01-18 11:48:44 -0800612 break;
613
614 this.tabStops_.pop();
615 }
616 }
617
618 this.screen_.setColumnCount(this.screenSize.width);
619};
620
621/**
622 * Deal with terminal height changes.
623 *
624 * This function does what needs to be done when the terminal height changes
625 * out from under us. It happens here rather than in onResize_() because this
626 * code may need to run synchronously to handle programmatic changes of
627 * terminal height.
628 *
629 * Relying on the browser to send us an async resize event means we may not be
630 * in the correct state yet when the next escape sequence hits.
631 */
632hterm.Terminal.prototype.realizeHeight_ = function(rowCount) {
633 var deltaRows = rowCount - this.screen_.getHeight();
634
635 this.screenSize.height = rowCount;
636
637 var cursor = this.saveCursor();
638
639 if (deltaRows < 0) {
640 // Screen got smaller.
641 deltaRows *= -1;
642 while (deltaRows) {
643 var lastRow = this.getRowCount() - 1;
644 if (lastRow - this.scrollbackRows_.length == cursor.row)
645 break;
646
647 if (this.getRowText(lastRow))
648 break;
649
650 this.screen_.popRow();
651 deltaRows--;
652 }
653
654 var ary = this.screen_.shiftRows(deltaRows);
655 this.scrollbackRows_.push.apply(this.scrollbackRows_, ary);
656
657 // We just removed rows from the top of the screen, we need to update
658 // the cursor to match.
rginda35c456b2012-02-09 17:29:05 -0800659 cursor.row = Math.max(cursor.row - deltaRows, 0);
rgindac9bc5502012-01-18 11:48:44 -0800660 } else if (deltaRows > 0) {
661 // Screen got larger.
662
663 if (deltaRows <= this.scrollbackRows_.length) {
664 var scrollbackCount = Math.min(deltaRows, this.scrollbackRows_.length);
665 var rows = this.scrollbackRows_.splice(
666 this.scrollbackRows_.length - scrollbackCount, scrollbackCount);
667 this.screen_.unshiftRows(rows);
668 deltaRows -= scrollbackCount;
669 cursor.row += scrollbackCount;
670 }
671
672 if (deltaRows)
673 this.appendRows_(deltaRows);
674 }
675
rginda35c456b2012-02-09 17:29:05 -0800676 this.setVTScrollRegion(null, null);
rgindac9bc5502012-01-18 11:48:44 -0800677 this.restoreCursor(cursor);
rginda87b86462011-12-14 13:48:03 -0800678};
679
680/**
681 * Scroll the terminal to the top of the scrollback buffer.
682 */
683hterm.Terminal.prototype.scrollHome = function() {
684 this.scrollPort_.scrollRowToTop(0);
685};
686
687/**
688 * Scroll the terminal to the end.
689 */
690hterm.Terminal.prototype.scrollEnd = function() {
691 this.scrollPort_.scrollRowToBottom(this.getRowCount());
692};
693
694/**
695 * Scroll the terminal one page up (minus one line) relative to the current
696 * position.
697 */
698hterm.Terminal.prototype.scrollPageUp = function() {
699 var i = this.scrollPort_.getTopRowIndex();
700 this.scrollPort_.scrollRowToTop(i - this.screenSize.height + 1);
701};
702
703/**
704 * Scroll the terminal one page down (minus one line) relative to the current
705 * position.
706 */
707hterm.Terminal.prototype.scrollPageDown = function() {
708 var i = this.scrollPort_.getTopRowIndex();
709 this.scrollPort_.scrollRowToTop(i + this.screenSize.height - 1);
rginda8ba33642011-12-14 12:31:31 -0800710};
711
rgindac9bc5502012-01-18 11:48:44 -0800712/**
713 * Full terminal reset.
714 */
rginda87b86462011-12-14 13:48:03 -0800715hterm.Terminal.prototype.reset = function() {
rgindac9bc5502012-01-18 11:48:44 -0800716 this.clearAllTabStops();
717 this.setDefaultTabStops();
rginda9ea433c2012-03-16 11:57:00 -0700718
719 this.clearHome(this.primaryScreen_);
720 this.primaryScreen_.textAttributes.reset();
721
722 this.clearHome(this.alternateScreen_);
723 this.alternateScreen_.textAttributes.reset();
724
rgindab8bc8932012-04-27 12:45:03 -0700725 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
726
rgindac9bc5502012-01-18 11:48:44 -0800727 this.softReset();
rginda87b86462011-12-14 13:48:03 -0800728};
729
rgindac9bc5502012-01-18 11:48:44 -0800730/**
731 * Soft terminal reset.
rgindab8bc8932012-04-27 12:45:03 -0700732 *
733 * Perform a soft reset to the default values listed in
734 * http://www.vt100.net/docs/vt510-rm/DECSTR#T5-9
rgindac9bc5502012-01-18 11:48:44 -0800735 */
rginda0f5c0292012-01-13 11:00:13 -0800736hterm.Terminal.prototype.softReset = function() {
rgindab8bc8932012-04-27 12:45:03 -0700737 // Reset terminal options to their default values.
rgindac9bc5502012-01-18 11:48:44 -0800738 this.options_ = new hterm.Options();
rgindaf522ce02012-04-17 17:49:17 -0700739
rgindab8bc8932012-04-27 12:45:03 -0700740 // Xterm also resets the color palette on soft reset, even though it doesn't
741 // seem to be documented anywhere.
rgindaf522ce02012-04-17 17:49:17 -0700742 this.primaryScreen_.textAttributes.resetColorPalette();
743 this.alternateScreen_.textAttributes.resetColorPalette();
744
rgindab8bc8932012-04-27 12:45:03 -0700745 // The xterm man page explicitly says this will happen on soft reset.
746 this.setVTScrollRegion(null, null);
747
748 // Xterm also shows the cursor on soft reset, but does not alter the blink
749 // state.
rgindaa19afe22012-01-25 15:40:22 -0800750 this.setCursorVisible(true);
rginda0f5c0292012-01-13 11:00:13 -0800751};
752
rgindac9bc5502012-01-18 11:48:44 -0800753/**
754 * Move the cursor forward to the next tab stop, or to the last column
755 * if no more tab stops are set.
756 */
757hterm.Terminal.prototype.forwardTabStop = function() {
758 var column = this.screen_.cursorPosition.column;
759
760 for (var i = 0; i < this.tabStops_.length; i++) {
761 if (this.tabStops_[i] > column) {
762 this.setCursorColumn(this.tabStops_[i]);
763 return;
764 }
765 }
766
David Benjamin66e954d2012-05-05 21:08:12 -0400767 // xterm does not clear the overflow flag on HT or CHT.
768 var overflow = this.screen_.cursorPosition.overflow;
rgindac9bc5502012-01-18 11:48:44 -0800769 this.setCursorColumn(this.screenSize.width - 1);
David Benjamin66e954d2012-05-05 21:08:12 -0400770 this.screen_.cursorPosition.overflow = overflow;
rginda0f5c0292012-01-13 11:00:13 -0800771};
772
rgindac9bc5502012-01-18 11:48:44 -0800773/**
774 * Move the cursor backward to the previous tab stop, or to the first column
775 * if no previous tab stops are set.
776 */
777hterm.Terminal.prototype.backwardTabStop = function() {
778 var column = this.screen_.cursorPosition.column;
779
780 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
781 if (this.tabStops_[i] < column) {
782 this.setCursorColumn(this.tabStops_[i]);
783 return;
784 }
785 }
786
787 this.setCursorColumn(1);
rginda0f5c0292012-01-13 11:00:13 -0800788};
789
rgindac9bc5502012-01-18 11:48:44 -0800790/**
791 * Set a tab stop at the given column.
792 *
793 * @param {int} column Zero based column.
794 */
795hterm.Terminal.prototype.setTabStop = function(column) {
796 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
797 if (this.tabStops_[i] == column)
798 return;
799
800 if (this.tabStops_[i] < column) {
801 this.tabStops_.splice(i + 1, 0, column);
802 return;
803 }
804 }
805
806 this.tabStops_.splice(0, 0, column);
rginda87b86462011-12-14 13:48:03 -0800807};
808
rgindac9bc5502012-01-18 11:48:44 -0800809/**
810 * Clear the tab stop at the current cursor position.
811 *
812 * No effect if there is no tab stop at the current cursor position.
813 */
814hterm.Terminal.prototype.clearTabStopAtCursor = function() {
815 var column = this.screen_.cursorPosition.column;
816
817 var i = this.tabStops_.indexOf(column);
818 if (i == -1)
819 return;
820
821 this.tabStops_.splice(i, 1);
822};
823
824/**
825 * Clear all tab stops.
826 */
827hterm.Terminal.prototype.clearAllTabStops = function() {
828 this.tabStops_.length = 0;
David Benjamin66e954d2012-05-05 21:08:12 -0400829 this.defaultTabStops = false;
rgindac9bc5502012-01-18 11:48:44 -0800830};
831
832/**
833 * Set up the default tab stops, starting from a given column.
834 *
835 * This sets a tabstop every (column % this.tabWidth) column, starting
David Benjamin66e954d2012-05-05 21:08:12 -0400836 * from the specified column, or 0 if no column is provided. It also flags
837 * future resizes to set them up.
rgindac9bc5502012-01-18 11:48:44 -0800838 *
839 * This does not clear the existing tab stops first, use clearAllTabStops
840 * for that.
841 *
842 * @param {int} opt_start Optional starting zero based starting column, useful
843 * for filling out missing tab stops when the terminal is resized.
844 */
845hterm.Terminal.prototype.setDefaultTabStops = function(opt_start) {
846 var start = opt_start || 0;
847 var w = this.tabWidth;
David Benjamin66e954d2012-05-05 21:08:12 -0400848 // Round start up to a default tab stop.
849 start = start - 1 - ((start - 1) % w) + w;
850 for (var i = start; i < this.screenSize.width; i += w) {
851 this.setTabStop(i);
rgindac9bc5502012-01-18 11:48:44 -0800852 }
David Benjamin66e954d2012-05-05 21:08:12 -0400853
854 this.defaultTabStops = true;
rginda87b86462011-12-14 13:48:03 -0800855};
856
rginda6d397402012-01-17 10:58:29 -0800857/**
858 * Save cursor position and attributes.
859 *
860 * TODO(rginda): Save attributes once we support them.
861 */
rginda87b86462011-12-14 13:48:03 -0800862hterm.Terminal.prototype.saveOptions = function() {
rginda6d397402012-01-17 10:58:29 -0800863 this.savedOptions_.cursor = this.saveCursor();
rgindaa19afe22012-01-25 15:40:22 -0800864 this.savedOptions_.textAttributes = this.screen_.textAttributes.clone();
rginda87b86462011-12-14 13:48:03 -0800865};
866
rginda6d397402012-01-17 10:58:29 -0800867/**
868 * Restore cursor position and attributes.
869 *
870 * TODO(rginda): Restore attributes once we support them.
871 */
rginda87b86462011-12-14 13:48:03 -0800872hterm.Terminal.prototype.restoreOptions = function() {
rginda6d397402012-01-17 10:58:29 -0800873 if (this.savedOptions_.cursor)
874 this.restoreCursor(this.savedOptions_.cursor);
rgindaa19afe22012-01-25 15:40:22 -0800875 if (this.savedOptions_.textAttributes)
876 this.screen_.textAttributes = this.savedOptions_.textAttributes;
rginda8ba33642011-12-14 12:31:31 -0800877};
878
879/**
880 * Interpret a sequence of characters.
881 *
882 * Incomplete escape sequences are buffered until the next call.
883 *
884 * @param {string} str Sequence of characters to interpret or pass through.
885 */
886hterm.Terminal.prototype.interpret = function(str) {
rginda0f5c0292012-01-13 11:00:13 -0800887 this.vt.interpret(str);
rginda8ba33642011-12-14 12:31:31 -0800888 this.scheduleSyncCursorPosition_();
889};
890
891/**
892 * Take over the given DIV for use as the terminal display.
893 *
894 * @param {HTMLDivElement} div The div to use as the terminal display.
895 */
896hterm.Terminal.prototype.decorate = function(div) {
rginda87b86462011-12-14 13:48:03 -0800897 this.div_ = div;
898
rginda8ba33642011-12-14 12:31:31 -0800899 this.scrollPort_.decorate(div);
rginda30f20f62012-04-05 16:36:19 -0700900 this.scrollPort_.setBackgroundImage(this.prefs_.get('background-image'));
Philip Douglass959b49d2012-05-30 13:29:29 -0400901 this.scrollPort_.setBackgroundSize(this.prefs_.get('background-size'));
902 this.scrollPort_.setBackgroundPosition(
903 this.prefs_.get('background-position'));
rginda30f20f62012-04-05 16:36:19 -0700904
rginda0918b652012-04-04 11:26:24 -0700905 this.div_.focus = this.focus.bind(this);
rgindaf7521392012-02-28 17:20:34 -0800906
rginda9f5222b2012-03-05 11:53:28 -0800907 this.setFontSize(this.prefs_.get('font-size'));
908 this.syncFontFamily();
rgindaa19afe22012-01-25 15:40:22 -0800909
David Reveman8f552492012-03-28 12:18:41 -0400910 this.setScrollbarVisible(this.prefs_.get('scrollbar-visible'));
911
rginda8ba33642011-12-14 12:31:31 -0800912 this.document_ = this.scrollPort_.getDocument();
913
rginda8ba33642011-12-14 12:31:31 -0800914 this.cursorNode_ = this.document_.createElement('div');
915 this.cursorNode_.style.cssText =
916 ('position: absolute;' +
rginda87b86462011-12-14 13:48:03 -0800917 'top: -99px;' +
918 'display: block;' +
rginda35c456b2012-02-09 17:29:05 -0800919 'width: ' + this.scrollPort_.characterSize.width + 'px;' +
920 'height: ' + this.scrollPort_.characterSize.height + 'px;' +
rginda6d397402012-01-17 10:58:29 -0800921 '-webkit-transition: opacity, background-color 100ms linear;' +
rginda9f5222b2012-03-05 11:53:28 -0800922 'background-color: ' + this.prefs_.get('cursor-color'));
rginda8ba33642011-12-14 12:31:31 -0800923 this.document_.body.appendChild(this.cursorNode_);
924
rgindade84e382012-04-20 15:39:31 -0700925 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
rginda8ba33642011-12-14 12:31:31 -0800926 this.setReverseVideo(false);
rginda87b86462011-12-14 13:48:03 -0800927
rginda87b86462011-12-14 13:48:03 -0800928 this.scrollPort_.focus();
rginda6d397402012-01-17 10:58:29 -0800929 this.scrollPort_.scheduleRedraw();
rginda87b86462011-12-14 13:48:03 -0800930};
931
rginda0918b652012-04-04 11:26:24 -0700932/**
933 * Return the HTML document that contains the terminal DOM nodes.
934 */
rginda87b86462011-12-14 13:48:03 -0800935hterm.Terminal.prototype.getDocument = function() {
936 return this.document_;
rginda8ba33642011-12-14 12:31:31 -0800937};
938
939/**
rginda0918b652012-04-04 11:26:24 -0700940 * Focus the terminal.
941 */
942hterm.Terminal.prototype.focus = function() {
943 this.scrollPort_.focus();
944};
945
946/**
rginda8ba33642011-12-14 12:31:31 -0800947 * Return the HTML Element for a given row index.
948 *
949 * This is a method from the RowProvider interface. The ScrollPort uses
950 * it to fetch rows on demand as they are scrolled into view.
951 *
952 * TODO(rginda): Consider saving scrollback rows as (HTML source, text content)
953 * pairs to conserve memory.
954 *
955 * @param {integer} index The zero-based row index, measured relative to the
956 * start of the scrollback buffer. On-screen rows will always have the
957 * largest indicies.
958 * @return {HTMLElement} The 'x-row' element containing for the requested row.
959 */
960hterm.Terminal.prototype.getRowNode = function(index) {
961 if (index < this.scrollbackRows_.length)
962 return this.scrollbackRows_[index];
963
964 var screenIndex = index - this.scrollbackRows_.length;
965 return this.screen_.rowsArray[screenIndex];
966};
967
968/**
969 * Return the text content for a given range of rows.
970 *
971 * This is a method from the RowProvider interface. The ScrollPort uses
972 * it to fetch text content on demand when the user attempts to copy their
973 * selection to the clipboard.
974 *
975 * @param {integer} start The zero-based row index to start from, measured
976 * relative to the start of the scrollback buffer. On-screen rows will
977 * always have the largest indicies.
978 * @param {integer} end The zero-based row index to end on, measured
979 * relative to the start of the scrollback buffer.
980 * @return {string} A single string containing the text value of the range of
981 * rows. Lines will be newline delimited, with no trailing newline.
982 */
983hterm.Terminal.prototype.getRowsText = function(start, end) {
984 var ary = [];
985 for (var i = start; i < end; i++) {
986 var node = this.getRowNode(i);
987 ary.push(node.textContent);
988 }
989
990 return ary.join('\n');
991};
992
993/**
994 * Return the text content for a given row.
995 *
996 * This is a method from the RowProvider interface. The ScrollPort uses
997 * it to fetch text content on demand when the user attempts to copy their
998 * selection to the clipboard.
999 *
1000 * @param {integer} index The zero-based row index to return, measured
1001 * relative to the start of the scrollback buffer. On-screen rows will
1002 * always have the largest indicies.
1003 * @return {string} A string containing the text value of the selected row.
1004 */
1005hterm.Terminal.prototype.getRowText = function(index) {
1006 var node = this.getRowNode(index);
rginda87b86462011-12-14 13:48:03 -08001007 return node.textContent;
rginda8ba33642011-12-14 12:31:31 -08001008};
1009
1010/**
1011 * Return the total number of rows in the addressable screen and in the
1012 * scrollback buffer of this terminal.
1013 *
1014 * This is a method from the RowProvider interface. The ScrollPort uses
1015 * it to compute the size of the scrollbar.
1016 *
1017 * @return {integer} The number of rows in this terminal.
1018 */
1019hterm.Terminal.prototype.getRowCount = function() {
1020 return this.scrollbackRows_.length + this.screen_.rowsArray.length;
1021};
1022
1023/**
1024 * Create DOM nodes for new rows and append them to the end of the terminal.
1025 *
1026 * This is the only correct way to add a new DOM node for a row. Notice that
1027 * the new row is appended to the bottom of the list of rows, and does not
1028 * require renumbering (of the rowIndex property) of previous rows.
1029 *
1030 * If you think you want a new blank row somewhere in the middle of the
1031 * terminal, look into moveRows_().
1032 *
1033 * This method does not pay attention to vtScrollTop/Bottom, since you should
1034 * be using moveRows() in cases where they would matter.
1035 *
1036 * The cursor will be positioned at column 0 of the first inserted line.
1037 */
1038hterm.Terminal.prototype.appendRows_ = function(count) {
1039 var cursorRow = this.screen_.rowsArray.length;
1040 var offset = this.scrollbackRows_.length + cursorRow;
1041 for (var i = 0; i < count; i++) {
1042 var row = this.document_.createElement('x-row');
1043 row.appendChild(this.document_.createTextNode(''));
1044 row.rowIndex = offset + i;
1045 this.screen_.pushRow(row);
1046 }
1047
1048 var extraRows = this.screen_.rowsArray.length - this.screenSize.height;
1049 if (extraRows > 0) {
1050 var ary = this.screen_.shiftRows(extraRows);
1051 Array.prototype.push.apply(this.scrollbackRows_, ary);
1052 this.scheduleScrollDown_();
1053 }
1054
1055 if (cursorRow >= this.screen_.rowsArray.length)
1056 cursorRow = this.screen_.rowsArray.length - 1;
1057
rginda87b86462011-12-14 13:48:03 -08001058 this.setAbsoluteCursorPosition(cursorRow, 0);
rginda8ba33642011-12-14 12:31:31 -08001059};
1060
1061/**
1062 * Relocate rows from one part of the addressable screen to another.
1063 *
1064 * This is used to recycle rows during VT scrolls (those which are driven
1065 * by VT commands, rather than by the user manipulating the scrollbar.)
1066 *
1067 * In this case, the blank lines scrolled into the scroll region are made of
1068 * the nodes we scrolled off. These have their rowIndex properties carefully
1069 * renumbered so as not to confuse the ScrollPort.
rginda8ba33642011-12-14 12:31:31 -08001070 */
1071hterm.Terminal.prototype.moveRows_ = function(fromIndex, count, toIndex) {
1072 var ary = this.screen_.removeRows(fromIndex, count);
1073 this.screen_.insertRows(toIndex, ary);
1074
1075 var start, end;
1076 if (fromIndex < toIndex) {
1077 start = fromIndex;
rginda87b86462011-12-14 13:48:03 -08001078 end = toIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001079 } else {
1080 start = toIndex;
rginda87b86462011-12-14 13:48:03 -08001081 end = fromIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001082 }
1083
1084 this.renumberRows_(start, end);
rginda2312fff2012-01-05 16:20:52 -08001085 this.scrollPort_.scheduleInvalidate();
rginda8ba33642011-12-14 12:31:31 -08001086};
1087
1088/**
1089 * Renumber the rowIndex property of the given range of rows.
1090 *
1091 * The start and end indicies are relative to the screen, not the scrollback.
1092 * Rows in the scrollback buffer cannot be renumbered. Since they are not
rginda2312fff2012-01-05 16:20:52 -08001093 * addressable (you can't delete them, scroll them, etc), you should have
rginda8ba33642011-12-14 12:31:31 -08001094 * no need to renumber scrollback rows.
1095 */
1096hterm.Terminal.prototype.renumberRows_ = function(start, end) {
1097 var offset = this.scrollbackRows_.length;
1098 for (var i = start; i < end; i++) {
1099 this.screen_.rowsArray[i].rowIndex = offset + i;
1100 }
1101};
1102
1103/**
1104 * Print a string to the terminal.
1105 *
1106 * This respects the current insert and wraparound modes. It will add new lines
1107 * to the end of the terminal, scrolling off the top into the scrollback buffer
1108 * if necessary.
1109 *
1110 * The string is *not* parsed for escape codes. Use the interpret() method if
1111 * that's what you're after.
1112 *
1113 * @param{string} str The string to print.
1114 */
1115hterm.Terminal.prototype.print = function(str) {
rgindaa19afe22012-01-25 15:40:22 -08001116 if (this.options_.wraparound && this.screen_.cursorPosition.overflow)
1117 this.newLine();
rginda2312fff2012-01-05 16:20:52 -08001118
rgindaa19afe22012-01-25 15:40:22 -08001119 if (this.options_.insertMode) {
1120 this.screen_.insertString(str);
1121 } else {
1122 this.screen_.overwriteString(str);
1123 }
1124
1125 var overflow = this.screen_.maybeClipCurrentRow();
1126
1127 if (this.options_.wraparound && overflow) {
1128 var lastColumn;
1129
1130 do {
rginda35c456b2012-02-09 17:29:05 -08001131 this.newLine();
1132 lastColumn = overflow.characterLength;
rgindaa19afe22012-01-25 15:40:22 -08001133
1134 if (!this.options_.insertMode)
1135 this.screen_.deleteChars(overflow.characterLength);
1136
1137 this.screen_.prependNodes(overflow);
rgindaa19afe22012-01-25 15:40:22 -08001138
1139 overflow = this.screen_.maybeClipCurrentRow();
1140 } while (overflow);
1141
1142 this.setCursorColumn(lastColumn);
1143 }
rginda8ba33642011-12-14 12:31:31 -08001144
1145 this.scheduleSyncCursorPosition_();
rginda0f5c0292012-01-13 11:00:13 -08001146
rginda9f5222b2012-03-05 11:53:28 -08001147 if (this.scrollOnOutput_)
rginda0f5c0292012-01-13 11:00:13 -08001148 this.scrollPort_.scrollRowToBottom(this.getRowCount());
rginda8ba33642011-12-14 12:31:31 -08001149};
1150
1151/**
rginda87b86462011-12-14 13:48:03 -08001152 * Set the VT scroll region.
1153 *
rginda87b86462011-12-14 13:48:03 -08001154 * This also resets the cursor position to the absolute (0, 0) position, since
1155 * that's what xterm appears to do.
1156 *
1157 * @param {integer} scrollTop The zero-based top of the scroll region.
1158 * @param {integer} scrollBottom The zero-based bottom of the scroll region,
1159 * inclusive.
1160 */
1161hterm.Terminal.prototype.setVTScrollRegion = function(scrollTop, scrollBottom) {
1162 this.vtScrollTop_ = scrollTop;
1163 this.vtScrollBottom_ = scrollBottom;
rginda87b86462011-12-14 13:48:03 -08001164};
1165
1166/**
rginda8ba33642011-12-14 12:31:31 -08001167 * Return the top row index according to the VT.
1168 *
1169 * This will return 0 unless the terminal has been told to restrict scrolling
1170 * to some lower row. It is used for some VT cursor positioning and scrolling
1171 * commands.
1172 *
1173 * @return {integer} The topmost row in the terminal's scroll region.
1174 */
1175hterm.Terminal.prototype.getVTScrollTop = function() {
1176 if (this.vtScrollTop_ != null)
1177 return this.vtScrollTop_;
1178
1179 return 0;
rginda87b86462011-12-14 13:48:03 -08001180};
rginda8ba33642011-12-14 12:31:31 -08001181
1182/**
1183 * Return the bottom row index according to the VT.
1184 *
1185 * This will return the height of the terminal unless the it has been told to
1186 * restrict scrolling to some higher row. It is used for some VT cursor
1187 * positioning and scrolling commands.
1188 *
1189 * @return {integer} The bottommost row in the terminal's scroll region.
1190 */
1191hterm.Terminal.prototype.getVTScrollBottom = function() {
1192 if (this.vtScrollBottom_ != null)
1193 return this.vtScrollBottom_;
1194
rginda87b86462011-12-14 13:48:03 -08001195 return this.screenSize.height - 1;
rginda8ba33642011-12-14 12:31:31 -08001196}
1197
1198/**
1199 * Process a '\n' character.
1200 *
1201 * If the cursor is on the final row of the terminal this will append a new
1202 * blank row to the screen and scroll the topmost row into the scrollback
1203 * buffer.
1204 *
1205 * Otherwise, this moves the cursor to column zero of the next row.
1206 */
1207hterm.Terminal.prototype.newLine = function() {
1208 if (this.screen_.cursorPosition.row == this.screen_.rowsArray.length - 1) {
rginda87b86462011-12-14 13:48:03 -08001209 // If we're at the end of the screen we need to append a new line and
1210 // scroll the top line into the scrollback buffer.
rginda8ba33642011-12-14 12:31:31 -08001211 this.appendRows_(1);
rginda87b86462011-12-14 13:48:03 -08001212 } else if (this.screen_.cursorPosition.row == this.getVTScrollBottom()) {
1213 // End of the scroll region does not affect the scrollback buffer.
1214 this.vtScrollUp(1);
1215 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
rginda8ba33642011-12-14 12:31:31 -08001216 } else {
rginda87b86462011-12-14 13:48:03 -08001217 // Anywhere else in the screen just moves the cursor.
1218 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
rginda8ba33642011-12-14 12:31:31 -08001219 }
1220};
1221
1222/**
1223 * Like newLine(), except maintain the cursor column.
1224 */
1225hterm.Terminal.prototype.lineFeed = function() {
1226 var column = this.screen_.cursorPosition.column;
1227 this.newLine();
1228 this.setCursorColumn(column);
1229};
1230
1231/**
rginda87b86462011-12-14 13:48:03 -08001232 * If autoCarriageReturn is set then newLine(), else lineFeed().
1233 */
1234hterm.Terminal.prototype.formFeed = function() {
1235 if (this.options_.autoCarriageReturn) {
1236 this.newLine();
1237 } else {
1238 this.lineFeed();
1239 }
1240};
1241
1242/**
1243 * Move the cursor up one row, possibly inserting a blank line.
1244 *
1245 * The cursor column is not changed.
1246 */
1247hterm.Terminal.prototype.reverseLineFeed = function() {
1248 var scrollTop = this.getVTScrollTop();
1249 var currentRow = this.screen_.cursorPosition.row;
1250
1251 if (currentRow == scrollTop) {
1252 this.insertLines(1);
1253 } else {
1254 this.setAbsoluteCursorRow(currentRow - 1);
1255 }
1256};
1257
1258/**
rginda8ba33642011-12-14 12:31:31 -08001259 * Replace all characters to the left of the current cursor with the space
1260 * character.
1261 *
1262 * TODO(rginda): This should probably *remove* the characters (not just replace
1263 * with a space) if there are no characters at or beyond the current cursor
1264 * position. Once it does that, it'll have the same text-attribute related
1265 * issues as hterm.Screen.prototype.clearCursorRow :/
1266 */
1267hterm.Terminal.prototype.eraseToLeft = function() {
rginda87b86462011-12-14 13:48:03 -08001268 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001269 this.setCursorColumn(0);
rginda87b86462011-12-14 13:48:03 -08001270 this.screen_.overwriteString(hterm.getWhitespace(cursor.column + 1));
1271 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001272};
1273
1274/**
David Benjamin684a9b72012-05-01 17:19:58 -04001275 * Erase a given number of characters to the right of the cursor.
rginda8ba33642011-12-14 12:31:31 -08001276 *
1277 * The cursor position is unchanged.
1278 *
1279 * TODO(rginda): Test that this works even when the cursor is positioned beyond
1280 * the end of the text.
1281 *
1282 * TODO(rginda): This likely has text-attribute related troubles similar to the
1283 * todo on hterm.Screen.prototype.clearCursorRow.
David Benjamin684a9b72012-05-01 17:19:58 -04001284 *
1285 * TODO(davidben): Probably better to not add the whitespace to the clipboard
1286 * if erasing to the end of the drawn portion of the line. That said, xterm
1287 * behaves the same here.
rginda8ba33642011-12-14 12:31:31 -08001288 */
1289hterm.Terminal.prototype.eraseToRight = function(opt_count) {
rginda87b86462011-12-14 13:48:03 -08001290 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001291
rginda87b86462011-12-14 13:48:03 -08001292 var maxCount = this.screenSize.width - cursor.column;
David Benjamin684a9b72012-05-01 17:19:58 -04001293 if (opt_count === undefined || opt_count >= maxCount) {
1294 this.screen_.deleteChars(maxCount);
1295 } else {
1296 this.screen_.overwriteString(hterm.getWhitespace(opt_count));
1297 }
rginda87b86462011-12-14 13:48:03 -08001298 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001299 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001300};
1301
1302/**
1303 * Erase the current line.
1304 *
1305 * The cursor position is unchanged.
1306 *
1307 * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which
1308 * has a text-attribute related TODO.
1309 */
1310hterm.Terminal.prototype.eraseLine = function() {
rginda87b86462011-12-14 13:48:03 -08001311 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001312 this.screen_.clearCursorRow();
rginda87b86462011-12-14 13:48:03 -08001313 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001314 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001315};
1316
1317/**
David Benjamina08d78f2012-05-05 00:28:49 -04001318 * Erase all characters from the start of the screen to the current cursor
1319 * position, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001320 *
1321 * The cursor position is unchanged.
1322 *
1323 * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which
1324 * has a text-attribute related TODO.
1325 */
1326hterm.Terminal.prototype.eraseAbove = function() {
rginda87b86462011-12-14 13:48:03 -08001327 var cursor = this.saveCursor();
1328
1329 this.eraseToLeft();
rginda8ba33642011-12-14 12:31:31 -08001330
David Benjamina08d78f2012-05-05 00:28:49 -04001331 for (var i = 0; i < cursor.row; i++) {
rginda87b86462011-12-14 13:48:03 -08001332 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001333 this.screen_.clearCursorRow();
1334 }
1335
rginda87b86462011-12-14 13:48:03 -08001336 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001337 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001338};
1339
1340/**
1341 * Erase all characters from the current cursor position to the end of the
David Benjamina08d78f2012-05-05 00:28:49 -04001342 * screen, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001343 *
1344 * The cursor position is unchanged.
1345 *
1346 * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which
1347 * has a text-attribute related TODO.
1348 */
1349hterm.Terminal.prototype.eraseBelow = function() {
rginda87b86462011-12-14 13:48:03 -08001350 var cursor = this.saveCursor();
1351
1352 this.eraseToRight();
rginda8ba33642011-12-14 12:31:31 -08001353
David Benjamina08d78f2012-05-05 00:28:49 -04001354 var bottom = this.screenSize.height - 1;
rginda87b86462011-12-14 13:48:03 -08001355 for (var i = cursor.row + 1; i <= bottom; i++) {
1356 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001357 this.screen_.clearCursorRow();
1358 }
1359
rginda87b86462011-12-14 13:48:03 -08001360 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001361 this.clearCursorOverflow();
rginda87b86462011-12-14 13:48:03 -08001362};
1363
1364/**
1365 * Fill the terminal with a given character.
1366 *
1367 * This methods does not respect the VT scroll region.
1368 *
1369 * @param {string} ch The character to use for the fill.
1370 */
1371hterm.Terminal.prototype.fill = function(ch) {
1372 var cursor = this.saveCursor();
1373
1374 this.setAbsoluteCursorPosition(0, 0);
1375 for (var row = 0; row < this.screenSize.height; row++) {
1376 for (var col = 0; col < this.screenSize.width; col++) {
1377 this.setAbsoluteCursorPosition(row, col);
1378 this.screen_.overwriteString(ch);
1379 }
1380 }
1381
1382 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001383};
1384
1385/**
rginda9ea433c2012-03-16 11:57:00 -07001386 * Erase the entire display and leave the cursor at (0, 0).
rginda8ba33642011-12-14 12:31:31 -08001387 *
rginda9ea433c2012-03-16 11:57:00 -07001388 * This does not respect the scroll region.
1389 *
1390 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1391 * to the current screen.
rginda8ba33642011-12-14 12:31:31 -08001392 *
1393 * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which
1394 * has a text-attribute related TODO.
1395 */
rginda9ea433c2012-03-16 11:57:00 -07001396hterm.Terminal.prototype.clearHome = function(opt_screen) {
1397 var screen = opt_screen || this.screen_;
1398 var bottom = screen.getHeight();
rginda8ba33642011-12-14 12:31:31 -08001399
rginda11057d52012-04-25 12:29:56 -07001400 if (bottom == 0) {
1401 // Empty screen, nothing to do.
1402 return;
1403 }
1404
rgindae4d29232012-01-19 10:47:13 -08001405 for (var i = 0; i < bottom; i++) {
rginda9ea433c2012-03-16 11:57:00 -07001406 screen.setCursorPosition(i, 0);
1407 screen.clearCursorRow();
rginda8ba33642011-12-14 12:31:31 -08001408 }
1409
rginda9ea433c2012-03-16 11:57:00 -07001410 screen.setCursorPosition(0, 0);
1411};
1412
1413/**
1414 * Erase the entire display without changing the cursor position.
1415 *
1416 * The cursor position is unchanged. This does not respect the scroll
1417 * region.
1418 *
1419 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1420 * to the current screen.
1421 *
1422 * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which
1423 * has a text-attribute related TODO.
1424 */
1425hterm.Terminal.prototype.clear = function(opt_screen) {
1426 var screen = opt_screen || this.screen_;
1427 var cursor = screen.cursorPosition.clone();
1428 this.clearHome(screen);
1429 screen.setCursorPosition(cursor.row, cursor.column);
rginda8ba33642011-12-14 12:31:31 -08001430};
1431
1432/**
1433 * VT command to insert lines at the current cursor row.
1434 *
1435 * This respects the current scroll region. Rows pushed off the bottom are
1436 * lost (they won't show up in the scrollback buffer).
1437 *
1438 * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which
1439 * has a text-attribute related TODO.
1440 *
1441 * @param {integer} count The number of lines to insert.
1442 */
1443hterm.Terminal.prototype.insertLines = function(count) {
rginda87b86462011-12-14 13:48:03 -08001444 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001445
1446 var bottom = this.getVTScrollBottom();
rginda87b86462011-12-14 13:48:03 -08001447 count = Math.min(count, bottom - cursor.row);
rginda8ba33642011-12-14 12:31:31 -08001448
rgindae4d29232012-01-19 10:47:13 -08001449 var start = bottom - count + 1;
rginda87b86462011-12-14 13:48:03 -08001450 if (start != cursor.row)
1451 this.moveRows_(start, count, cursor.row);
rginda8ba33642011-12-14 12:31:31 -08001452
1453 for (var i = 0; i < count; i++) {
rginda87b86462011-12-14 13:48:03 -08001454 this.setAbsoluteCursorPosition(cursor.row + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001455 this.screen_.clearCursorRow();
1456 }
1457
rginda87b86462011-12-14 13:48:03 -08001458 cursor.column = 0;
1459 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001460};
1461
1462/**
1463 * VT command to delete lines at the current cursor row.
1464 *
1465 * New rows are added to the bottom of scroll region to take their place. New
1466 * rows are strictly there to take up space and have no content or style.
1467 */
1468hterm.Terminal.prototype.deleteLines = function(count) {
rginda87b86462011-12-14 13:48:03 -08001469 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001470
rginda87b86462011-12-14 13:48:03 -08001471 var top = cursor.row;
rginda8ba33642011-12-14 12:31:31 -08001472 var bottom = this.getVTScrollBottom();
1473
rginda87b86462011-12-14 13:48:03 -08001474 var maxCount = bottom - top + 1;
rginda8ba33642011-12-14 12:31:31 -08001475 count = Math.min(count, maxCount);
1476
rginda87b86462011-12-14 13:48:03 -08001477 var moveStart = bottom - count + 1;
rginda8ba33642011-12-14 12:31:31 -08001478 if (count != maxCount)
1479 this.moveRows_(top, count, moveStart);
1480
1481 for (var i = 0; i < count; i++) {
rginda87b86462011-12-14 13:48:03 -08001482 this.setAbsoluteCursorPosition(moveStart + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001483 this.screen_.clearCursorRow();
1484 }
1485
rginda87b86462011-12-14 13:48:03 -08001486 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001487 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001488};
1489
1490/**
1491 * Inserts the given number of spaces at the current cursor position.
1492 *
rginda87b86462011-12-14 13:48:03 -08001493 * The cursor position is not changed.
rginda8ba33642011-12-14 12:31:31 -08001494 */
1495hterm.Terminal.prototype.insertSpace = function(count) {
rginda87b86462011-12-14 13:48:03 -08001496 var cursor = this.saveCursor();
1497
rginda0f5c0292012-01-13 11:00:13 -08001498 var ws = hterm.getWhitespace(count || 1);
rginda8ba33642011-12-14 12:31:31 -08001499 this.screen_.insertString(ws);
rgindaa19afe22012-01-25 15:40:22 -08001500 this.screen_.maybeClipCurrentRow();
rginda87b86462011-12-14 13:48:03 -08001501
1502 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001503 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001504};
1505
1506/**
1507 * Forward-delete the specified number of characters starting at the cursor
1508 * position.
1509 *
1510 * @param {integer} count The number of characters to delete.
1511 */
1512hterm.Terminal.prototype.deleteChars = function(count) {
1513 this.screen_.deleteChars(count);
David Benjamin54e8bf62012-06-01 22:31:40 -04001514 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001515};
1516
1517/**
1518 * Shift rows in the scroll region upwards by a given number of lines.
1519 *
1520 * New rows are inserted at the bottom of the scroll region to fill the
1521 * vacated rows. The new rows not filled out with the current text attributes.
1522 *
1523 * This function does not affect the scrollback rows at all. Rows shifted
1524 * off the top are lost.
1525 *
rginda87b86462011-12-14 13:48:03 -08001526 * The cursor position is not altered.
1527 *
rginda8ba33642011-12-14 12:31:31 -08001528 * @param {integer} count The number of rows to scroll.
1529 */
1530hterm.Terminal.prototype.vtScrollUp = function(count) {
rginda87b86462011-12-14 13:48:03 -08001531 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001532
rginda87b86462011-12-14 13:48:03 -08001533 this.setAbsoluteCursorRow(this.getVTScrollTop());
rginda8ba33642011-12-14 12:31:31 -08001534 this.deleteLines(count);
1535
rginda87b86462011-12-14 13:48:03 -08001536 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001537};
1538
1539/**
1540 * Shift rows below the cursor down by a given number of lines.
1541 *
1542 * This function respects the current scroll region.
1543 *
1544 * New rows are inserted at the top of the scroll region to fill the
1545 * vacated rows. The new rows not filled out with the current text attributes.
1546 *
1547 * This function does not affect the scrollback rows at all. Rows shifted
1548 * off the bottom are lost.
1549 *
1550 * @param {integer} count The number of rows to scroll.
1551 */
1552hterm.Terminal.prototype.vtScrollDown = function(opt_count) {
rginda87b86462011-12-14 13:48:03 -08001553 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001554
rginda87b86462011-12-14 13:48:03 -08001555 this.setAbsoluteCursorPosition(this.getVTScrollTop(), 0);
rginda8ba33642011-12-14 12:31:31 -08001556 this.insertLines(opt_count);
1557
rginda87b86462011-12-14 13:48:03 -08001558 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001559};
1560
rginda87b86462011-12-14 13:48:03 -08001561
rginda8ba33642011-12-14 12:31:31 -08001562/**
1563 * Set the cursor position.
1564 *
1565 * The cursor row is relative to the scroll region if the terminal has
1566 * 'origin mode' enabled, or relative to the addressable screen otherwise.
1567 *
1568 * @param {integer} row The new zero-based cursor row.
1569 * @param {integer} row The new zero-based cursor column.
1570 */
1571hterm.Terminal.prototype.setCursorPosition = function(row, column) {
1572 if (this.options_.originMode) {
rginda87b86462011-12-14 13:48:03 -08001573 this.setRelativeCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001574 } else {
rginda87b86462011-12-14 13:48:03 -08001575 this.setAbsoluteCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001576 }
rginda87b86462011-12-14 13:48:03 -08001577};
rginda8ba33642011-12-14 12:31:31 -08001578
rginda87b86462011-12-14 13:48:03 -08001579hterm.Terminal.prototype.setRelativeCursorPosition = function(row, column) {
1580 var scrollTop = this.getVTScrollTop();
1581 row = hterm.clamp(row + scrollTop, scrollTop, this.getVTScrollBottom());
rginda2312fff2012-01-05 16:20:52 -08001582 column = hterm.clamp(column, 0, this.screenSize.width - 1);
rginda87b86462011-12-14 13:48:03 -08001583 this.screen_.setCursorPosition(row, column);
1584};
1585
1586hterm.Terminal.prototype.setAbsoluteCursorPosition = function(row, column) {
rginda2312fff2012-01-05 16:20:52 -08001587 row = hterm.clamp(row, 0, this.screenSize.height - 1);
1588 column = hterm.clamp(column, 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08001589 this.screen_.setCursorPosition(row, column);
1590};
1591
1592/**
1593 * Set the cursor column.
1594 *
1595 * @param {integer} column The new zero-based cursor column.
1596 */
1597hterm.Terminal.prototype.setCursorColumn = function(column) {
rginda87b86462011-12-14 13:48:03 -08001598 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, column);
rginda8ba33642011-12-14 12:31:31 -08001599};
1600
1601/**
1602 * Return the cursor column.
1603 *
1604 * @return {integer} The zero-based cursor column.
1605 */
1606hterm.Terminal.prototype.getCursorColumn = function() {
1607 return this.screen_.cursorPosition.column;
1608};
1609
1610/**
1611 * Set the cursor row.
1612 *
1613 * The cursor row is relative to the scroll region if the terminal has
1614 * 'origin mode' enabled, or relative to the addressable screen otherwise.
1615 *
1616 * @param {integer} row The new cursor row.
1617 */
rginda87b86462011-12-14 13:48:03 -08001618hterm.Terminal.prototype.setAbsoluteCursorRow = function(row) {
1619 this.setAbsoluteCursorPosition(row, this.screen_.cursorPosition.column);
rginda8ba33642011-12-14 12:31:31 -08001620};
1621
1622/**
1623 * Return the cursor row.
1624 *
1625 * @return {integer} The zero-based cursor row.
1626 */
1627hterm.Terminal.prototype.getCursorRow = function(row) {
1628 return this.screen_.cursorPosition.row;
1629};
1630
1631/**
1632 * Request that the ScrollPort redraw itself soon.
1633 *
1634 * The redraw will happen asynchronously, soon after the call stack winds down.
1635 * Multiple calls will be coalesced into a single redraw.
1636 */
1637hterm.Terminal.prototype.scheduleRedraw_ = function() {
rginda87b86462011-12-14 13:48:03 -08001638 if (this.timeouts_.redraw)
1639 return;
rginda8ba33642011-12-14 12:31:31 -08001640
1641 var self = this;
rginda87b86462011-12-14 13:48:03 -08001642 this.timeouts_.redraw = setTimeout(function() {
1643 delete self.timeouts_.redraw;
rginda8ba33642011-12-14 12:31:31 -08001644 self.scrollPort_.redraw_();
1645 }, 0);
1646};
1647
1648/**
1649 * Request that the ScrollPort be scrolled to the bottom.
1650 *
1651 * The scroll will happen asynchronously, soon after the call stack winds down.
1652 * Multiple calls will be coalesced into a single scroll.
1653 *
1654 * This affects the scrollbar position of the ScrollPort, and has nothing to
1655 * do with the VT scroll commands.
1656 */
1657hterm.Terminal.prototype.scheduleScrollDown_ = function() {
1658 if (this.timeouts_.scrollDown)
rginda87b86462011-12-14 13:48:03 -08001659 return;
rginda8ba33642011-12-14 12:31:31 -08001660
1661 var self = this;
1662 this.timeouts_.scrollDown = setTimeout(function() {
1663 delete self.timeouts_.scrollDown;
1664 self.scrollPort_.scrollRowToBottom(self.getRowCount());
1665 }, 10);
1666};
1667
1668/**
1669 * Move the cursor up a specified number of rows.
1670 *
1671 * @param {integer} count The number of rows to move the cursor.
1672 */
1673hterm.Terminal.prototype.cursorUp = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001674 return this.cursorDown(-(count || 1));
rginda8ba33642011-12-14 12:31:31 -08001675};
1676
1677/**
1678 * Move the cursor down a specified number of rows.
1679 *
1680 * @param {integer} count The number of rows to move the cursor.
1681 */
1682hterm.Terminal.prototype.cursorDown = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001683 count = count || 1;
rginda8ba33642011-12-14 12:31:31 -08001684 var minHeight = (this.options_.originMode ? this.getVTScrollTop() : 0);
1685 var maxHeight = (this.options_.originMode ? this.getVTScrollBottom() :
1686 this.screenSize.height - 1);
1687
1688 var row = hterm.clamp(this.screen_.cursorPosition.row + count,
1689 minHeight, maxHeight);
rginda87b86462011-12-14 13:48:03 -08001690 this.setAbsoluteCursorRow(row);
rginda8ba33642011-12-14 12:31:31 -08001691};
1692
1693/**
1694 * Move the cursor left a specified number of columns.
1695 *
1696 * @param {integer} count The number of columns to move the cursor.
1697 */
1698hterm.Terminal.prototype.cursorLeft = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001699 return this.cursorRight(-(count || 1));
rginda8ba33642011-12-14 12:31:31 -08001700};
1701
1702/**
1703 * Move the cursor right a specified number of columns.
1704 *
1705 * @param {integer} count The number of columns to move the cursor.
1706 */
1707hterm.Terminal.prototype.cursorRight = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001708 count = count || 1;
rginda8ba33642011-12-14 12:31:31 -08001709 var column = hterm.clamp(this.screen_.cursorPosition.column + count,
rginda87b86462011-12-14 13:48:03 -08001710 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08001711 this.setCursorColumn(column);
1712};
1713
1714/**
1715 * Reverse the foreground and background colors of the terminal.
1716 *
1717 * This only affects text that was drawn with no attributes.
1718 *
1719 * TODO(rginda): Test xterm to see if reverse is respected for text that has
1720 * been drawn with attributes that happen to coincide with the default
1721 * 'no-attribute' colors. My guess is probably not.
1722 */
1723hterm.Terminal.prototype.setReverseVideo = function(state) {
rginda87b86462011-12-14 13:48:03 -08001724 this.options_.reverseVideo = state;
rginda8ba33642011-12-14 12:31:31 -08001725 if (state) {
rginda9f5222b2012-03-05 11:53:28 -08001726 this.scrollPort_.setForegroundColor(this.prefs_.get('background-color'));
1727 this.scrollPort_.setBackgroundColor(this.prefs_.get('foreground-color'));
rginda8ba33642011-12-14 12:31:31 -08001728 } else {
rginda9f5222b2012-03-05 11:53:28 -08001729 this.scrollPort_.setForegroundColor(this.prefs_.get('foreground-color'));
1730 this.scrollPort_.setBackgroundColor(this.prefs_.get('background-color'));
rginda8ba33642011-12-14 12:31:31 -08001731 }
1732};
1733
1734/**
rginda87b86462011-12-14 13:48:03 -08001735 * Ring the terminal bell.
rginda87b86462011-12-14 13:48:03 -08001736 */
1737hterm.Terminal.prototype.ringBell = function() {
rginda9f5222b2012-03-05 11:53:28 -08001738 if (this.bellAudio_.getAttribute('src'))
1739 this.bellAudio_.play();
rgindaf0090c92012-02-10 14:58:52 -08001740
rginda6d397402012-01-17 10:58:29 -08001741 this.cursorNode_.style.backgroundColor =
1742 this.scrollPort_.getForegroundColor();
rginda87b86462011-12-14 13:48:03 -08001743
1744 var self = this;
1745 setTimeout(function() {
rginda9f5222b2012-03-05 11:53:28 -08001746 self.cursorNode_.style.backgroundColor = self.prefs_.get('cursor-color');
rginda6d397402012-01-17 10:58:29 -08001747 }, 200);
rginda87b86462011-12-14 13:48:03 -08001748};
1749
1750/**
rginda8ba33642011-12-14 12:31:31 -08001751 * Set the origin mode bit.
1752 *
1753 * If origin mode is on, certain VT cursor and scrolling commands measure their
1754 * row parameter relative to the VT scroll region. Otherwise, row 0 corresponds
1755 * to the top of the addressable screen.
1756 *
1757 * Defaults to off.
1758 *
1759 * @param {boolean} state True to set origin mode, false to unset.
1760 */
1761hterm.Terminal.prototype.setOriginMode = function(state) {
1762 this.options_.originMode = state;
rgindae4d29232012-01-19 10:47:13 -08001763 this.setCursorPosition(0, 0);
rginda8ba33642011-12-14 12:31:31 -08001764};
1765
1766/**
1767 * Set the insert mode bit.
1768 *
1769 * If insert mode is on, existing text beyond the cursor position will be
1770 * shifted right to make room for new text. Otherwise, new text overwrites
1771 * any existing text.
1772 *
1773 * Defaults to off.
1774 *
1775 * @param {boolean} state True to set insert mode, false to unset.
1776 */
1777hterm.Terminal.prototype.setInsertMode = function(state) {
1778 this.options_.insertMode = state;
1779};
1780
1781/**
rginda87b86462011-12-14 13:48:03 -08001782 * Set the auto carriage return bit.
1783 *
1784 * If auto carriage return is on then a formfeed character is interpreted
1785 * as a newline, otherwise it's the same as a linefeed. The difference boils
1786 * down to whether or not the cursor column is reset.
1787 */
1788hterm.Terminal.prototype.setAutoCarriageReturn = function(state) {
1789 this.options_.autoCarriageReturn = state;
1790};
1791
1792/**
rginda8ba33642011-12-14 12:31:31 -08001793 * Set the wraparound mode bit.
1794 *
1795 * If wraparound mode is on, certain VT commands will allow the cursor to wrap
1796 * to the start of the following row. Otherwise, the cursor is clamped to the
1797 * end of the screen and attempts to write past it are ignored.
1798 *
1799 * Defaults to on.
1800 *
1801 * @param {boolean} state True to set wraparound mode, false to unset.
1802 */
1803hterm.Terminal.prototype.setWraparound = function(state) {
1804 this.options_.wraparound = state;
1805};
1806
1807/**
1808 * Set the reverse-wraparound mode bit.
1809 *
1810 * If wraparound mode is off, certain VT commands will allow the cursor to wrap
1811 * to the end of the previous row. Otherwise, the cursor is clamped to column
1812 * 0.
1813 *
1814 * Defaults to off.
1815 *
1816 * @param {boolean} state True to set reverse-wraparound mode, false to unset.
1817 */
1818hterm.Terminal.prototype.setReverseWraparound = function(state) {
1819 this.options_.reverseWraparound = state;
1820};
1821
1822/**
1823 * Selects between the primary and alternate screens.
1824 *
1825 * If alternate mode is on, the alternate screen is active. Otherwise the
1826 * primary screen is active.
1827 *
1828 * Swapping screens has no effect on the scrollback buffer.
1829 *
1830 * Each screen maintains its own cursor position.
1831 *
1832 * Defaults to off.
1833 *
1834 * @param {boolean} state True to set alternate mode, false to unset.
1835 */
1836hterm.Terminal.prototype.setAlternateMode = function(state) {
rginda6d397402012-01-17 10:58:29 -08001837 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001838 this.screen_ = state ? this.alternateScreen_ : this.primaryScreen_;
1839
rginda35c456b2012-02-09 17:29:05 -08001840 if (this.screen_.rowsArray.length &&
1841 this.screen_.rowsArray[0].rowIndex != this.scrollbackRows_.length) {
1842 // If the screen changed sizes while we were away, our rowIndexes may
1843 // be incorrect.
1844 var offset = this.scrollbackRows_.length;
1845 var ary = this.screen_.rowsArray;
1846 for (i = 0; i < ary.length; i++) {
1847 ary[i].rowIndex = offset + i;
1848 }
1849 }
rginda8ba33642011-12-14 12:31:31 -08001850
rginda35c456b2012-02-09 17:29:05 -08001851 this.realizeWidth_(this.screenSize.width);
1852 this.realizeHeight_(this.screenSize.height);
1853 this.scrollPort_.syncScrollHeight();
1854 this.scrollPort_.invalidate();
rginda8ba33642011-12-14 12:31:31 -08001855
rginda6d397402012-01-17 10:58:29 -08001856 this.restoreCursor(cursor);
rginda35c456b2012-02-09 17:29:05 -08001857 this.scrollPort_.resize();
rginda8ba33642011-12-14 12:31:31 -08001858};
1859
1860/**
1861 * Set the cursor-blink mode bit.
1862 *
1863 * If cursor-blink is on, the cursor will blink when it is visible. Otherwise
1864 * a visible cursor does not blink.
1865 *
1866 * You should make sure to turn blinking off if you're going to dispose of a
1867 * terminal, otherwise you'll leak a timeout.
1868 *
1869 * Defaults to on.
1870 *
1871 * @param {boolean} state True to set cursor-blink mode, false to unset.
1872 */
1873hterm.Terminal.prototype.setCursorBlink = function(state) {
1874 this.options_.cursorBlink = state;
1875
1876 if (!state && this.timeouts_.cursorBlink) {
1877 clearTimeout(this.timeouts_.cursorBlink);
1878 delete this.timeouts_.cursorBlink;
1879 }
1880
1881 if (this.options_.cursorVisible)
1882 this.setCursorVisible(true);
1883};
1884
1885/**
1886 * Set the cursor-visible mode bit.
1887 *
1888 * If cursor-visible is on, the cursor will be visible. Otherwise it will not.
1889 *
1890 * Defaults to on.
1891 *
1892 * @param {boolean} state True to set cursor-visible mode, false to unset.
1893 */
1894hterm.Terminal.prototype.setCursorVisible = function(state) {
1895 this.options_.cursorVisible = state;
1896
1897 if (!state) {
rginda87b86462011-12-14 13:48:03 -08001898 this.cursorNode_.style.opacity = '0';
rginda8ba33642011-12-14 12:31:31 -08001899 return;
1900 }
1901
rginda87b86462011-12-14 13:48:03 -08001902 this.syncCursorPosition_();
1903
1904 this.cursorNode_.style.opacity = '1';
rginda8ba33642011-12-14 12:31:31 -08001905
1906 if (this.options_.cursorBlink) {
1907 if (this.timeouts_.cursorBlink)
1908 return;
1909
1910 this.timeouts_.cursorBlink = setInterval(this.onCursorBlink_.bind(this),
1911 500);
1912 } else {
1913 if (this.timeouts_.cursorBlink) {
1914 clearTimeout(this.timeouts_.cursorBlink);
1915 delete this.timeouts_.cursorBlink;
1916 }
1917 }
1918};
1919
1920/**
rginda87b86462011-12-14 13:48:03 -08001921 * Synchronizes the visible cursor and document selection with the current
1922 * cursor coordinates.
rginda8ba33642011-12-14 12:31:31 -08001923 */
1924hterm.Terminal.prototype.syncCursorPosition_ = function() {
1925 var topRowIndex = this.scrollPort_.getTopRowIndex();
1926 var bottomRowIndex = this.scrollPort_.getBottomRowIndex(topRowIndex);
1927 var cursorRowIndex = this.scrollbackRows_.length +
1928 this.screen_.cursorPosition.row;
1929
1930 if (cursorRowIndex > bottomRowIndex) {
1931 // Cursor is scrolled off screen, move it outside of the visible area.
rginda35c456b2012-02-09 17:29:05 -08001932 this.cursorNode_.style.top = -this.scrollPort_.characterSize.height + 'px';
rginda8ba33642011-12-14 12:31:31 -08001933 return;
1934 }
1935
rginda35c456b2012-02-09 17:29:05 -08001936 this.cursorNode_.style.width = this.scrollPort_.characterSize.width + 'px';
1937 this.cursorNode_.style.height = this.scrollPort_.characterSize.height + 'px';
1938
rginda8ba33642011-12-14 12:31:31 -08001939 this.cursorNode_.style.top = this.scrollPort_.visibleRowTopMargin +
rginda35c456b2012-02-09 17:29:05 -08001940 this.scrollPort_.characterSize.height * (cursorRowIndex - topRowIndex) +
1941 'px';
1942 this.cursorNode_.style.left = this.scrollPort_.characterSize.width *
1943 this.screen_.cursorPosition.column + 'px';
rginda87b86462011-12-14 13:48:03 -08001944
1945 this.cursorNode_.setAttribute('title',
1946 '(' + this.screen_.cursorPosition.row +
1947 ', ' + this.screen_.cursorPosition.column +
1948 ')');
1949
1950 // Update the caret for a11y purposes.
1951 var selection = this.document_.getSelection();
1952 if (selection && selection.isCollapsed)
1953 this.screen_.syncSelectionCaret(selection);
rginda8ba33642011-12-14 12:31:31 -08001954};
1955
1956/**
1957 * Synchronizes the visible cursor with the current cursor coordinates.
1958 *
1959 * The sync will happen asynchronously, soon after the call stack winds down.
1960 * Multiple calls will be coalesced into a single sync.
1961 */
1962hterm.Terminal.prototype.scheduleSyncCursorPosition_ = function() {
1963 if (this.timeouts_.syncCursor)
rginda87b86462011-12-14 13:48:03 -08001964 return;
rginda8ba33642011-12-14 12:31:31 -08001965
1966 var self = this;
1967 this.timeouts_.syncCursor = setTimeout(function() {
1968 self.syncCursorPosition_();
1969 delete self.timeouts_.syncCursor;
rginda87b86462011-12-14 13:48:03 -08001970 }, 0);
1971};
1972
rgindacc2996c2012-02-24 14:59:31 -08001973/**
rgindaf522ce02012-04-17 17:49:17 -07001974 * Show or hide the zoom warning.
1975 *
1976 * The zoom warning is a message warning the user that their browser zoom must
1977 * be set to 100% in order for hterm to function properly.
1978 *
1979 * @param {boolean} state True to show the message, false to hide it.
1980 */
1981hterm.Terminal.prototype.showZoomWarning_ = function(state) {
1982 if (!this.zoomWarningNode_) {
1983 if (!state)
1984 return;
1985
1986 this.zoomWarningNode_ = this.document_.createElement('div');
1987 this.zoomWarningNode_.style.cssText = (
1988 'color: black;' +
1989 'background-color: #ff2222;' +
1990 'font-size: large;' +
1991 'border-radius: 8px;' +
1992 'opacity: 0.75;' +
1993 'padding: 0.2em 0.5em 0.2em 0.5em;' +
1994 'top: 0.5em;' +
1995 'right: 1.2em;' +
1996 'position: absolute;' +
1997 '-webkit-text-size-adjust: none;' +
1998 '-webkit-user-select: none;');
rgindaf522ce02012-04-17 17:49:17 -07001999 }
2000
rgindade84e382012-04-20 15:39:31 -07002001 this.zoomWarningNode_.textContent = hterm.msg('ZOOM_WARNING') ||
2002 ('!! ' + parseInt(this.scrollPort_.characterSize.zoomFactor * 100) +
2003 '% !!');
rgindaf522ce02012-04-17 17:49:17 -07002004 this.zoomWarningNode_.style.fontFamily = this.prefs_.get('font-family');
2005
2006 if (state) {
2007 if (!this.zoomWarningNode_.parentNode)
2008 this.div_.parentNode.appendChild(this.zoomWarningNode_);
2009 } else if (this.zoomWarningNode_.parentNode) {
2010 this.zoomWarningNode_.parentNode.removeChild(this.zoomWarningNode_);
2011 }
2012};
2013
2014/**
rgindacc2996c2012-02-24 14:59:31 -08002015 * Show the terminal overlay for a given amount of time.
2016 *
2017 * The terminal overlay appears in inverse video in a large font, centered
2018 * over the terminal. You should probably keep the overlay message brief,
2019 * since it's in a large font and you probably aren't going to check the size
2020 * of the terminal first.
2021 *
2022 * @param {string} msg The text (not HTML) message to display in the overlay.
2023 * @param {number} opt_timeout The amount of time to wait before fading out
2024 * the overlay. Defaults to 1.5 seconds. Pass null to have the overlay
2025 * stay up forever (or until the next overlay).
2026 */
2027hterm.Terminal.prototype.showOverlay = function(msg, opt_timeout) {
rgindaf0090c92012-02-10 14:58:52 -08002028 if (!this.overlayNode_) {
2029 if (!this.div_)
2030 return;
2031
2032 this.overlayNode_ = this.document_.createElement('div');
2033 this.overlayNode_.style.cssText = (
rgindaf0090c92012-02-10 14:58:52 -08002034 'border-radius: 15px;' +
rgindaf0090c92012-02-10 14:58:52 -08002035 'font-size: xx-large;' +
2036 'opacity: 0.75;' +
2037 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2038 'position: absolute;' +
2039 '-webkit-user-select: none;' +
2040 '-webkit-transition: opacity 180ms ease-in;');
2041 }
2042
rginda9f5222b2012-03-05 11:53:28 -08002043 this.overlayNode_.style.color = this.prefs_.get('background-color');
2044 this.overlayNode_.style.backgroundColor = this.prefs_.get('foreground-color');
2045 this.overlayNode_.style.fontFamily = this.prefs_.get('font-family');
2046
rgindaf0090c92012-02-10 14:58:52 -08002047 this.overlayNode_.textContent = msg;
2048 this.overlayNode_.style.opacity = '0.75';
2049
2050 if (!this.overlayNode_.parentNode)
2051 this.div_.appendChild(this.overlayNode_);
2052
2053 this.overlayNode_.style.top = (
2054 this.div_.clientHeight - this.overlayNode_.clientHeight) / 2;
2055 this.overlayNode_.style.left = (
2056 this.div_.clientWidth - this.overlayNode_.clientWidth -
2057 this.scrollbarWidthPx) / 2;
2058
2059 var self = this;
2060
2061 if (this.overlayTimeout_)
2062 clearTimeout(this.overlayTimeout_);
2063
rgindacc2996c2012-02-24 14:59:31 -08002064 if (opt_timeout === null)
2065 return;
2066
rgindaf0090c92012-02-10 14:58:52 -08002067 this.overlayTimeout_ = setTimeout(function() {
2068 self.overlayNode_.style.opacity = '0';
2069 setTimeout(function() {
rginda259dcca2012-03-14 16:37:11 -07002070 if (self.overlayNode_.parentNode)
2071 self.overlayNode_.parentNode.removeChild(self.overlayNode_);
rgindaf0090c92012-02-10 14:58:52 -08002072 self.overlayTimeout_ = null;
2073 self.overlayNode_.style.opacity = '0.75';
2074 }, 200);
rgindacc2996c2012-02-24 14:59:31 -08002075 }, opt_timeout || 1500);
rgindaf0090c92012-02-10 14:58:52 -08002076};
2077
2078hterm.Terminal.prototype.overlaySize = function() {
2079 this.showOverlay(this.screenSize.width + 'x' + this.screenSize.height);
2080};
2081
rginda87b86462011-12-14 13:48:03 -08002082/**
2083 * Invoked by hterm.Terminal.Keyboard when a VT keystroke is detected.
2084 *
2085 * @param {string} string The VT string representing the keystroke.
2086 */
2087hterm.Terminal.prototype.onVTKeystroke = function(string) {
rginda9f5222b2012-03-05 11:53:28 -08002088 if (this.scrollOnKeystroke_)
rginda87b86462011-12-14 13:48:03 -08002089 this.scrollPort_.scrollRowToBottom(this.getRowCount());
2090
2091 this.io.onVTKeystroke(string);
rginda8ba33642011-12-14 12:31:31 -08002092};
2093
2094/**
2095 * React when the ScrollPort is scrolled.
2096 */
2097hterm.Terminal.prototype.onScroll_ = function() {
2098 this.scheduleSyncCursorPosition_();
2099};
2100
2101/**
rginda9846e2f2012-01-27 13:53:33 -08002102 * React when text is pasted into the scrollPort.
2103 */
2104hterm.Terminal.prototype.onPaste_ = function(e) {
2105 this.io.onVTKeystroke(e.text);
2106};
2107
2108/**
rginda8ba33642011-12-14 12:31:31 -08002109 * React when the ScrollPort is resized.
rgindac9bc5502012-01-18 11:48:44 -08002110 *
2111 * Note: This function should not directly contain code that alters the internal
2112 * state of the terminal. That kind of code belongs in realizeWidth or
2113 * realizeHeight, so that it can be executed synchronously in the case of a
2114 * programmatic width change.
rginda8ba33642011-12-14 12:31:31 -08002115 */
2116hterm.Terminal.prototype.onResize_ = function() {
rgindac9bc5502012-01-18 11:48:44 -08002117 var columnCount = Math.floor(this.scrollPort_.getScreenWidth() /
rginda35c456b2012-02-09 17:29:05 -08002118 this.scrollPort_.characterSize.width);
2119 var rowCount = Math.floor(this.scrollPort_.getScreenHeight() /
2120 this.scrollPort_.characterSize.height);
2121
2122 if (!(columnCount || rowCount)) {
2123 // We avoid these situations since they happen sometimes when the terminal
2124 // gets removed from the document, and we can't deal with that.
2125 return;
2126 }
2127
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +04002128 this.realizeSize_(columnCount, rowCount);
rgindac9bc5502012-01-18 11:48:44 -08002129 this.scheduleSyncCursorPosition_();
rgindaf522ce02012-04-17 17:49:17 -07002130 this.showZoomWarning_(this.scrollPort_.characterSize.zoomFactor != 1);
rgindaf0090c92012-02-10 14:58:52 -08002131 this.overlaySize();
rginda8ba33642011-12-14 12:31:31 -08002132};
2133
2134/**
2135 * Service the cursor blink timeout.
2136 */
2137hterm.Terminal.prototype.onCursorBlink_ = function() {
rginda87b86462011-12-14 13:48:03 -08002138 if (this.cursorNode_.style.opacity == '0') {
2139 this.cursorNode_.style.opacity = '1';
rginda8ba33642011-12-14 12:31:31 -08002140 } else {
rginda87b86462011-12-14 13:48:03 -08002141 this.cursorNode_.style.opacity = '0';
rginda8ba33642011-12-14 12:31:31 -08002142 }
2143};
David Reveman8f552492012-03-28 12:18:41 -04002144
2145/**
2146 * Set the scrollbar-visible mode bit.
2147 *
2148 * If scrollbar-visible is on, the vertical scrollbar will be visible.
2149 * Otherwise it will not.
2150 *
2151 * Defaults to on.
2152 *
2153 * @param {boolean} state True to set scrollbar-visible mode, false to unset.
2154 */
2155hterm.Terminal.prototype.setScrollbarVisible = function(state) {
2156 this.scrollPort_.setScrollbarVisible(state);
2157};