blob: 2443752bdbfcfd1eb70efab9bcb94ddc39a4799b [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
rgindacbbd7482012-06-13 15:06:16 -07005'use strict';
6
Robert Gindab4839c22013-02-28 16:52:10 -08007lib.rtdep('lib.colors', 'lib.PreferenceManager', 'lib.resource',
Robert Ginda57f03b42012-09-13 11:02:48 -07008 'hterm.Keyboard', 'hterm.Options', 'hterm.PreferenceManager',
9 'hterm.Screen', 'hterm.ScrollPort', 'hterm.Size', 'hterm.VT');
rgindacbbd7482012-06-13 15:06:16 -070010
rginda8ba33642011-12-14 12:31:31 -080011/**
12 * Constructor for the Terminal class.
13 *
14 * A Terminal pulls together the hterm.ScrollPort, hterm.Screen and hterm.VT100
15 * classes to provide the complete terminal functionality.
16 *
17 * There are a number of lower-level Terminal methods that can be called
18 * directly to manipulate the cursor, text, scroll region, and other terminal
19 * attributes. However, the primary method is interpret(), which parses VT
20 * escape sequences and invokes the appropriate Terminal methods.
21 *
22 * This class was heavily influenced by Cory Maccarrone's Framebuffer class.
23 *
24 * TODO(rginda): Eventually we're going to need to support characters which are
25 * displayed twice as wide as standard latin characters. This is to support
26 * CJK (and possibly other character sets).
rginda9f5222b2012-03-05 11:53:28 -080027 *
Robert Ginda57f03b42012-09-13 11:02:48 -070028 * @param {string} opt_profileId Optional preference profile name. If not
rginda9f5222b2012-03-05 11:53:28 -080029 * provided, defaults to 'default'.
rginda8ba33642011-12-14 12:31:31 -080030 */
Robert Ginda57f03b42012-09-13 11:02:48 -070031hterm.Terminal = function(opt_profileId) {
32 this.profileId_ = null;
rginda9f5222b2012-03-05 11:53:28 -080033
rginda8ba33642011-12-14 12:31:31 -080034 // Two screen instances.
35 this.primaryScreen_ = new hterm.Screen();
36 this.alternateScreen_ = new hterm.Screen();
37
38 // The "current" screen.
39 this.screen_ = this.primaryScreen_;
40
rginda8ba33642011-12-14 12:31:31 -080041 // The local notion of the screen size. ScreenBuffers also have a size which
42 // indicates their present size. During size changes, the two may disagree.
43 // Also, the inactive screen's size is not altered until it is made the active
44 // screen.
45 this.screenSize = new hterm.Size(0, 0);
46
rginda8ba33642011-12-14 12:31:31 -080047 // The scroll port we'll be using to display the visible rows.
rginda35c456b2012-02-09 17:29:05 -080048 this.scrollPort_ = new hterm.ScrollPort(this);
rginda8ba33642011-12-14 12:31:31 -080049 this.scrollPort_.subscribe('resize', this.onResize_.bind(this));
50 this.scrollPort_.subscribe('scroll', this.onScroll_.bind(this));
rginda9846e2f2012-01-27 13:53:33 -080051 this.scrollPort_.subscribe('paste', this.onPaste_.bind(this));
rgindaa09e7332012-08-17 12:49:51 -070052 this.scrollPort_.onCopy = this.onCopy_.bind(this);
rginda8ba33642011-12-14 12:31:31 -080053
rginda87b86462011-12-14 13:48:03 -080054 // The div that contains this terminal.
55 this.div_ = null;
56
rgindac9bc5502012-01-18 11:48:44 -080057 // The document that contains the scrollPort. Defaulted to the global
58 // document here so that the terminal is functional even if it hasn't been
59 // inserted into a document yet, but re-set in decorate().
60 this.document_ = window.document;
rginda87b86462011-12-14 13:48:03 -080061
rginda8ba33642011-12-14 12:31:31 -080062 // The rows that have scrolled off screen and are no longer addressable.
63 this.scrollbackRows_ = [];
64
rgindac9bc5502012-01-18 11:48:44 -080065 // Saved tab stops.
66 this.tabStops_ = [];
67
David Benjamin66e954d2012-05-05 21:08:12 -040068 // Keep track of whether default tab stops have been erased; after a TBC
69 // clears all tab stops, defaults aren't restored on resize until a reset.
70 this.defaultTabStops = true;
71
rginda8ba33642011-12-14 12:31:31 -080072 // The VT's notion of the top and bottom rows. Used during some VT
73 // cursor positioning and scrolling commands.
74 this.vtScrollTop_ = null;
75 this.vtScrollBottom_ = null;
76
77 // The DIV element for the visible cursor.
78 this.cursorNode_ = null;
79
rginda9f5222b2012-03-05 11:53:28 -080080 // These prefs are cached so we don't have to read from local storage with
Robert Ginda57f03b42012-09-13 11:02:48 -070081 // each output and keystroke. They are initialized by the preference manager.
Robert Ginda8cb7d902013-06-20 14:37:18 -070082 this.backgroundColor_ = null;
83 this.foregroundColor_ = null;
Robert Ginda57f03b42012-09-13 11:02:48 -070084 this.scrollOnOutput_ = null;
85 this.scrollOnKeystroke_ = null;
rginda9f5222b2012-03-05 11:53:28 -080086
rgindaf0090c92012-02-10 14:58:52 -080087 // Terminal bell sound.
88 this.bellAudio_ = this.document_.createElement('audio');
rgindaf0090c92012-02-10 14:58:52 -080089 this.bellAudio_.setAttribute('preload', 'auto');
90
rginda6d397402012-01-17 10:58:29 -080091 // Cursor position and attributes saved with DECSC.
92 this.savedOptions_ = {};
93
rginda8ba33642011-12-14 12:31:31 -080094 // The current mode bits for the terminal.
95 this.options_ = new hterm.Options();
96
97 // Timeouts we might need to clear.
98 this.timeouts_ = {};
rginda87b86462011-12-14 13:48:03 -080099
100 // The VT escape sequence interpreter.
rginda0f5c0292012-01-13 11:00:13 -0800101 this.vt = new hterm.VT(this);
rginda87b86462011-12-14 13:48:03 -0800102
rgindafeaf3142012-01-31 15:14:20 -0800103 // The keyboard hander.
104 this.keyboard = new hterm.Keyboard(this);
105
rginda87b86462011-12-14 13:48:03 -0800106 // General IO interface that can be given to third parties without exposing
107 // the entire terminal object.
108 this.io = new hterm.Terminal.IO(this);
rgindac9bc5502012-01-18 11:48:44 -0800109
rgindad5613292012-06-19 15:40:37 -0700110 // True if mouse-click-drag should scroll the terminal.
111 this.enableMouseDragScroll = true;
112
Robert Ginda57f03b42012-09-13 11:02:48 -0700113 this.copyOnSelect = null;
rginda4bba5e12012-06-20 16:15:30 -0700114 this.mousePasteButton = null;
rginda4bba5e12012-06-20 16:15:30 -0700115
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400116 this.realizeSize_(80, 24);
rgindac9bc5502012-01-18 11:48:44 -0800117 this.setDefaultTabStops();
Robert Ginda57f03b42012-09-13 11:02:48 -0700118
119 this.setProfile(opt_profileId || 'default',
120 function() { this.onTerminalReady() }.bind(this));
rginda87b86462011-12-14 13:48:03 -0800121};
122
123/**
Robert Ginda57f03b42012-09-13 11:02:48 -0700124 * Clients should override this to be notified when the terminal is ready
125 * for use.
126 *
127 * The terminal initialization is asynchronous, and shouldn't be used before
128 * this method is called.
129 */
130hterm.Terminal.prototype.onTerminalReady = function() { };
131
132/**
rginda35c456b2012-02-09 17:29:05 -0800133 * Default tab with of 8 to match xterm.
134 */
135hterm.Terminal.prototype.tabWidth = 8;
136
137/**
rginda9f5222b2012-03-05 11:53:28 -0800138 * Select a preference profile.
139 *
140 * This will load the terminal preferences for the given profile name and
141 * associate subsequent preference changes with the new preference profile.
142 *
143 * @param {string} newName The name of the preference profile. Forward slash
144 * characters will be removed from the name.
Robert Ginda57f03b42012-09-13 11:02:48 -0700145 * @param {function} opt_callback Optional callback to invoke when the profile
146 * transition is complete.
rginda9f5222b2012-03-05 11:53:28 -0800147 */
Robert Ginda57f03b42012-09-13 11:02:48 -0700148hterm.Terminal.prototype.setProfile = function(profileId, opt_callback) {
149 this.profileId_ = profileId.replace(/\//g, '');
rginda9f5222b2012-03-05 11:53:28 -0800150
Robert Ginda57f03b42012-09-13 11:02:48 -0700151 var terminal = this;
rginda9f5222b2012-03-05 11:53:28 -0800152
Robert Ginda57f03b42012-09-13 11:02:48 -0700153 if (this.prefs_)
154 this.prefs_.deactivate();
rginda9f5222b2012-03-05 11:53:28 -0800155
Robert Ginda57f03b42012-09-13 11:02:48 -0700156 this.prefs_ = new hterm.PreferenceManager(this.profileId_);
157 this.prefs_.addObservers(null, {
Andrew de los Reyes574e10e2013-04-04 09:31:57 -0700158 'alt-backspace-is-meta-backspace': function(v) {
159 terminal.keyboard.altBackspaceIsMetaBackspace = v;
160 },
161
Robert Ginda57f03b42012-09-13 11:02:48 -0700162 'alt-is-meta': function(v) {
163 terminal.keyboard.altIsMeta = v;
164 },
165
166 'alt-sends-what': function(v) {
167 if (!/^(escape|8-bit|browser-key)$/.test(v))
168 v = 'escape';
169
170 terminal.keyboard.altSendsWhat = v;
171 },
172
173 'audible-bell-sound': function(v) {
Robert Gindab4839c22013-02-28 16:52:10 -0800174 var ary = v.match(/^lib-resource:(\S+)/);
175 if (ary) {
176 terminal.bellAudio_.setAttribute('src',
177 lib.resource.getDataUrl(ary[1]));
178 } else {
179 terminal.bellAudio_.setAttribute('src', v);
180 }
Robert Ginda57f03b42012-09-13 11:02:48 -0700181 },
182
183 'background-color': function(v) {
184 terminal.setBackgroundColor(v);
185 },
186
187 'background-image': function(v) {
188 terminal.scrollPort_.setBackgroundImage(v);
189 },
190
191 'background-size': function(v) {
192 terminal.scrollPort_.setBackgroundSize(v);
193 },
194
195 'background-position': function(v) {
196 terminal.scrollPort_.setBackgroundPosition(v);
197 },
198
199 'backspace-sends-backspace': function(v) {
200 terminal.keyboard.backspaceSendsBackspace = v;
201 },
202
203 'cursor-blink': function(v) {
204 terminal.setCursorBlink(!!v);
205 },
206
207 'cursor-color': function(v) {
208 terminal.setCursorColor(v);
209 },
210
211 'color-palette-overrides': function(v) {
212 if (!(v == null || v instanceof Object || v instanceof Array)) {
213 console.warn('Preference color-palette-overrides is not an array or ' +
214 'object: ' + v);
215 return;
rginda9f5222b2012-03-05 11:53:28 -0800216 }
rginda9f5222b2012-03-05 11:53:28 -0800217
Robert Ginda57f03b42012-09-13 11:02:48 -0700218 lib.colors.colorPalette = lib.colors.stockColorPalette.concat();
rginda39bdf6f2012-04-10 16:50:55 -0700219
Robert Ginda57f03b42012-09-13 11:02:48 -0700220 if (v) {
221 for (var key in v) {
222 var i = parseInt(key);
223 if (isNaN(i) || i < 0 || i > 255) {
224 console.log('Invalid value in palette: ' + key + ': ' + v[key]);
225 continue;
226 }
227
228 if (v[i]) {
229 var rgb = lib.colors.normalizeCSS(v[i]);
230 if (rgb)
231 lib.colors.colorPalette[i] = rgb;
232 }
233 }
rginda30f20f62012-04-05 16:36:19 -0700234 }
rginda30f20f62012-04-05 16:36:19 -0700235
Robert Ginda57f03b42012-09-13 11:02:48 -0700236 terminal.primaryScreen_.textAttributes.resetColorPalette()
237 terminal.alternateScreen_.textAttributes.resetColorPalette();
238 },
rginda30f20f62012-04-05 16:36:19 -0700239
Robert Ginda57f03b42012-09-13 11:02:48 -0700240 'copy-on-select': function(v) {
241 terminal.copyOnSelect = !!v;
242 },
rginda9f5222b2012-03-05 11:53:28 -0800243
Robert Ginda57f03b42012-09-13 11:02:48 -0700244 'enable-8-bit-control': function(v) {
245 terminal.vt.enable8BitControl = !!v;
246 },
rginda30f20f62012-04-05 16:36:19 -0700247
Robert Ginda57f03b42012-09-13 11:02:48 -0700248 'enable-bold': function(v) {
249 terminal.syncBoldSafeState();
250 },
Philip Douglass959b49d2012-05-30 13:29:29 -0400251
Robert Ginda57f03b42012-09-13 11:02:48 -0700252 'enable-clipboard-write': function(v) {
253 terminal.vt.enableClipboardWrite = !!v;
254 },
Philip Douglass959b49d2012-05-30 13:29:29 -0400255
Robert Ginda3755e752013-05-31 13:34:09 -0700256 'enable-dec12': function(v) {
257 terminal.vt.enableDec12 = !!v;
258 },
259
Robert Ginda57f03b42012-09-13 11:02:48 -0700260 'font-family': function(v) {
261 terminal.syncFontFamily();
262 },
rginda30f20f62012-04-05 16:36:19 -0700263
Robert Ginda57f03b42012-09-13 11:02:48 -0700264 'font-size': function(v) {
265 terminal.setFontSize(v);
266 },
rginda9875d902012-08-20 16:21:57 -0700267
Robert Ginda57f03b42012-09-13 11:02:48 -0700268 'font-smoothing': function(v) {
269 terminal.syncFontFamily();
270 },
rgindade84e382012-04-20 15:39:31 -0700271
Robert Ginda57f03b42012-09-13 11:02:48 -0700272 'foreground-color': function(v) {
273 terminal.setForegroundColor(v);
274 },
rginda30f20f62012-04-05 16:36:19 -0700275
Robert Ginda57f03b42012-09-13 11:02:48 -0700276 'home-keys-scroll': function(v) {
277 terminal.keyboard.homeKeysScroll = v;
278 },
rginda4bba5e12012-06-20 16:15:30 -0700279
Robert Ginda57f03b42012-09-13 11:02:48 -0700280 'max-string-sequence': function(v) {
281 terminal.vt.maxStringSequence = v;
282 },
rginda11057d52012-04-25 12:29:56 -0700283
Andrew de los Reyes6af23ae2013-04-04 14:17:50 -0700284 'media-keys-are-fkeys': function(v) {
285 terminal.keyboard.mediaKeysAreFKeys = v;
286 },
287
Robert Ginda57f03b42012-09-13 11:02:48 -0700288 'meta-sends-escape': function(v) {
289 terminal.keyboard.metaSendsEscape = v;
290 },
rginda30f20f62012-04-05 16:36:19 -0700291
Robert Ginda57f03b42012-09-13 11:02:48 -0700292 'mouse-cell-motion-trick': function(v) {
293 terminal.vt.setMouseCellMotionTrick(v);
294 },
Robert Ginda9fb38222012-09-11 14:19:12 -0700295
Robert Ginda57f03b42012-09-13 11:02:48 -0700296 'mouse-paste-button': function(v) {
297 terminal.syncMousePasteButton();
298 },
rgindaa8ba17d2012-08-15 14:41:10 -0700299
Robert Ginda40932892012-12-10 17:26:40 -0800300 'pass-alt-number': function(v) {
301 if (v == null) {
302 var osx = window.navigator.userAgent.match(/Mac OS X/);
303
304 // Let Alt-1..9 pass to the browser (to control tab switching) on
305 // non-OS X systems, or if hterm is not opened in an app window.
306 v = (!osx && hterm.windowType != 'popup');
307 }
308
309 terminal.passAltNumber = v;
310 },
311
312 'pass-ctrl-number': function(v) {
313 if (v == null) {
314 var osx = window.navigator.userAgent.match(/Mac OS X/);
315
316 // Let Ctrl-1..9 pass to the browser (to control tab switching) on
317 // non-OS X systems, or if hterm is not opened in an app window.
318 v = (!osx && hterm.windowType != 'popup');
319 }
320
321 terminal.passCtrlNumber = v;
322 },
323
324 'pass-meta-number': function(v) {
325 if (v == null) {
326 var osx = window.navigator.userAgent.match(/Mac OS X/);
327
328 // Let Meta-1..9 pass to the browser (to control tab switching) on
329 // OS X systems, or if hterm is not opened in an app window.
330 v = (osx && hterm.windowType != 'popup');
331 }
332
333 terminal.passMetaNumber = v;
334 },
335
Robert Ginda8cb7d902013-06-20 14:37:18 -0700336 'receive-encoding': function(v) {
337 if (!(/^(utf-8|raw)$/).test(v)) {
338 console.warn('Invalid value for "receive-encoding": ' + v);
339 v = 'utf-8';
340 }
341
342 terminal.vt.characterEncoding = v;
343 },
344
Robert Ginda57f03b42012-09-13 11:02:48 -0700345 'scroll-on-keystroke': function(v) {
346 terminal.scrollOnKeystroke_ = v;
347 },
rginda9f5222b2012-03-05 11:53:28 -0800348
Robert Ginda57f03b42012-09-13 11:02:48 -0700349 'scroll-on-output': function(v) {
350 terminal.scrollOnOutput_ = v;
351 },
rginda30f20f62012-04-05 16:36:19 -0700352
Robert Ginda57f03b42012-09-13 11:02:48 -0700353 'scrollbar-visible': function(v) {
354 terminal.setScrollbarVisible(v);
355 },
rginda9f5222b2012-03-05 11:53:28 -0800356
Robert Ginda8cb7d902013-06-20 14:37:18 -0700357 'send-encoding': function(v) {
358 if (!(/^(utf-8|raw)$/).test(v)) {
359 console.warn('Invalid value for "send-encoding": ' + v);
360 v = 'utf-8';
361 }
362
363 terminal.keyboard.characterEncoding = v;
364 },
365
Robert Ginda57f03b42012-09-13 11:02:48 -0700366 'shift-insert-paste': function(v) {
367 terminal.keyboard.shiftInsertPaste = v;
368 },
rginda9f5222b2012-03-05 11:53:28 -0800369
Robert Ginda57f03b42012-09-13 11:02:48 -0700370 'page-keys-scroll': function(v) {
371 terminal.keyboard.pageKeysScroll = v;
372 }
373 });
rginda30f20f62012-04-05 16:36:19 -0700374
Robert Ginda57f03b42012-09-13 11:02:48 -0700375 this.prefs_.readStorage(function() {
rginda9f5222b2012-03-05 11:53:28 -0800376 this.prefs_.notifyAll();
Robert Ginda57f03b42012-09-13 11:02:48 -0700377
378 if (opt_callback)
379 opt_callback();
380 }.bind(this));
rginda9f5222b2012-03-05 11:53:28 -0800381};
382
rginda8e92a692012-05-20 19:37:20 -0700383/**
384 * Set the color for the cursor.
385 *
386 * If you want this setting to persist, set it through prefs_, rather than
387 * with this method.
388 */
389hterm.Terminal.prototype.setCursorColor = function(color) {
390 this.cursorNode_.style.backgroundColor = color;
391 this.cursorNode_.style.borderColor = color;
392};
393
394/**
395 * Return the current cursor color as a string.
396 */
397hterm.Terminal.prototype.getCursorColor = function() {
398 return this.cursorNode_.style.backgroundColor;
399};
400
401/**
rgindad5613292012-06-19 15:40:37 -0700402 * Enable or disable mouse based text selection in the terminal.
403 */
404hterm.Terminal.prototype.setSelectionEnabled = function(state) {
405 this.enableMouseDragScroll = state;
406 this.scrollPort_.setSelectionEnabled(state);
407};
408
409/**
rginda8e92a692012-05-20 19:37:20 -0700410 * Set the background color.
411 *
412 * If you want this setting to persist, set it through prefs_, rather than
413 * with this method.
414 */
415hterm.Terminal.prototype.setBackgroundColor = function(color) {
rgindacbbd7482012-06-13 15:06:16 -0700416 this.backgroundColor_ = lib.colors.normalizeCSS(color);
Robert Ginda57f03b42012-09-13 11:02:48 -0700417 this.primaryScreen_.textAttributes.setDefaults(
418 this.foregroundColor_, this.backgroundColor_);
419 this.alternateScreen_.textAttributes.setDefaults(
420 this.foregroundColor_, this.backgroundColor_);
rginda8e92a692012-05-20 19:37:20 -0700421 this.scrollPort_.setBackgroundColor(color);
422};
423
rginda9f5222b2012-03-05 11:53:28 -0800424/**
425 * Return the current terminal background color.
426 *
427 * Intended for use by other classes, so we don't have to expose the entire
428 * prefs_ object.
429 */
430hterm.Terminal.prototype.getBackgroundColor = function() {
rginda8e92a692012-05-20 19:37:20 -0700431 return this.backgroundColor_;
432};
433
434/**
435 * Set the foreground color.
436 *
437 * If you want this setting to persist, set it through prefs_, rather than
438 * with this method.
439 */
440hterm.Terminal.prototype.setForegroundColor = function(color) {
rgindacbbd7482012-06-13 15:06:16 -0700441 this.foregroundColor_ = lib.colors.normalizeCSS(color);
Robert Ginda57f03b42012-09-13 11:02:48 -0700442 this.primaryScreen_.textAttributes.setDefaults(
443 this.foregroundColor_, this.backgroundColor_);
444 this.alternateScreen_.textAttributes.setDefaults(
445 this.foregroundColor_, this.backgroundColor_);
rginda8e92a692012-05-20 19:37:20 -0700446 this.scrollPort_.setForegroundColor(color);
rginda9f5222b2012-03-05 11:53:28 -0800447};
448
449/**
450 * Return the current terminal foreground color.
451 *
452 * Intended for use by other classes, so we don't have to expose the entire
453 * prefs_ object.
454 */
455hterm.Terminal.prototype.getForegroundColor = function() {
rginda8e92a692012-05-20 19:37:20 -0700456 return this.foregroundColor_;
rginda9f5222b2012-03-05 11:53:28 -0800457};
458
459/**
rginda87b86462011-12-14 13:48:03 -0800460 * Create a new instance of a terminal command and run it with a given
461 * argument string.
462 *
463 * @param {function} commandClass The constructor for a terminal command.
464 * @param {string} argString The argument string to pass to the command.
465 */
466hterm.Terminal.prototype.runCommandClass = function(commandClass, argString) {
rgindaf522ce02012-04-17 17:49:17 -0700467 var environment = this.prefs_.get('environment');
468 if (typeof environment != 'object' || environment == null)
469 environment = {};
470
rginda87b86462011-12-14 13:48:03 -0800471 var self = this;
472 this.command = new commandClass(
473 { argString: argString || '',
474 io: this.io.push(),
rgindaf522ce02012-04-17 17:49:17 -0700475 environment: environment,
rginda87b86462011-12-14 13:48:03 -0800476 onExit: function(code) {
477 self.io.pop();
rgindafeaf3142012-01-31 15:14:20 -0800478 self.uninstallKeyboard();
rginda9875d902012-08-20 16:21:57 -0700479 if (self.prefs_.get('close-on-exit'))
480 window.close();
rginda87b86462011-12-14 13:48:03 -0800481 }
482 });
483
rgindafeaf3142012-01-31 15:14:20 -0800484 this.installKeyboard();
rginda87b86462011-12-14 13:48:03 -0800485 this.command.run();
486};
487
488/**
rgindafeaf3142012-01-31 15:14:20 -0800489 * Returns true if the current screen is the primary screen, false otherwise.
490 */
491hterm.Terminal.prototype.isPrimaryScreen = function() {
rgindaf522ce02012-04-17 17:49:17 -0700492 return this.screen_ == this.primaryScreen_;
rgindafeaf3142012-01-31 15:14:20 -0800493};
494
495/**
496 * Install the keyboard handler for this terminal.
497 *
498 * This will prevent the browser from seeing any keystrokes sent to the
499 * terminal.
500 */
501hterm.Terminal.prototype.installKeyboard = function() {
502 this.keyboard.installKeyboard(this.document_.body.firstChild);
503}
504
505/**
506 * Uninstall the keyboard handler for this terminal.
507 */
508hterm.Terminal.prototype.uninstallKeyboard = function() {
509 this.keyboard.installKeyboard(null);
510}
511
512/**
rginda35c456b2012-02-09 17:29:05 -0800513 * Set the font size for this terminal.
rginda9f5222b2012-03-05 11:53:28 -0800514 *
515 * Call setFontSize(0) to reset to the default font size.
516 *
517 * This function does not modify the font-size preference.
518 *
519 * @param {number} px The desired font size, in pixels.
rginda35c456b2012-02-09 17:29:05 -0800520 */
521hterm.Terminal.prototype.setFontSize = function(px) {
rginda9f5222b2012-03-05 11:53:28 -0800522 if (px === 0)
523 px = this.prefs_.get('font-size');
524
rginda35c456b2012-02-09 17:29:05 -0800525 this.scrollPort_.setFontSize(px);
526};
527
528/**
529 * Get the current font size.
530 */
531hterm.Terminal.prototype.getFontSize = function() {
532 return this.scrollPort_.getFontSize();
533};
534
535/**
rginda8e92a692012-05-20 19:37:20 -0700536 * Get the current font family.
537 */
538hterm.Terminal.prototype.getFontFamily = function() {
539 return this.scrollPort_.getFontFamily();
540};
541
542/**
rginda35c456b2012-02-09 17:29:05 -0800543 * Set the CSS "font-family" for this terminal.
544 */
rginda9f5222b2012-03-05 11:53:28 -0800545hterm.Terminal.prototype.syncFontFamily = function() {
546 this.scrollPort_.setFontFamily(this.prefs_.get('font-family'),
547 this.prefs_.get('font-smoothing'));
548 this.syncBoldSafeState();
549};
550
rginda4bba5e12012-06-20 16:15:30 -0700551/**
552 * Set this.mousePasteButton based on the mouse-paste-button pref,
553 * autodetecting if necessary.
554 */
555hterm.Terminal.prototype.syncMousePasteButton = function() {
556 var button = this.prefs_.get('mouse-paste-button');
557 if (typeof button == 'number') {
558 this.mousePasteButton = button;
559 return;
560 }
561
562 var ary = navigator.userAgent.match(/\(X11;\s+(\S+)/);
563 if (!ary || ary[2] == 'CrOS') {
564 this.mousePasteButton = 2;
565 } else {
566 this.mousePasteButton = 3;
567 }
568};
569
570/**
571 * Enable or disable bold based on the enable-bold pref, autodetecting if
572 * necessary.
573 */
rginda9f5222b2012-03-05 11:53:28 -0800574hterm.Terminal.prototype.syncBoldSafeState = function() {
575 var enableBold = this.prefs_.get('enable-bold');
576 if (enableBold !== null) {
Robert Gindaed016262012-10-26 16:27:09 -0700577 this.primaryScreen_.textAttributes.enableBold = enableBold;
578 this.alternateScreen_.textAttributes.enableBold = enableBold;
rginda9f5222b2012-03-05 11:53:28 -0800579 return;
580 }
581
rgindaf7521392012-02-28 17:20:34 -0800582 var normalSize = this.scrollPort_.measureCharacterSize();
583 var boldSize = this.scrollPort_.measureCharacterSize('bold');
584
585 var isBoldSafe = normalSize.equals(boldSize);
rgindaf7521392012-02-28 17:20:34 -0800586 if (!isBoldSafe) {
587 console.warn('Bold characters disabled: Size of bold weight differs ' +
rgindac9759de2012-03-19 13:21:41 -0700588 'from normal. Font family is: ' +
589 this.scrollPort_.getFontFamily());
rgindaf7521392012-02-28 17:20:34 -0800590 }
rginda9f5222b2012-03-05 11:53:28 -0800591
Robert Gindaed016262012-10-26 16:27:09 -0700592 this.primaryScreen_.textAttributes.enableBold = isBoldSafe;
593 this.alternateScreen_.textAttributes.enableBold = isBoldSafe;
rginda35c456b2012-02-09 17:29:05 -0800594};
595
596/**
rginda87b86462011-12-14 13:48:03 -0800597 * Return a copy of the current cursor position.
598 *
599 * @return {hterm.RowCol} The RowCol object representing the current position.
600 */
601hterm.Terminal.prototype.saveCursor = function() {
602 return this.screen_.cursorPosition.clone();
603};
604
rgindaa19afe22012-01-25 15:40:22 -0800605hterm.Terminal.prototype.getTextAttributes = function() {
606 return this.screen_.textAttributes;
607};
608
rginda1a09aa02012-06-18 21:11:25 -0700609hterm.Terminal.prototype.setTextAttributes = function(textAttributes) {
610 this.screen_.textAttributes = textAttributes;
611};
612
rginda87b86462011-12-14 13:48:03 -0800613/**
rgindaf522ce02012-04-17 17:49:17 -0700614 * Return the current browser zoom factor applied to the terminal.
615 *
616 * @return {number} The current browser zoom factor.
617 */
618hterm.Terminal.prototype.getZoomFactor = function() {
619 return this.scrollPort_.characterSize.zoomFactor;
620};
621
622/**
rginda9846e2f2012-01-27 13:53:33 -0800623 * Change the title of this terminal's window.
624 */
625hterm.Terminal.prototype.setWindowTitle = function(title) {
rgindafeaf3142012-01-31 15:14:20 -0800626 window.document.title = title;
rginda9846e2f2012-01-27 13:53:33 -0800627};
628
629/**
rginda87b86462011-12-14 13:48:03 -0800630 * Restore a previously saved cursor position.
631 *
632 * @param {hterm.RowCol} cursor The position to restore.
633 */
634hterm.Terminal.prototype.restoreCursor = function(cursor) {
rgindacbbd7482012-06-13 15:06:16 -0700635 var row = lib.f.clamp(cursor.row, 0, this.screenSize.height - 1);
636 var column = lib.f.clamp(cursor.column, 0, this.screenSize.width - 1);
rginda35c456b2012-02-09 17:29:05 -0800637 this.screen_.setCursorPosition(row, column);
638 if (cursor.column > column ||
639 cursor.column == column && cursor.overflow) {
640 this.screen_.cursorPosition.overflow = true;
641 }
rginda87b86462011-12-14 13:48:03 -0800642};
643
644/**
David Benjamin54e8bf62012-06-01 22:31:40 -0400645 * Clear the cursor's overflow flag.
646 */
647hterm.Terminal.prototype.clearCursorOverflow = function() {
648 this.screen_.cursorPosition.overflow = false;
649};
650
651/**
rginda87b86462011-12-14 13:48:03 -0800652 * Set the width of the terminal, resizing the UI to match.
653 */
654hterm.Terminal.prototype.setWidth = function(columnCount) {
rgindaf0090c92012-02-10 14:58:52 -0800655 if (columnCount == null) {
656 this.div_.style.width = '100%';
657 return;
658 }
659
rginda35c456b2012-02-09 17:29:05 -0800660 this.div_.style.width = this.scrollPort_.characterSize.width *
Robert Ginda97769282013-02-01 15:30:30 -0800661 columnCount + this.scrollPort_.currentScrollbarWidthPx + 'px';
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400662 this.realizeSize_(columnCount, this.screenSize.height);
rgindac9bc5502012-01-18 11:48:44 -0800663 this.scheduleSyncCursorPosition_();
664};
rginda87b86462011-12-14 13:48:03 -0800665
rgindac9bc5502012-01-18 11:48:44 -0800666/**
rginda35c456b2012-02-09 17:29:05 -0800667 * Set the height of the terminal, resizing the UI to match.
668 */
669hterm.Terminal.prototype.setHeight = function(rowCount) {
rgindaf0090c92012-02-10 14:58:52 -0800670 if (rowCount == null) {
671 this.div_.style.height = '100%';
672 return;
673 }
674
rginda35c456b2012-02-09 17:29:05 -0800675 this.div_.style.height =
rginda30f20f62012-04-05 16:36:19 -0700676 this.scrollPort_.characterSize.height * rowCount + 'px';
rginda35c456b2012-02-09 17:29:05 -0800677 this.realizeSize_(this.screenSize.width, rowCount);
678 this.scheduleSyncCursorPosition_();
679};
680
681/**
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400682 * Deal with terminal size changes.
683 *
684 */
685hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) {
686 if (columnCount != this.screenSize.width)
687 this.realizeWidth_(columnCount);
688
689 if (rowCount != this.screenSize.height)
690 this.realizeHeight_(rowCount);
691
692 // Send new terminal size to plugin.
Robert Gindae81427f2013-05-24 10:34:46 -0700693 this.io.onTerminalResize_(columnCount, rowCount);
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400694};
695
696/**
rgindac9bc5502012-01-18 11:48:44 -0800697 * Deal with terminal width changes.
698 *
699 * This function does what needs to be done when the terminal width changes
700 * out from under us. It happens here rather than in onResize_() because this
701 * code may need to run synchronously to handle programmatic changes of
702 * terminal width.
703 *
704 * Relying on the browser to send us an async resize event means we may not be
705 * in the correct state yet when the next escape sequence hits.
706 */
707hterm.Terminal.prototype.realizeWidth_ = function(columnCount) {
Robert Ginda4e83f3a2012-09-04 15:25:25 -0700708 if (columnCount <= 0)
709 throw new Error('Attempt to realize bad width: ' + columnCount);
710
rgindac9bc5502012-01-18 11:48:44 -0800711 var deltaColumns = columnCount - this.screen_.getWidth();
712
rginda87b86462011-12-14 13:48:03 -0800713 this.screenSize.width = columnCount;
714 this.screen_.setColumnCount(columnCount);
rgindac9bc5502012-01-18 11:48:44 -0800715
716 if (deltaColumns > 0) {
David Benjamin66e954d2012-05-05 21:08:12 -0400717 if (this.defaultTabStops)
718 this.setDefaultTabStops(this.screenSize.width - deltaColumns);
rgindac9bc5502012-01-18 11:48:44 -0800719 } else {
720 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
David Benjamin66e954d2012-05-05 21:08:12 -0400721 if (this.tabStops_[i] < columnCount)
rgindac9bc5502012-01-18 11:48:44 -0800722 break;
723
724 this.tabStops_.pop();
725 }
726 }
727
728 this.screen_.setColumnCount(this.screenSize.width);
729};
730
731/**
732 * Deal with terminal height changes.
733 *
734 * This function does what needs to be done when the terminal height changes
735 * out from under us. It happens here rather than in onResize_() because this
736 * code may need to run synchronously to handle programmatic changes of
737 * terminal height.
738 *
739 * Relying on the browser to send us an async resize event means we may not be
740 * in the correct state yet when the next escape sequence hits.
741 */
742hterm.Terminal.prototype.realizeHeight_ = function(rowCount) {
Robert Ginda4e83f3a2012-09-04 15:25:25 -0700743 if (rowCount <= 0)
744 throw new Error('Attempt to realize bad height: ' + rowCount);
745
rgindac9bc5502012-01-18 11:48:44 -0800746 var deltaRows = rowCount - this.screen_.getHeight();
747
748 this.screenSize.height = rowCount;
749
750 var cursor = this.saveCursor();
751
752 if (deltaRows < 0) {
753 // Screen got smaller.
754 deltaRows *= -1;
755 while (deltaRows) {
756 var lastRow = this.getRowCount() - 1;
757 if (lastRow - this.scrollbackRows_.length == cursor.row)
758 break;
759
760 if (this.getRowText(lastRow))
761 break;
762
763 this.screen_.popRow();
764 deltaRows--;
765 }
766
767 var ary = this.screen_.shiftRows(deltaRows);
768 this.scrollbackRows_.push.apply(this.scrollbackRows_, ary);
769
770 // We just removed rows from the top of the screen, we need to update
771 // the cursor to match.
rginda35c456b2012-02-09 17:29:05 -0800772 cursor.row = Math.max(cursor.row - deltaRows, 0);
rgindac9bc5502012-01-18 11:48:44 -0800773 } else if (deltaRows > 0) {
774 // Screen got larger.
775
776 if (deltaRows <= this.scrollbackRows_.length) {
777 var scrollbackCount = Math.min(deltaRows, this.scrollbackRows_.length);
778 var rows = this.scrollbackRows_.splice(
779 this.scrollbackRows_.length - scrollbackCount, scrollbackCount);
780 this.screen_.unshiftRows(rows);
781 deltaRows -= scrollbackCount;
782 cursor.row += scrollbackCount;
783 }
784
785 if (deltaRows)
786 this.appendRows_(deltaRows);
787 }
788
rginda35c456b2012-02-09 17:29:05 -0800789 this.setVTScrollRegion(null, null);
rgindac9bc5502012-01-18 11:48:44 -0800790 this.restoreCursor(cursor);
rginda87b86462011-12-14 13:48:03 -0800791};
792
793/**
794 * Scroll the terminal to the top of the scrollback buffer.
795 */
796hterm.Terminal.prototype.scrollHome = function() {
797 this.scrollPort_.scrollRowToTop(0);
798};
799
800/**
801 * Scroll the terminal to the end.
802 */
803hterm.Terminal.prototype.scrollEnd = function() {
804 this.scrollPort_.scrollRowToBottom(this.getRowCount());
805};
806
807/**
808 * Scroll the terminal one page up (minus one line) relative to the current
809 * position.
810 */
811hterm.Terminal.prototype.scrollPageUp = function() {
812 var i = this.scrollPort_.getTopRowIndex();
813 this.scrollPort_.scrollRowToTop(i - this.screenSize.height + 1);
814};
815
816/**
817 * Scroll the terminal one page down (minus one line) relative to the current
818 * position.
819 */
820hterm.Terminal.prototype.scrollPageDown = function() {
821 var i = this.scrollPort_.getTopRowIndex();
822 this.scrollPort_.scrollRowToTop(i + this.screenSize.height - 1);
rginda8ba33642011-12-14 12:31:31 -0800823};
824
rgindac9bc5502012-01-18 11:48:44 -0800825/**
Robert Ginda40932892012-12-10 17:26:40 -0800826 * Clear primary screen, secondary screen, and the scrollback buffer.
827 */
828hterm.Terminal.prototype.wipeContents = function() {
829 this.scrollbackRows_.length = 0;
830 this.scrollPort_.resetCache();
831
832 [this.primaryScreen_, this.alternateScreen_].forEach(function(screen) {
833 var bottom = screen.getHeight();
834 if (bottom > 0) {
835 this.renumberRows_(0, bottom);
836 this.clearHome(screen);
837 }
838 }.bind(this));
839
840 this.syncCursorPosition_();
Andrew de los Reyes68e07802013-04-04 15:38:55 -0700841 this.scrollPort_.invalidate();
Robert Ginda40932892012-12-10 17:26:40 -0800842};
843
844/**
rgindac9bc5502012-01-18 11:48:44 -0800845 * Full terminal reset.
846 */
rginda87b86462011-12-14 13:48:03 -0800847hterm.Terminal.prototype.reset = function() {
rgindac9bc5502012-01-18 11:48:44 -0800848 this.clearAllTabStops();
849 this.setDefaultTabStops();
rginda9ea433c2012-03-16 11:57:00 -0700850
851 this.clearHome(this.primaryScreen_);
852 this.primaryScreen_.textAttributes.reset();
853
854 this.clearHome(this.alternateScreen_);
855 this.alternateScreen_.textAttributes.reset();
856
rgindab8bc8932012-04-27 12:45:03 -0700857 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
858
Robert Ginda92e18102013-03-14 13:56:37 -0700859 this.vt.reset();
860
rgindac9bc5502012-01-18 11:48:44 -0800861 this.softReset();
rginda87b86462011-12-14 13:48:03 -0800862};
863
rgindac9bc5502012-01-18 11:48:44 -0800864/**
865 * Soft terminal reset.
rgindab8bc8932012-04-27 12:45:03 -0700866 *
867 * Perform a soft reset to the default values listed in
868 * http://www.vt100.net/docs/vt510-rm/DECSTR#T5-9
rgindac9bc5502012-01-18 11:48:44 -0800869 */
rginda0f5c0292012-01-13 11:00:13 -0800870hterm.Terminal.prototype.softReset = function() {
rgindab8bc8932012-04-27 12:45:03 -0700871 // Reset terminal options to their default values.
rgindac9bc5502012-01-18 11:48:44 -0800872 this.options_ = new hterm.Options();
rgindaf522ce02012-04-17 17:49:17 -0700873
rgindab8bc8932012-04-27 12:45:03 -0700874 // Xterm also resets the color palette on soft reset, even though it doesn't
875 // seem to be documented anywhere.
rgindaf522ce02012-04-17 17:49:17 -0700876 this.primaryScreen_.textAttributes.resetColorPalette();
877 this.alternateScreen_.textAttributes.resetColorPalette();
878
rgindab8bc8932012-04-27 12:45:03 -0700879 // The xterm man page explicitly says this will happen on soft reset.
880 this.setVTScrollRegion(null, null);
881
882 // Xterm also shows the cursor on soft reset, but does not alter the blink
883 // state.
rgindaa19afe22012-01-25 15:40:22 -0800884 this.setCursorVisible(true);
rginda0f5c0292012-01-13 11:00:13 -0800885};
886
rgindac9bc5502012-01-18 11:48:44 -0800887/**
888 * Move the cursor forward to the next tab stop, or to the last column
889 * if no more tab stops are set.
890 */
891hterm.Terminal.prototype.forwardTabStop = function() {
892 var column = this.screen_.cursorPosition.column;
893
894 for (var i = 0; i < this.tabStops_.length; i++) {
895 if (this.tabStops_[i] > column) {
896 this.setCursorColumn(this.tabStops_[i]);
897 return;
898 }
899 }
900
David Benjamin66e954d2012-05-05 21:08:12 -0400901 // xterm does not clear the overflow flag on HT or CHT.
902 var overflow = this.screen_.cursorPosition.overflow;
rgindac9bc5502012-01-18 11:48:44 -0800903 this.setCursorColumn(this.screenSize.width - 1);
David Benjamin66e954d2012-05-05 21:08:12 -0400904 this.screen_.cursorPosition.overflow = overflow;
rginda0f5c0292012-01-13 11:00:13 -0800905};
906
rgindac9bc5502012-01-18 11:48:44 -0800907/**
908 * Move the cursor backward to the previous tab stop, or to the first column
909 * if no previous tab stops are set.
910 */
911hterm.Terminal.prototype.backwardTabStop = function() {
912 var column = this.screen_.cursorPosition.column;
913
914 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
915 if (this.tabStops_[i] < column) {
916 this.setCursorColumn(this.tabStops_[i]);
917 return;
918 }
919 }
920
921 this.setCursorColumn(1);
rginda0f5c0292012-01-13 11:00:13 -0800922};
923
rgindac9bc5502012-01-18 11:48:44 -0800924/**
925 * Set a tab stop at the given column.
926 *
927 * @param {int} column Zero based column.
928 */
929hterm.Terminal.prototype.setTabStop = function(column) {
930 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
931 if (this.tabStops_[i] == column)
932 return;
933
934 if (this.tabStops_[i] < column) {
935 this.tabStops_.splice(i + 1, 0, column);
936 return;
937 }
938 }
939
940 this.tabStops_.splice(0, 0, column);
rginda87b86462011-12-14 13:48:03 -0800941};
942
rgindac9bc5502012-01-18 11:48:44 -0800943/**
944 * Clear the tab stop at the current cursor position.
945 *
946 * No effect if there is no tab stop at the current cursor position.
947 */
948hterm.Terminal.prototype.clearTabStopAtCursor = function() {
949 var column = this.screen_.cursorPosition.column;
950
951 var i = this.tabStops_.indexOf(column);
952 if (i == -1)
953 return;
954
955 this.tabStops_.splice(i, 1);
956};
957
958/**
959 * Clear all tab stops.
960 */
961hterm.Terminal.prototype.clearAllTabStops = function() {
962 this.tabStops_.length = 0;
David Benjamin66e954d2012-05-05 21:08:12 -0400963 this.defaultTabStops = false;
rgindac9bc5502012-01-18 11:48:44 -0800964};
965
966/**
967 * Set up the default tab stops, starting from a given column.
968 *
969 * This sets a tabstop every (column % this.tabWidth) column, starting
David Benjamin66e954d2012-05-05 21:08:12 -0400970 * from the specified column, or 0 if no column is provided. It also flags
971 * future resizes to set them up.
rgindac9bc5502012-01-18 11:48:44 -0800972 *
973 * This does not clear the existing tab stops first, use clearAllTabStops
974 * for that.
975 *
976 * @param {int} opt_start Optional starting zero based starting column, useful
977 * for filling out missing tab stops when the terminal is resized.
978 */
979hterm.Terminal.prototype.setDefaultTabStops = function(opt_start) {
980 var start = opt_start || 0;
981 var w = this.tabWidth;
David Benjamin66e954d2012-05-05 21:08:12 -0400982 // Round start up to a default tab stop.
983 start = start - 1 - ((start - 1) % w) + w;
984 for (var i = start; i < this.screenSize.width; i += w) {
985 this.setTabStop(i);
rgindac9bc5502012-01-18 11:48:44 -0800986 }
David Benjamin66e954d2012-05-05 21:08:12 -0400987
988 this.defaultTabStops = true;
rginda87b86462011-12-14 13:48:03 -0800989};
990
rginda6d397402012-01-17 10:58:29 -0800991/**
rginda8ba33642011-12-14 12:31:31 -0800992 * Interpret a sequence of characters.
993 *
994 * Incomplete escape sequences are buffered until the next call.
995 *
996 * @param {string} str Sequence of characters to interpret or pass through.
997 */
998hterm.Terminal.prototype.interpret = function(str) {
rginda0f5c0292012-01-13 11:00:13 -0800999 this.vt.interpret(str);
rginda8ba33642011-12-14 12:31:31 -08001000 this.scheduleSyncCursorPosition_();
1001};
1002
1003/**
1004 * Take over the given DIV for use as the terminal display.
1005 *
1006 * @param {HTMLDivElement} div The div to use as the terminal display.
1007 */
1008hterm.Terminal.prototype.decorate = function(div) {
rginda87b86462011-12-14 13:48:03 -08001009 this.div_ = div;
1010
rginda8ba33642011-12-14 12:31:31 -08001011 this.scrollPort_.decorate(div);
rginda30f20f62012-04-05 16:36:19 -07001012 this.scrollPort_.setBackgroundImage(this.prefs_.get('background-image'));
Philip Douglass959b49d2012-05-30 13:29:29 -04001013 this.scrollPort_.setBackgroundSize(this.prefs_.get('background-size'));
1014 this.scrollPort_.setBackgroundPosition(
1015 this.prefs_.get('background-position'));
rginda30f20f62012-04-05 16:36:19 -07001016
rginda0918b652012-04-04 11:26:24 -07001017 this.div_.focus = this.focus.bind(this);
rgindaf7521392012-02-28 17:20:34 -08001018
rginda9f5222b2012-03-05 11:53:28 -08001019 this.setFontSize(this.prefs_.get('font-size'));
1020 this.syncFontFamily();
rgindaa19afe22012-01-25 15:40:22 -08001021
David Reveman8f552492012-03-28 12:18:41 -04001022 this.setScrollbarVisible(this.prefs_.get('scrollbar-visible'));
1023
rginda8ba33642011-12-14 12:31:31 -08001024 this.document_ = this.scrollPort_.getDocument();
1025
rginda4bba5e12012-06-20 16:15:30 -07001026 this.document_.body.oncontextmenu = function() { return false };
1027
1028 var onMouse = this.onMouse_.bind(this);
1029 this.document_.body.firstChild.addEventListener('mousedown', onMouse);
1030 this.document_.body.firstChild.addEventListener('mouseup', onMouse);
1031 this.document_.body.firstChild.addEventListener('mousemove', onMouse);
1032 this.scrollPort_.onScrollWheel = onMouse;
1033
rginda8e92a692012-05-20 19:37:20 -07001034 this.document_.body.firstChild.addEventListener(
1035 'focus', this.onFocusChange_.bind(this, true));
1036 this.document_.body.firstChild.addEventListener(
1037 'blur', this.onFocusChange_.bind(this, false));
1038
1039 var style = this.document_.createElement('style');
1040 style.textContent =
1041 ('.cursor-node[focus="false"] {' +
1042 ' box-sizing: border-box;' +
1043 ' background-color: transparent !important;' +
1044 ' border-width: 2px;' +
1045 ' border-style: solid;' +
1046 '}');
1047 this.document_.head.appendChild(style);
1048
rginda8ba33642011-12-14 12:31:31 -08001049 this.cursorNode_ = this.document_.createElement('div');
rginda8e92a692012-05-20 19:37:20 -07001050 this.cursorNode_.className = 'cursor-node';
rginda8ba33642011-12-14 12:31:31 -08001051 this.cursorNode_.style.cssText =
1052 ('position: absolute;' +
rginda87b86462011-12-14 13:48:03 -08001053 'top: -99px;' +
1054 'display: block;' +
rginda35c456b2012-02-09 17:29:05 -08001055 'width: ' + this.scrollPort_.characterSize.width + 'px;' +
1056 'height: ' + this.scrollPort_.characterSize.height + 'px;' +
rginda8e92a692012-05-20 19:37:20 -07001057 '-webkit-transition: opacity, background-color 100ms linear;');
1058 this.setCursorColor(this.prefs_.get('cursor-color'));
rgindad5613292012-06-19 15:40:37 -07001059
rginda8ba33642011-12-14 12:31:31 -08001060 this.document_.body.appendChild(this.cursorNode_);
1061
rgindad5613292012-06-19 15:40:37 -07001062 // When 'enableMouseDragScroll' is off we reposition this element directly
1063 // under the mouse cursor after a click. This makes Chrome associate
1064 // subsequent mousemove events with the scroll-blocker. Since the
1065 // scroll-blocker is a peer (not a child) of the scrollport, the mousemove
1066 // events do not cause the scrollport to scroll.
1067 //
1068 // It's a hack, but it's the cleanest way I could find.
1069 this.scrollBlockerNode_ = this.document_.createElement('div');
1070 this.scrollBlockerNode_.style.cssText =
1071 ('position: absolute;' +
1072 'top: -99px;' +
1073 'display: block;' +
1074 'width: 10px;' +
1075 'height: 10px;');
1076 this.document_.body.appendChild(this.scrollBlockerNode_);
1077
1078 var onMouse = this.onMouse_.bind(this);
1079 this.scrollPort_.onScrollWheel = onMouse;
1080 ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick',
1081 ].forEach(function(event) {
1082 this.scrollBlockerNode_.addEventListener(event, onMouse);
1083 this.cursorNode_.addEventListener(event, onMouse);
1084 this.document_.addEventListener(event, onMouse);
1085 }.bind(this));
1086
1087 this.cursorNode_.addEventListener('mousedown', function() {
1088 setTimeout(this.focus.bind(this));
1089 }.bind(this));
1090
rgindade84e382012-04-20 15:39:31 -07001091 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
rginda8ba33642011-12-14 12:31:31 -08001092 this.setReverseVideo(false);
rginda87b86462011-12-14 13:48:03 -08001093
rginda87b86462011-12-14 13:48:03 -08001094 this.scrollPort_.focus();
rginda6d397402012-01-17 10:58:29 -08001095 this.scrollPort_.scheduleRedraw();
rginda87b86462011-12-14 13:48:03 -08001096};
1097
rginda0918b652012-04-04 11:26:24 -07001098/**
1099 * Return the HTML document that contains the terminal DOM nodes.
1100 */
rginda87b86462011-12-14 13:48:03 -08001101hterm.Terminal.prototype.getDocument = function() {
1102 return this.document_;
rginda8ba33642011-12-14 12:31:31 -08001103};
1104
1105/**
rginda0918b652012-04-04 11:26:24 -07001106 * Focus the terminal.
1107 */
1108hterm.Terminal.prototype.focus = function() {
1109 this.scrollPort_.focus();
1110};
1111
1112/**
rginda8ba33642011-12-14 12:31:31 -08001113 * Return the HTML Element for a given row index.
1114 *
1115 * This is a method from the RowProvider interface. The ScrollPort uses
1116 * it to fetch rows on demand as they are scrolled into view.
1117 *
1118 * TODO(rginda): Consider saving scrollback rows as (HTML source, text content)
1119 * pairs to conserve memory.
1120 *
1121 * @param {integer} index The zero-based row index, measured relative to the
1122 * start of the scrollback buffer. On-screen rows will always have the
1123 * largest indicies.
1124 * @return {HTMLElement} The 'x-row' element containing for the requested row.
1125 */
1126hterm.Terminal.prototype.getRowNode = function(index) {
1127 if (index < this.scrollbackRows_.length)
1128 return this.scrollbackRows_[index];
1129
1130 var screenIndex = index - this.scrollbackRows_.length;
1131 return this.screen_.rowsArray[screenIndex];
1132};
1133
1134/**
1135 * Return the text content for a given range of rows.
1136 *
1137 * This is a method from the RowProvider interface. The ScrollPort uses
1138 * it to fetch text content on demand when the user attempts to copy their
1139 * selection to the clipboard.
1140 *
1141 * @param {integer} start The zero-based row index to start from, measured
1142 * relative to the start of the scrollback buffer. On-screen rows will
1143 * always have the largest indicies.
1144 * @param {integer} end The zero-based row index to end on, measured
1145 * relative to the start of the scrollback buffer.
1146 * @return {string} A single string containing the text value of the range of
1147 * rows. Lines will be newline delimited, with no trailing newline.
1148 */
1149hterm.Terminal.prototype.getRowsText = function(start, end) {
1150 var ary = [];
1151 for (var i = start; i < end; i++) {
1152 var node = this.getRowNode(i);
1153 ary.push(node.textContent);
rgindaa09e7332012-08-17 12:49:51 -07001154 if (i < end - 1 && !node.getAttribute('line-overflow'))
1155 ary.push('\n');
rginda8ba33642011-12-14 12:31:31 -08001156 }
1157
rgindaa09e7332012-08-17 12:49:51 -07001158 return ary.join('');
rginda8ba33642011-12-14 12:31:31 -08001159};
1160
1161/**
1162 * Return the text content for a given row.
1163 *
1164 * This is a method from the RowProvider interface. The ScrollPort uses
1165 * it to fetch text content on demand when the user attempts to copy their
1166 * selection to the clipboard.
1167 *
1168 * @param {integer} index The zero-based row index to return, measured
1169 * relative to the start of the scrollback buffer. On-screen rows will
1170 * always have the largest indicies.
1171 * @return {string} A string containing the text value of the selected row.
1172 */
1173hterm.Terminal.prototype.getRowText = function(index) {
1174 var node = this.getRowNode(index);
rginda87b86462011-12-14 13:48:03 -08001175 return node.textContent;
rginda8ba33642011-12-14 12:31:31 -08001176};
1177
1178/**
1179 * Return the total number of rows in the addressable screen and in the
1180 * scrollback buffer of this terminal.
1181 *
1182 * This is a method from the RowProvider interface. The ScrollPort uses
1183 * it to compute the size of the scrollbar.
1184 *
1185 * @return {integer} The number of rows in this terminal.
1186 */
1187hterm.Terminal.prototype.getRowCount = function() {
1188 return this.scrollbackRows_.length + this.screen_.rowsArray.length;
1189};
1190
1191/**
1192 * Create DOM nodes for new rows and append them to the end of the terminal.
1193 *
1194 * This is the only correct way to add a new DOM node for a row. Notice that
1195 * the new row is appended to the bottom of the list of rows, and does not
1196 * require renumbering (of the rowIndex property) of previous rows.
1197 *
1198 * If you think you want a new blank row somewhere in the middle of the
1199 * terminal, look into moveRows_().
1200 *
1201 * This method does not pay attention to vtScrollTop/Bottom, since you should
1202 * be using moveRows() in cases where they would matter.
1203 *
1204 * The cursor will be positioned at column 0 of the first inserted line.
1205 */
1206hterm.Terminal.prototype.appendRows_ = function(count) {
1207 var cursorRow = this.screen_.rowsArray.length;
1208 var offset = this.scrollbackRows_.length + cursorRow;
1209 for (var i = 0; i < count; i++) {
1210 var row = this.document_.createElement('x-row');
1211 row.appendChild(this.document_.createTextNode(''));
1212 row.rowIndex = offset + i;
1213 this.screen_.pushRow(row);
1214 }
1215
1216 var extraRows = this.screen_.rowsArray.length - this.screenSize.height;
1217 if (extraRows > 0) {
1218 var ary = this.screen_.shiftRows(extraRows);
1219 Array.prototype.push.apply(this.scrollbackRows_, ary);
Robert Ginda36c5aa62012-10-15 11:17:47 -07001220 if (this.scrollPort_.isScrolledEnd)
1221 this.scheduleScrollDown_();
rginda8ba33642011-12-14 12:31:31 -08001222 }
1223
1224 if (cursorRow >= this.screen_.rowsArray.length)
1225 cursorRow = this.screen_.rowsArray.length - 1;
1226
rginda87b86462011-12-14 13:48:03 -08001227 this.setAbsoluteCursorPosition(cursorRow, 0);
rginda8ba33642011-12-14 12:31:31 -08001228};
1229
1230/**
1231 * Relocate rows from one part of the addressable screen to another.
1232 *
1233 * This is used to recycle rows during VT scrolls (those which are driven
1234 * by VT commands, rather than by the user manipulating the scrollbar.)
1235 *
1236 * In this case, the blank lines scrolled into the scroll region are made of
1237 * the nodes we scrolled off. These have their rowIndex properties carefully
1238 * renumbered so as not to confuse the ScrollPort.
rginda8ba33642011-12-14 12:31:31 -08001239 */
1240hterm.Terminal.prototype.moveRows_ = function(fromIndex, count, toIndex) {
1241 var ary = this.screen_.removeRows(fromIndex, count);
1242 this.screen_.insertRows(toIndex, ary);
1243
1244 var start, end;
1245 if (fromIndex < toIndex) {
1246 start = fromIndex;
rginda87b86462011-12-14 13:48:03 -08001247 end = toIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001248 } else {
1249 start = toIndex;
rginda87b86462011-12-14 13:48:03 -08001250 end = fromIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001251 }
1252
1253 this.renumberRows_(start, end);
rginda2312fff2012-01-05 16:20:52 -08001254 this.scrollPort_.scheduleInvalidate();
rginda8ba33642011-12-14 12:31:31 -08001255};
1256
1257/**
1258 * Renumber the rowIndex property of the given range of rows.
1259 *
1260 * The start and end indicies are relative to the screen, not the scrollback.
1261 * Rows in the scrollback buffer cannot be renumbered. Since they are not
rginda2312fff2012-01-05 16:20:52 -08001262 * addressable (you can't delete them, scroll them, etc), you should have
rginda8ba33642011-12-14 12:31:31 -08001263 * no need to renumber scrollback rows.
1264 */
Robert Ginda40932892012-12-10 17:26:40 -08001265hterm.Terminal.prototype.renumberRows_ = function(start, end, opt_screen) {
1266 var screen = opt_screen || this.screen_;
1267
rginda8ba33642011-12-14 12:31:31 -08001268 var offset = this.scrollbackRows_.length;
1269 for (var i = start; i < end; i++) {
Robert Ginda40932892012-12-10 17:26:40 -08001270 screen.rowsArray[i].rowIndex = offset + i;
rginda8ba33642011-12-14 12:31:31 -08001271 }
1272};
1273
1274/**
1275 * Print a string to the terminal.
1276 *
1277 * This respects the current insert and wraparound modes. It will add new lines
1278 * to the end of the terminal, scrolling off the top into the scrollback buffer
1279 * if necessary.
1280 *
1281 * The string is *not* parsed for escape codes. Use the interpret() method if
1282 * that's what you're after.
1283 *
1284 * @param{string} str The string to print.
1285 */
1286hterm.Terminal.prototype.print = function(str) {
rgindaa9abdd82012-08-06 18:05:09 -07001287 var startOffset = 0;
rginda2312fff2012-01-05 16:20:52 -08001288
rgindaa9abdd82012-08-06 18:05:09 -07001289 while (startOffset < str.length) {
rgindaa09e7332012-08-17 12:49:51 -07001290 if (this.options_.wraparound && this.screen_.cursorPosition.overflow) {
1291 this.screen_.commitLineOverflow();
rginda35c456b2012-02-09 17:29:05 -08001292 this.newLine();
rgindaa09e7332012-08-17 12:49:51 -07001293 }
rgindaa19afe22012-01-25 15:40:22 -08001294
rgindaa9abdd82012-08-06 18:05:09 -07001295 var count = str.length - startOffset;
1296 var didOverflow = false;
1297 var substr;
rgindaa19afe22012-01-25 15:40:22 -08001298
rgindaa9abdd82012-08-06 18:05:09 -07001299 if (this.screen_.cursorPosition.column + count >= this.screenSize.width) {
1300 didOverflow = true;
1301 count = this.screenSize.width - this.screen_.cursorPosition.column;
1302 }
rgindaa19afe22012-01-25 15:40:22 -08001303
rgindaa9abdd82012-08-06 18:05:09 -07001304 if (didOverflow && !this.options_.wraparound) {
1305 // If the string overflowed the line but wraparound is off, then the
1306 // last printed character should be the last of the string.
1307 // TODO: This will add to our problems with multibyte UTF-16 characters.
1308 substr = str.substr(startOffset, count - 1) +
1309 str.substr(str.length - 1);
1310 count = str.length;
1311 } else {
1312 substr = str.substr(startOffset, count);
1313 }
rgindaa19afe22012-01-25 15:40:22 -08001314
rgindaa9abdd82012-08-06 18:05:09 -07001315 if (this.options_.insertMode) {
1316 this.screen_.insertString(substr);
1317 } else {
1318 this.screen_.overwriteString(substr);
1319 }
1320
1321 this.screen_.maybeClipCurrentRow();
1322 startOffset += count;
rgindaa19afe22012-01-25 15:40:22 -08001323 }
rginda8ba33642011-12-14 12:31:31 -08001324
1325 this.scheduleSyncCursorPosition_();
rginda0f5c0292012-01-13 11:00:13 -08001326
rginda9f5222b2012-03-05 11:53:28 -08001327 if (this.scrollOnOutput_)
rginda0f5c0292012-01-13 11:00:13 -08001328 this.scrollPort_.scrollRowToBottom(this.getRowCount());
rginda8ba33642011-12-14 12:31:31 -08001329};
1330
1331/**
rginda87b86462011-12-14 13:48:03 -08001332 * Set the VT scroll region.
1333 *
rginda87b86462011-12-14 13:48:03 -08001334 * This also resets the cursor position to the absolute (0, 0) position, since
1335 * that's what xterm appears to do.
1336 *
1337 * @param {integer} scrollTop The zero-based top of the scroll region.
1338 * @param {integer} scrollBottom The zero-based bottom of the scroll region,
1339 * inclusive.
1340 */
1341hterm.Terminal.prototype.setVTScrollRegion = function(scrollTop, scrollBottom) {
1342 this.vtScrollTop_ = scrollTop;
1343 this.vtScrollBottom_ = scrollBottom;
rginda87b86462011-12-14 13:48:03 -08001344};
1345
1346/**
rginda8ba33642011-12-14 12:31:31 -08001347 * Return the top row index according to the VT.
1348 *
1349 * This will return 0 unless the terminal has been told to restrict scrolling
1350 * to some lower row. It is used for some VT cursor positioning and scrolling
1351 * commands.
1352 *
1353 * @return {integer} The topmost row in the terminal's scroll region.
1354 */
1355hterm.Terminal.prototype.getVTScrollTop = function() {
1356 if (this.vtScrollTop_ != null)
1357 return this.vtScrollTop_;
1358
1359 return 0;
rginda87b86462011-12-14 13:48:03 -08001360};
rginda8ba33642011-12-14 12:31:31 -08001361
1362/**
1363 * Return the bottom row index according to the VT.
1364 *
1365 * This will return the height of the terminal unless the it has been told to
1366 * restrict scrolling to some higher row. It is used for some VT cursor
1367 * positioning and scrolling commands.
1368 *
1369 * @return {integer} The bottommost row in the terminal's scroll region.
1370 */
1371hterm.Terminal.prototype.getVTScrollBottom = function() {
1372 if (this.vtScrollBottom_ != null)
1373 return this.vtScrollBottom_;
1374
rginda87b86462011-12-14 13:48:03 -08001375 return this.screenSize.height - 1;
rginda8ba33642011-12-14 12:31:31 -08001376}
1377
1378/**
1379 * Process a '\n' character.
1380 *
1381 * If the cursor is on the final row of the terminal this will append a new
1382 * blank row to the screen and scroll the topmost row into the scrollback
1383 * buffer.
1384 *
1385 * Otherwise, this moves the cursor to column zero of the next row.
1386 */
1387hterm.Terminal.prototype.newLine = function() {
Robert Ginda9937abc2013-07-25 16:09:23 -07001388 var cursorAtEndOfScreen = (this.screen_.cursorPosition.row ==
1389 this.screen_.rowsArray.length - 1);
1390
1391 if (this.vtScrollBottom_ != null) {
1392 // A VT Scroll region is active, we never append new rows.
1393 if (this.screen_.cursorPosition.row == this.vtScrollBottom_) {
1394 // We're at the end of the VT Scroll Region, perform a VT scroll.
1395 this.vtScrollUp(1);
1396 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
1397 } else if (cursorAtEndOfScreen) {
1398 // We're at the end of the screen, the only thing to do is put the
1399 // cursor to column 0.
1400 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
1401 } else {
1402 // Anywhere else, advance the cursor row, and reset the column.
1403 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
1404 }
1405 } else if (cursorAtEndOfScreen) {
Robert Ginda1b06b372013-07-19 15:22:51 -07001406 // We're at the end of the screen. Append a new row to the terminal,
1407 // shifting the top row into the scrollback.
1408 this.appendRows_(1);
rginda8ba33642011-12-14 12:31:31 -08001409 } else {
rginda87b86462011-12-14 13:48:03 -08001410 // Anywhere else in the screen just moves the cursor.
1411 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
rginda8ba33642011-12-14 12:31:31 -08001412 }
1413};
1414
1415/**
1416 * Like newLine(), except maintain the cursor column.
1417 */
1418hterm.Terminal.prototype.lineFeed = function() {
1419 var column = this.screen_.cursorPosition.column;
1420 this.newLine();
1421 this.setCursorColumn(column);
1422};
1423
1424/**
rginda87b86462011-12-14 13:48:03 -08001425 * If autoCarriageReturn is set then newLine(), else lineFeed().
1426 */
1427hterm.Terminal.prototype.formFeed = function() {
1428 if (this.options_.autoCarriageReturn) {
1429 this.newLine();
1430 } else {
1431 this.lineFeed();
1432 }
1433};
1434
1435/**
1436 * Move the cursor up one row, possibly inserting a blank line.
1437 *
1438 * The cursor column is not changed.
1439 */
1440hterm.Terminal.prototype.reverseLineFeed = function() {
1441 var scrollTop = this.getVTScrollTop();
1442 var currentRow = this.screen_.cursorPosition.row;
1443
1444 if (currentRow == scrollTop) {
1445 this.insertLines(1);
1446 } else {
1447 this.setAbsoluteCursorRow(currentRow - 1);
1448 }
1449};
1450
1451/**
rginda8ba33642011-12-14 12:31:31 -08001452 * Replace all characters to the left of the current cursor with the space
1453 * character.
1454 *
1455 * TODO(rginda): This should probably *remove* the characters (not just replace
1456 * with a space) if there are no characters at or beyond the current cursor
Robert Gindaf2547f12012-10-25 20:36:21 -07001457 * position.
rginda8ba33642011-12-14 12:31:31 -08001458 */
1459hterm.Terminal.prototype.eraseToLeft = function() {
rginda87b86462011-12-14 13:48:03 -08001460 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001461 this.setCursorColumn(0);
rgindacbbd7482012-06-13 15:06:16 -07001462 this.screen_.overwriteString(lib.f.getWhitespace(cursor.column + 1));
rginda87b86462011-12-14 13:48:03 -08001463 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001464};
1465
1466/**
David Benjamin684a9b72012-05-01 17:19:58 -04001467 * Erase a given number of characters to the right of the cursor.
rginda8ba33642011-12-14 12:31:31 -08001468 *
1469 * The cursor position is unchanged.
1470 *
Robert Gindaf2547f12012-10-25 20:36:21 -07001471 * If the current background color is not the default background color this
1472 * will insert spaces rather than delete. This is unfortunate because the
1473 * trailing space will affect text selection, but it's difficult to come up
1474 * with a way to style empty space that wouldn't trip up the hterm.Screen
1475 * code.
rginda8ba33642011-12-14 12:31:31 -08001476 */
1477hterm.Terminal.prototype.eraseToRight = function(opt_count) {
Robert Ginda7fd57082012-09-25 14:41:47 -07001478 var maxCount = this.screenSize.width - this.screen_.cursorPosition.column;
1479 var count = opt_count ? Math.min(opt_count, maxCount) : maxCount;
Robert Gindaf2547f12012-10-25 20:36:21 -07001480
1481 if (this.screen_.textAttributes.background ===
1482 this.screen_.textAttributes.DEFAULT_COLOR) {
1483 var cursorRow = this.screen_.rowsArray[this.screen_.cursorPosition.row];
1484 if (cursorRow.textContent.length <=
1485 this.screen_.cursorPosition.column + count) {
1486 this.screen_.deleteChars(count);
1487 this.clearCursorOverflow();
1488 return;
1489 }
1490 }
1491
rginda87b86462011-12-14 13:48:03 -08001492 var cursor = this.saveCursor();
Robert Ginda7fd57082012-09-25 14:41:47 -07001493 this.screen_.overwriteString(lib.f.getWhitespace(count));
rginda87b86462011-12-14 13:48:03 -08001494 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001495 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001496};
1497
1498/**
1499 * Erase the current line.
1500 *
1501 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001502 */
1503hterm.Terminal.prototype.eraseLine = function() {
rginda87b86462011-12-14 13:48:03 -08001504 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001505 this.screen_.clearCursorRow();
rginda87b86462011-12-14 13:48:03 -08001506 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001507 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001508};
1509
1510/**
David Benjamina08d78f2012-05-05 00:28:49 -04001511 * Erase all characters from the start of the screen to the current cursor
1512 * position, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001513 *
1514 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001515 */
1516hterm.Terminal.prototype.eraseAbove = function() {
rginda87b86462011-12-14 13:48:03 -08001517 var cursor = this.saveCursor();
1518
1519 this.eraseToLeft();
rginda8ba33642011-12-14 12:31:31 -08001520
David Benjamina08d78f2012-05-05 00:28:49 -04001521 for (var i = 0; i < cursor.row; i++) {
rginda87b86462011-12-14 13:48:03 -08001522 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001523 this.screen_.clearCursorRow();
1524 }
1525
rginda87b86462011-12-14 13:48:03 -08001526 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001527 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001528};
1529
1530/**
1531 * Erase all characters from the current cursor position to the end of the
David Benjamina08d78f2012-05-05 00:28:49 -04001532 * screen, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001533 *
1534 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001535 */
1536hterm.Terminal.prototype.eraseBelow = function() {
rginda87b86462011-12-14 13:48:03 -08001537 var cursor = this.saveCursor();
1538
1539 this.eraseToRight();
rginda8ba33642011-12-14 12:31:31 -08001540
David Benjamina08d78f2012-05-05 00:28:49 -04001541 var bottom = this.screenSize.height - 1;
rginda87b86462011-12-14 13:48:03 -08001542 for (var i = cursor.row + 1; i <= bottom; i++) {
1543 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001544 this.screen_.clearCursorRow();
1545 }
1546
rginda87b86462011-12-14 13:48:03 -08001547 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001548 this.clearCursorOverflow();
rginda87b86462011-12-14 13:48:03 -08001549};
1550
1551/**
1552 * Fill the terminal with a given character.
1553 *
1554 * This methods does not respect the VT scroll region.
1555 *
1556 * @param {string} ch The character to use for the fill.
1557 */
1558hterm.Terminal.prototype.fill = function(ch) {
1559 var cursor = this.saveCursor();
1560
1561 this.setAbsoluteCursorPosition(0, 0);
1562 for (var row = 0; row < this.screenSize.height; row++) {
1563 for (var col = 0; col < this.screenSize.width; col++) {
1564 this.setAbsoluteCursorPosition(row, col);
1565 this.screen_.overwriteString(ch);
1566 }
1567 }
1568
1569 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001570};
1571
1572/**
rginda9ea433c2012-03-16 11:57:00 -07001573 * Erase the entire display and leave the cursor at (0, 0).
rginda8ba33642011-12-14 12:31:31 -08001574 *
rginda9ea433c2012-03-16 11:57:00 -07001575 * This does not respect the scroll region.
1576 *
1577 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1578 * to the current screen.
rginda8ba33642011-12-14 12:31:31 -08001579 */
rginda9ea433c2012-03-16 11:57:00 -07001580hterm.Terminal.prototype.clearHome = function(opt_screen) {
1581 var screen = opt_screen || this.screen_;
1582 var bottom = screen.getHeight();
rginda8ba33642011-12-14 12:31:31 -08001583
rginda11057d52012-04-25 12:29:56 -07001584 if (bottom == 0) {
1585 // Empty screen, nothing to do.
1586 return;
1587 }
1588
rgindae4d29232012-01-19 10:47:13 -08001589 for (var i = 0; i < bottom; i++) {
rginda9ea433c2012-03-16 11:57:00 -07001590 screen.setCursorPosition(i, 0);
1591 screen.clearCursorRow();
rginda8ba33642011-12-14 12:31:31 -08001592 }
1593
rginda9ea433c2012-03-16 11:57:00 -07001594 screen.setCursorPosition(0, 0);
1595};
1596
1597/**
1598 * Erase the entire display without changing the cursor position.
1599 *
1600 * The cursor position is unchanged. This does not respect the scroll
1601 * region.
1602 *
1603 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1604 * to the current screen.
rginda9ea433c2012-03-16 11:57:00 -07001605 */
1606hterm.Terminal.prototype.clear = function(opt_screen) {
1607 var screen = opt_screen || this.screen_;
1608 var cursor = screen.cursorPosition.clone();
1609 this.clearHome(screen);
1610 screen.setCursorPosition(cursor.row, cursor.column);
rginda8ba33642011-12-14 12:31:31 -08001611};
1612
1613/**
1614 * VT command to insert lines at the current cursor row.
1615 *
1616 * This respects the current scroll region. Rows pushed off the bottom are
1617 * lost (they won't show up in the scrollback buffer).
1618 *
rginda8ba33642011-12-14 12:31:31 -08001619 * @param {integer} count The number of lines to insert.
1620 */
1621hterm.Terminal.prototype.insertLines = function(count) {
Robert Ginda579186b2012-09-26 11:40:04 -07001622 var cursorRow = this.screen_.cursorPosition.row;
rginda8ba33642011-12-14 12:31:31 -08001623
1624 var bottom = this.getVTScrollBottom();
Robert Ginda579186b2012-09-26 11:40:04 -07001625 count = Math.min(count, bottom - cursorRow);
rginda8ba33642011-12-14 12:31:31 -08001626
Robert Ginda579186b2012-09-26 11:40:04 -07001627 // The moveCount is the number of rows we need to relocate to make room for
1628 // the new row(s). The count is the distance to move them.
1629 var moveCount = bottom - cursorRow - count + 1;
1630 if (moveCount)
1631 this.moveRows_(cursorRow, moveCount, cursorRow + count);
rginda8ba33642011-12-14 12:31:31 -08001632
Robert Ginda579186b2012-09-26 11:40:04 -07001633 for (var i = count - 1; i >= 0; i--) {
1634 this.setAbsoluteCursorPosition(cursorRow + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001635 this.screen_.clearCursorRow();
1636 }
rginda8ba33642011-12-14 12:31:31 -08001637};
1638
1639/**
1640 * VT command to delete lines at the current cursor row.
1641 *
1642 * New rows are added to the bottom of scroll region to take their place. New
1643 * rows are strictly there to take up space and have no content or style.
1644 */
1645hterm.Terminal.prototype.deleteLines = function(count) {
rginda87b86462011-12-14 13:48:03 -08001646 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001647
rginda87b86462011-12-14 13:48:03 -08001648 var top = cursor.row;
rginda8ba33642011-12-14 12:31:31 -08001649 var bottom = this.getVTScrollBottom();
1650
rginda87b86462011-12-14 13:48:03 -08001651 var maxCount = bottom - top + 1;
rginda8ba33642011-12-14 12:31:31 -08001652 count = Math.min(count, maxCount);
1653
rginda87b86462011-12-14 13:48:03 -08001654 var moveStart = bottom - count + 1;
rginda8ba33642011-12-14 12:31:31 -08001655 if (count != maxCount)
1656 this.moveRows_(top, count, moveStart);
1657
1658 for (var i = 0; i < count; i++) {
rginda87b86462011-12-14 13:48:03 -08001659 this.setAbsoluteCursorPosition(moveStart + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001660 this.screen_.clearCursorRow();
1661 }
1662
rginda87b86462011-12-14 13:48:03 -08001663 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001664 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001665};
1666
1667/**
1668 * Inserts the given number of spaces at the current cursor position.
1669 *
rginda87b86462011-12-14 13:48:03 -08001670 * The cursor position is not changed.
rginda8ba33642011-12-14 12:31:31 -08001671 */
1672hterm.Terminal.prototype.insertSpace = function(count) {
rginda87b86462011-12-14 13:48:03 -08001673 var cursor = this.saveCursor();
1674
rgindacbbd7482012-06-13 15:06:16 -07001675 var ws = lib.f.getWhitespace(count || 1);
rginda8ba33642011-12-14 12:31:31 -08001676 this.screen_.insertString(ws);
rgindaa19afe22012-01-25 15:40:22 -08001677 this.screen_.maybeClipCurrentRow();
rginda87b86462011-12-14 13:48:03 -08001678
1679 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001680 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001681};
1682
1683/**
1684 * Forward-delete the specified number of characters starting at the cursor
1685 * position.
1686 *
1687 * @param {integer} count The number of characters to delete.
1688 */
1689hterm.Terminal.prototype.deleteChars = function(count) {
Robert Ginda7fd57082012-09-25 14:41:47 -07001690 var deleted = this.screen_.deleteChars(count);
1691 if (deleted && !this.screen_.textAttributes.isDefault()) {
1692 var cursor = this.saveCursor();
1693 this.setCursorColumn(this.screenSize.width - deleted);
1694 this.screen_.insertString(lib.f.getWhitespace(deleted));
1695 this.restoreCursor(cursor);
1696 }
1697
David Benjamin54e8bf62012-06-01 22:31:40 -04001698 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001699};
1700
1701/**
1702 * Shift rows in the scroll region upwards by a given number of lines.
1703 *
1704 * New rows are inserted at the bottom of the scroll region to fill the
1705 * vacated rows. The new rows not filled out with the current text attributes.
1706 *
1707 * This function does not affect the scrollback rows at all. Rows shifted
1708 * off the top are lost.
1709 *
rginda87b86462011-12-14 13:48:03 -08001710 * The cursor position is not altered.
1711 *
rginda8ba33642011-12-14 12:31:31 -08001712 * @param {integer} count The number of rows to scroll.
1713 */
1714hterm.Terminal.prototype.vtScrollUp = function(count) {
rginda87b86462011-12-14 13:48:03 -08001715 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001716
rginda87b86462011-12-14 13:48:03 -08001717 this.setAbsoluteCursorRow(this.getVTScrollTop());
rginda8ba33642011-12-14 12:31:31 -08001718 this.deleteLines(count);
1719
rginda87b86462011-12-14 13:48:03 -08001720 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001721};
1722
1723/**
1724 * Shift rows below the cursor down by a given number of lines.
1725 *
1726 * This function respects the current scroll region.
1727 *
1728 * New rows are inserted at the top of the scroll region to fill the
1729 * vacated rows. The new rows not filled out with the current text attributes.
1730 *
1731 * This function does not affect the scrollback rows at all. Rows shifted
1732 * off the bottom are lost.
1733 *
1734 * @param {integer} count The number of rows to scroll.
1735 */
1736hterm.Terminal.prototype.vtScrollDown = function(opt_count) {
rginda87b86462011-12-14 13:48:03 -08001737 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001738
rginda87b86462011-12-14 13:48:03 -08001739 this.setAbsoluteCursorPosition(this.getVTScrollTop(), 0);
rginda8ba33642011-12-14 12:31:31 -08001740 this.insertLines(opt_count);
1741
rginda87b86462011-12-14 13:48:03 -08001742 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001743};
1744
rginda87b86462011-12-14 13:48:03 -08001745
rginda8ba33642011-12-14 12:31:31 -08001746/**
1747 * Set the cursor position.
1748 *
1749 * The cursor row is relative to the scroll region if the terminal has
1750 * 'origin mode' enabled, or relative to the addressable screen otherwise.
1751 *
1752 * @param {integer} row The new zero-based cursor row.
1753 * @param {integer} row The new zero-based cursor column.
1754 */
1755hterm.Terminal.prototype.setCursorPosition = function(row, column) {
1756 if (this.options_.originMode) {
rginda87b86462011-12-14 13:48:03 -08001757 this.setRelativeCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001758 } else {
rginda87b86462011-12-14 13:48:03 -08001759 this.setAbsoluteCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001760 }
rginda87b86462011-12-14 13:48:03 -08001761};
rginda8ba33642011-12-14 12:31:31 -08001762
rginda87b86462011-12-14 13:48:03 -08001763hterm.Terminal.prototype.setRelativeCursorPosition = function(row, column) {
1764 var scrollTop = this.getVTScrollTop();
rgindacbbd7482012-06-13 15:06:16 -07001765 row = lib.f.clamp(row + scrollTop, scrollTop, this.getVTScrollBottom());
1766 column = lib.f.clamp(column, 0, this.screenSize.width - 1);
rginda87b86462011-12-14 13:48:03 -08001767 this.screen_.setCursorPosition(row, column);
1768};
1769
1770hterm.Terminal.prototype.setAbsoluteCursorPosition = function(row, column) {
rgindacbbd7482012-06-13 15:06:16 -07001771 row = lib.f.clamp(row, 0, this.screenSize.height - 1);
1772 column = lib.f.clamp(column, 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08001773 this.screen_.setCursorPosition(row, column);
1774};
1775
1776/**
1777 * Set the cursor column.
1778 *
1779 * @param {integer} column The new zero-based cursor column.
1780 */
1781hterm.Terminal.prototype.setCursorColumn = function(column) {
rginda87b86462011-12-14 13:48:03 -08001782 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, column);
rginda8ba33642011-12-14 12:31:31 -08001783};
1784
1785/**
1786 * Return the cursor column.
1787 *
1788 * @return {integer} The zero-based cursor column.
1789 */
1790hterm.Terminal.prototype.getCursorColumn = function() {
1791 return this.screen_.cursorPosition.column;
1792};
1793
1794/**
1795 * Set the cursor row.
1796 *
1797 * The cursor row is relative to the scroll region if the terminal has
1798 * 'origin mode' enabled, or relative to the addressable screen otherwise.
1799 *
1800 * @param {integer} row The new cursor row.
1801 */
rginda87b86462011-12-14 13:48:03 -08001802hterm.Terminal.prototype.setAbsoluteCursorRow = function(row) {
1803 this.setAbsoluteCursorPosition(row, this.screen_.cursorPosition.column);
rginda8ba33642011-12-14 12:31:31 -08001804};
1805
1806/**
1807 * Return the cursor row.
1808 *
1809 * @return {integer} The zero-based cursor row.
1810 */
1811hterm.Terminal.prototype.getCursorRow = function(row) {
1812 return this.screen_.cursorPosition.row;
1813};
1814
1815/**
1816 * Request that the ScrollPort redraw itself soon.
1817 *
1818 * The redraw will happen asynchronously, soon after the call stack winds down.
1819 * Multiple calls will be coalesced into a single redraw.
1820 */
1821hterm.Terminal.prototype.scheduleRedraw_ = function() {
rginda87b86462011-12-14 13:48:03 -08001822 if (this.timeouts_.redraw)
1823 return;
rginda8ba33642011-12-14 12:31:31 -08001824
1825 var self = this;
rginda87b86462011-12-14 13:48:03 -08001826 this.timeouts_.redraw = setTimeout(function() {
1827 delete self.timeouts_.redraw;
rginda8ba33642011-12-14 12:31:31 -08001828 self.scrollPort_.redraw_();
1829 }, 0);
1830};
1831
1832/**
1833 * Request that the ScrollPort be scrolled to the bottom.
1834 *
1835 * The scroll will happen asynchronously, soon after the call stack winds down.
1836 * Multiple calls will be coalesced into a single scroll.
1837 *
1838 * This affects the scrollbar position of the ScrollPort, and has nothing to
1839 * do with the VT scroll commands.
1840 */
1841hterm.Terminal.prototype.scheduleScrollDown_ = function() {
1842 if (this.timeouts_.scrollDown)
rginda87b86462011-12-14 13:48:03 -08001843 return;
rginda8ba33642011-12-14 12:31:31 -08001844
1845 var self = this;
1846 this.timeouts_.scrollDown = setTimeout(function() {
1847 delete self.timeouts_.scrollDown;
1848 self.scrollPort_.scrollRowToBottom(self.getRowCount());
1849 }, 10);
1850};
1851
1852/**
1853 * Move the cursor up a specified number of rows.
1854 *
1855 * @param {integer} count The number of rows to move the cursor.
1856 */
1857hterm.Terminal.prototype.cursorUp = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001858 return this.cursorDown(-(count || 1));
rginda8ba33642011-12-14 12:31:31 -08001859};
1860
1861/**
1862 * Move the cursor down a specified number of rows.
1863 *
1864 * @param {integer} count The number of rows to move the cursor.
1865 */
1866hterm.Terminal.prototype.cursorDown = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001867 count = count || 1;
rginda8ba33642011-12-14 12:31:31 -08001868 var minHeight = (this.options_.originMode ? this.getVTScrollTop() : 0);
1869 var maxHeight = (this.options_.originMode ? this.getVTScrollBottom() :
1870 this.screenSize.height - 1);
1871
rgindacbbd7482012-06-13 15:06:16 -07001872 var row = lib.f.clamp(this.screen_.cursorPosition.row + count,
rginda8ba33642011-12-14 12:31:31 -08001873 minHeight, maxHeight);
rginda87b86462011-12-14 13:48:03 -08001874 this.setAbsoluteCursorRow(row);
rginda8ba33642011-12-14 12:31:31 -08001875};
1876
1877/**
1878 * Move the cursor left a specified number of columns.
1879 *
1880 * @param {integer} count The number of columns to move the cursor.
1881 */
1882hterm.Terminal.prototype.cursorLeft = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001883 return this.cursorRight(-(count || 1));
rginda8ba33642011-12-14 12:31:31 -08001884};
1885
1886/**
1887 * Move the cursor right a specified number of columns.
1888 *
1889 * @param {integer} count The number of columns to move the cursor.
1890 */
1891hterm.Terminal.prototype.cursorRight = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08001892 count = count || 1;
rgindacbbd7482012-06-13 15:06:16 -07001893 var column = lib.f.clamp(this.screen_.cursorPosition.column + count,
rginda87b86462011-12-14 13:48:03 -08001894 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08001895 this.setCursorColumn(column);
1896};
1897
1898/**
1899 * Reverse the foreground and background colors of the terminal.
1900 *
1901 * This only affects text that was drawn with no attributes.
1902 *
1903 * TODO(rginda): Test xterm to see if reverse is respected for text that has
1904 * been drawn with attributes that happen to coincide with the default
1905 * 'no-attribute' colors. My guess is probably not.
1906 */
1907hterm.Terminal.prototype.setReverseVideo = function(state) {
rginda87b86462011-12-14 13:48:03 -08001908 this.options_.reverseVideo = state;
rginda8ba33642011-12-14 12:31:31 -08001909 if (state) {
rginda9f5222b2012-03-05 11:53:28 -08001910 this.scrollPort_.setForegroundColor(this.prefs_.get('background-color'));
1911 this.scrollPort_.setBackgroundColor(this.prefs_.get('foreground-color'));
rginda8ba33642011-12-14 12:31:31 -08001912 } else {
rginda9f5222b2012-03-05 11:53:28 -08001913 this.scrollPort_.setForegroundColor(this.prefs_.get('foreground-color'));
1914 this.scrollPort_.setBackgroundColor(this.prefs_.get('background-color'));
rginda8ba33642011-12-14 12:31:31 -08001915 }
1916};
1917
1918/**
rginda87b86462011-12-14 13:48:03 -08001919 * Ring the terminal bell.
Robert Ginda92e18102013-03-14 13:56:37 -07001920 *
1921 * This will not play the bell audio more than once per second.
rginda87b86462011-12-14 13:48:03 -08001922 */
1923hterm.Terminal.prototype.ringBell = function() {
rginda6d397402012-01-17 10:58:29 -08001924 this.cursorNode_.style.backgroundColor =
1925 this.scrollPort_.getForegroundColor();
rginda87b86462011-12-14 13:48:03 -08001926
1927 var self = this;
1928 setTimeout(function() {
rginda9f5222b2012-03-05 11:53:28 -08001929 self.cursorNode_.style.backgroundColor = self.prefs_.get('cursor-color');
rginda6d397402012-01-17 10:58:29 -08001930 }, 200);
Robert Ginda92e18102013-03-14 13:56:37 -07001931
1932 if (this.bellAudio_.getAttribute('src')) {
Robert Gindaa6331372013-03-19 10:35:39 -07001933 if (this.bellSquelchTimeout_)
Robert Ginda92e18102013-03-14 13:56:37 -07001934 return;
1935
1936 this.bellAudio_.play();
1937
1938 this.bellSequelchTimeout_ = setTimeout(function() {
1939 delete this.bellSquelchTimeout_;
Robert Gindaa6331372013-03-19 10:35:39 -07001940 }.bind(this), 500);
Robert Ginda92e18102013-03-14 13:56:37 -07001941 } else {
1942 delete this.bellSquelchTimeout_;
1943 }
rginda87b86462011-12-14 13:48:03 -08001944};
1945
1946/**
rginda8ba33642011-12-14 12:31:31 -08001947 * Set the origin mode bit.
1948 *
1949 * If origin mode is on, certain VT cursor and scrolling commands measure their
1950 * row parameter relative to the VT scroll region. Otherwise, row 0 corresponds
1951 * to the top of the addressable screen.
1952 *
1953 * Defaults to off.
1954 *
1955 * @param {boolean} state True to set origin mode, false to unset.
1956 */
1957hterm.Terminal.prototype.setOriginMode = function(state) {
1958 this.options_.originMode = state;
rgindae4d29232012-01-19 10:47:13 -08001959 this.setCursorPosition(0, 0);
rginda8ba33642011-12-14 12:31:31 -08001960};
1961
1962/**
1963 * Set the insert mode bit.
1964 *
1965 * If insert mode is on, existing text beyond the cursor position will be
1966 * shifted right to make room for new text. Otherwise, new text overwrites
1967 * any existing text.
1968 *
1969 * Defaults to off.
1970 *
1971 * @param {boolean} state True to set insert mode, false to unset.
1972 */
1973hterm.Terminal.prototype.setInsertMode = function(state) {
1974 this.options_.insertMode = state;
1975};
1976
1977/**
rginda87b86462011-12-14 13:48:03 -08001978 * Set the auto carriage return bit.
1979 *
1980 * If auto carriage return is on then a formfeed character is interpreted
1981 * as a newline, otherwise it's the same as a linefeed. The difference boils
1982 * down to whether or not the cursor column is reset.
1983 */
1984hterm.Terminal.prototype.setAutoCarriageReturn = function(state) {
1985 this.options_.autoCarriageReturn = state;
1986};
1987
1988/**
rginda8ba33642011-12-14 12:31:31 -08001989 * Set the wraparound mode bit.
1990 *
1991 * If wraparound mode is on, certain VT commands will allow the cursor to wrap
1992 * to the start of the following row. Otherwise, the cursor is clamped to the
1993 * end of the screen and attempts to write past it are ignored.
1994 *
1995 * Defaults to on.
1996 *
1997 * @param {boolean} state True to set wraparound mode, false to unset.
1998 */
1999hterm.Terminal.prototype.setWraparound = function(state) {
2000 this.options_.wraparound = state;
2001};
2002
2003/**
2004 * Set the reverse-wraparound mode bit.
2005 *
2006 * If wraparound mode is off, certain VT commands will allow the cursor to wrap
2007 * to the end of the previous row. Otherwise, the cursor is clamped to column
2008 * 0.
2009 *
2010 * Defaults to off.
2011 *
2012 * @param {boolean} state True to set reverse-wraparound mode, false to unset.
2013 */
2014hterm.Terminal.prototype.setReverseWraparound = function(state) {
2015 this.options_.reverseWraparound = state;
2016};
2017
2018/**
2019 * Selects between the primary and alternate screens.
2020 *
2021 * If alternate mode is on, the alternate screen is active. Otherwise the
2022 * primary screen is active.
2023 *
2024 * Swapping screens has no effect on the scrollback buffer.
2025 *
2026 * Each screen maintains its own cursor position.
2027 *
2028 * Defaults to off.
2029 *
2030 * @param {boolean} state True to set alternate mode, false to unset.
2031 */
2032hterm.Terminal.prototype.setAlternateMode = function(state) {
rginda6d397402012-01-17 10:58:29 -08002033 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08002034 this.screen_ = state ? this.alternateScreen_ : this.primaryScreen_;
2035
rginda35c456b2012-02-09 17:29:05 -08002036 if (this.screen_.rowsArray.length &&
2037 this.screen_.rowsArray[0].rowIndex != this.scrollbackRows_.length) {
2038 // If the screen changed sizes while we were away, our rowIndexes may
2039 // be incorrect.
2040 var offset = this.scrollbackRows_.length;
2041 var ary = this.screen_.rowsArray;
rgindacbbd7482012-06-13 15:06:16 -07002042 for (var i = 0; i < ary.length; i++) {
rginda35c456b2012-02-09 17:29:05 -08002043 ary[i].rowIndex = offset + i;
2044 }
2045 }
rginda8ba33642011-12-14 12:31:31 -08002046
rginda35c456b2012-02-09 17:29:05 -08002047 this.realizeWidth_(this.screenSize.width);
2048 this.realizeHeight_(this.screenSize.height);
2049 this.scrollPort_.syncScrollHeight();
2050 this.scrollPort_.invalidate();
rginda8ba33642011-12-14 12:31:31 -08002051
rginda6d397402012-01-17 10:58:29 -08002052 this.restoreCursor(cursor);
rginda35c456b2012-02-09 17:29:05 -08002053 this.scrollPort_.resize();
rginda8ba33642011-12-14 12:31:31 -08002054};
2055
2056/**
2057 * Set the cursor-blink mode bit.
2058 *
2059 * If cursor-blink is on, the cursor will blink when it is visible. Otherwise
2060 * a visible cursor does not blink.
2061 *
2062 * You should make sure to turn blinking off if you're going to dispose of a
2063 * terminal, otherwise you'll leak a timeout.
2064 *
2065 * Defaults to on.
2066 *
2067 * @param {boolean} state True to set cursor-blink mode, false to unset.
2068 */
2069hterm.Terminal.prototype.setCursorBlink = function(state) {
2070 this.options_.cursorBlink = state;
2071
2072 if (!state && this.timeouts_.cursorBlink) {
2073 clearTimeout(this.timeouts_.cursorBlink);
2074 delete this.timeouts_.cursorBlink;
2075 }
2076
2077 if (this.options_.cursorVisible)
2078 this.setCursorVisible(true);
2079};
2080
2081/**
2082 * Set the cursor-visible mode bit.
2083 *
2084 * If cursor-visible is on, the cursor will be visible. Otherwise it will not.
2085 *
2086 * Defaults to on.
2087 *
2088 * @param {boolean} state True to set cursor-visible mode, false to unset.
2089 */
2090hterm.Terminal.prototype.setCursorVisible = function(state) {
2091 this.options_.cursorVisible = state;
2092
2093 if (!state) {
rginda87b86462011-12-14 13:48:03 -08002094 this.cursorNode_.style.opacity = '0';
rginda8ba33642011-12-14 12:31:31 -08002095 return;
2096 }
2097
rginda87b86462011-12-14 13:48:03 -08002098 this.syncCursorPosition_();
2099
2100 this.cursorNode_.style.opacity = '1';
rginda8ba33642011-12-14 12:31:31 -08002101
2102 if (this.options_.cursorBlink) {
2103 if (this.timeouts_.cursorBlink)
2104 return;
2105
2106 this.timeouts_.cursorBlink = setInterval(this.onCursorBlink_.bind(this),
2107 500);
2108 } else {
2109 if (this.timeouts_.cursorBlink) {
2110 clearTimeout(this.timeouts_.cursorBlink);
2111 delete this.timeouts_.cursorBlink;
2112 }
2113 }
2114};
2115
2116/**
rginda87b86462011-12-14 13:48:03 -08002117 * Synchronizes the visible cursor and document selection with the current
2118 * cursor coordinates.
rginda8ba33642011-12-14 12:31:31 -08002119 */
2120hterm.Terminal.prototype.syncCursorPosition_ = function() {
2121 var topRowIndex = this.scrollPort_.getTopRowIndex();
2122 var bottomRowIndex = this.scrollPort_.getBottomRowIndex(topRowIndex);
2123 var cursorRowIndex = this.scrollbackRows_.length +
2124 this.screen_.cursorPosition.row;
2125
2126 if (cursorRowIndex > bottomRowIndex) {
2127 // Cursor is scrolled off screen, move it outside of the visible area.
rginda35c456b2012-02-09 17:29:05 -08002128 this.cursorNode_.style.top = -this.scrollPort_.characterSize.height + 'px';
rginda8ba33642011-12-14 12:31:31 -08002129 return;
2130 }
2131
rginda35c456b2012-02-09 17:29:05 -08002132 this.cursorNode_.style.width = this.scrollPort_.characterSize.width + 'px';
2133 this.cursorNode_.style.height = this.scrollPort_.characterSize.height + 'px';
2134
rginda8ba33642011-12-14 12:31:31 -08002135 this.cursorNode_.style.top = this.scrollPort_.visibleRowTopMargin +
rginda35c456b2012-02-09 17:29:05 -08002136 this.scrollPort_.characterSize.height * (cursorRowIndex - topRowIndex) +
2137 'px';
2138 this.cursorNode_.style.left = this.scrollPort_.characterSize.width *
2139 this.screen_.cursorPosition.column + 'px';
rginda87b86462011-12-14 13:48:03 -08002140
2141 this.cursorNode_.setAttribute('title',
2142 '(' + this.screen_.cursorPosition.row +
2143 ', ' + this.screen_.cursorPosition.column +
2144 ')');
2145
2146 // Update the caret for a11y purposes.
2147 var selection = this.document_.getSelection();
2148 if (selection && selection.isCollapsed)
2149 this.screen_.syncSelectionCaret(selection);
rginda8ba33642011-12-14 12:31:31 -08002150};
2151
2152/**
2153 * Synchronizes the visible cursor with the current cursor coordinates.
2154 *
2155 * The sync will happen asynchronously, soon after the call stack winds down.
2156 * Multiple calls will be coalesced into a single sync.
2157 */
2158hterm.Terminal.prototype.scheduleSyncCursorPosition_ = function() {
2159 if (this.timeouts_.syncCursor)
rginda87b86462011-12-14 13:48:03 -08002160 return;
rginda8ba33642011-12-14 12:31:31 -08002161
2162 var self = this;
2163 this.timeouts_.syncCursor = setTimeout(function() {
2164 self.syncCursorPosition_();
2165 delete self.timeouts_.syncCursor;
rginda87b86462011-12-14 13:48:03 -08002166 }, 0);
2167};
2168
rgindacc2996c2012-02-24 14:59:31 -08002169/**
rgindaf522ce02012-04-17 17:49:17 -07002170 * Show or hide the zoom warning.
2171 *
2172 * The zoom warning is a message warning the user that their browser zoom must
2173 * be set to 100% in order for hterm to function properly.
2174 *
2175 * @param {boolean} state True to show the message, false to hide it.
2176 */
2177hterm.Terminal.prototype.showZoomWarning_ = function(state) {
2178 if (!this.zoomWarningNode_) {
2179 if (!state)
2180 return;
2181
2182 this.zoomWarningNode_ = this.document_.createElement('div');
2183 this.zoomWarningNode_.style.cssText = (
2184 'color: black;' +
2185 'background-color: #ff2222;' +
2186 'font-size: large;' +
2187 'border-radius: 8px;' +
2188 'opacity: 0.75;' +
2189 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2190 'top: 0.5em;' +
2191 'right: 1.2em;' +
2192 'position: absolute;' +
2193 '-webkit-text-size-adjust: none;' +
2194 '-webkit-user-select: none;');
rgindaf522ce02012-04-17 17:49:17 -07002195 }
2196
Robert Gindab4839c22013-02-28 16:52:10 -08002197 this.zoomWarningNode_.textContent = lib.MessageManager.replaceReferences(
2198 hterm.zoomWarningMessage,
2199 [parseInt(this.scrollPort_.characterSize.zoomFactor * 100)]);
2200
rgindaf522ce02012-04-17 17:49:17 -07002201 this.zoomWarningNode_.style.fontFamily = this.prefs_.get('font-family');
2202
2203 if (state) {
2204 if (!this.zoomWarningNode_.parentNode)
2205 this.div_.parentNode.appendChild(this.zoomWarningNode_);
2206 } else if (this.zoomWarningNode_.parentNode) {
2207 this.zoomWarningNode_.parentNode.removeChild(this.zoomWarningNode_);
2208 }
2209};
2210
2211/**
rgindacc2996c2012-02-24 14:59:31 -08002212 * Show the terminal overlay for a given amount of time.
2213 *
2214 * The terminal overlay appears in inverse video in a large font, centered
2215 * over the terminal. You should probably keep the overlay message brief,
2216 * since it's in a large font and you probably aren't going to check the size
2217 * of the terminal first.
2218 *
2219 * @param {string} msg The text (not HTML) message to display in the overlay.
2220 * @param {number} opt_timeout The amount of time to wait before fading out
2221 * the overlay. Defaults to 1.5 seconds. Pass null to have the overlay
2222 * stay up forever (or until the next overlay).
2223 */
2224hterm.Terminal.prototype.showOverlay = function(msg, opt_timeout) {
rgindaf0090c92012-02-10 14:58:52 -08002225 if (!this.overlayNode_) {
2226 if (!this.div_)
2227 return;
2228
2229 this.overlayNode_ = this.document_.createElement('div');
2230 this.overlayNode_.style.cssText = (
rgindaf0090c92012-02-10 14:58:52 -08002231 'border-radius: 15px;' +
rgindaf0090c92012-02-10 14:58:52 -08002232 'font-size: xx-large;' +
2233 'opacity: 0.75;' +
2234 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2235 'position: absolute;' +
2236 '-webkit-user-select: none;' +
2237 '-webkit-transition: opacity 180ms ease-in;');
2238 }
2239
rginda9f5222b2012-03-05 11:53:28 -08002240 this.overlayNode_.style.color = this.prefs_.get('background-color');
2241 this.overlayNode_.style.backgroundColor = this.prefs_.get('foreground-color');
2242 this.overlayNode_.style.fontFamily = this.prefs_.get('font-family');
2243
rgindaf0090c92012-02-10 14:58:52 -08002244 this.overlayNode_.textContent = msg;
2245 this.overlayNode_.style.opacity = '0.75';
2246
2247 if (!this.overlayNode_.parentNode)
2248 this.div_.appendChild(this.overlayNode_);
2249
Robert Ginda97769282013-02-01 15:30:30 -08002250 var divSize = hterm.getClientSize(this.div_);
2251 var overlaySize = hterm.getClientSize(this.overlayNode_);
2252
2253 this.overlayNode_.style.top = (divSize.height - overlaySize.height) / 2;
2254 this.overlayNode_.style.left = (divSize.width - overlaySize.width -
2255 this.scrollPort_.currentScrollbarWidthPx) / 2;
rgindaf0090c92012-02-10 14:58:52 -08002256
2257 var self = this;
2258
2259 if (this.overlayTimeout_)
2260 clearTimeout(this.overlayTimeout_);
2261
rgindacc2996c2012-02-24 14:59:31 -08002262 if (opt_timeout === null)
2263 return;
2264
rgindaf0090c92012-02-10 14:58:52 -08002265 this.overlayTimeout_ = setTimeout(function() {
2266 self.overlayNode_.style.opacity = '0';
2267 setTimeout(function() {
rginda259dcca2012-03-14 16:37:11 -07002268 if (self.overlayNode_.parentNode)
2269 self.overlayNode_.parentNode.removeChild(self.overlayNode_);
rgindaf0090c92012-02-10 14:58:52 -08002270 self.overlayTimeout_ = null;
2271 self.overlayNode_.style.opacity = '0.75';
2272 }, 200);
rgindacc2996c2012-02-24 14:59:31 -08002273 }, opt_timeout || 1500);
rgindaf0090c92012-02-10 14:58:52 -08002274};
2275
rginda4bba5e12012-06-20 16:15:30 -07002276/**
2277 * Paste from the system clipboard to the terminal.
2278 */
2279hterm.Terminal.prototype.paste = function() {
2280 hterm.pasteFromClipboard(this.document_);
2281};
2282
2283/**
2284 * Copy a string to the system clipboard.
2285 *
2286 * Note: If there is a selected range in the terminal, it'll be cleared.
2287 */
2288hterm.Terminal.prototype.copyStringToClipboard = function(str) {
Robert Ginda9fb38222012-09-11 14:19:12 -07002289 if (this.prefs_.get('enable-clipboard-notice'))
Robert Gindab4839c22013-02-28 16:52:10 -08002290 setTimeout(this.showOverlay.bind(this, hterm.notifyCopyMessage, 500), 200);
rgindaa09e7332012-08-17 12:49:51 -07002291
2292 var copySource = this.document_.createElement('pre');
rginda4bba5e12012-06-20 16:15:30 -07002293 copySource.textContent = str;
2294 copySource.style.cssText = (
2295 '-webkit-user-select: text;' +
2296 'position: absolute;' +
2297 'top: -99px');
2298
2299 this.document_.body.appendChild(copySource);
rgindafaa74742012-08-21 13:34:03 -07002300
rginda4bba5e12012-06-20 16:15:30 -07002301 var selection = this.document_.getSelection();
rgindafaa74742012-08-21 13:34:03 -07002302 var anchorNode = selection.anchorNode;
2303 var anchorOffset = selection.anchorOffset;
2304 var focusNode = selection.focusNode;
2305 var focusOffset = selection.focusOffset;
2306
rginda4bba5e12012-06-20 16:15:30 -07002307 selection.selectAllChildren(copySource);
2308
rgindaa09e7332012-08-17 12:49:51 -07002309 hterm.copySelectionToClipboard(this.document_);
rginda4bba5e12012-06-20 16:15:30 -07002310
rgindafaa74742012-08-21 13:34:03 -07002311 selection.collapse(anchorNode, anchorOffset);
2312 selection.extend(focusNode, focusOffset);
2313
rginda4bba5e12012-06-20 16:15:30 -07002314 copySource.parentNode.removeChild(copySource);
2315};
2316
rgindaa09e7332012-08-17 12:49:51 -07002317hterm.Terminal.prototype.getSelectionText = function() {
2318 var selection = this.scrollPort_.selection;
2319 selection.sync();
2320
2321 if (selection.isCollapsed)
2322 return null;
2323
2324
2325 // Start offset measures from the beginning of the line.
2326 var startOffset = selection.startOffset;
2327 var node = selection.startNode;
Robert Ginda0d190502012-10-02 10:59:00 -07002328
Robert Gindafdbb3f22012-09-06 20:23:06 -07002329 if (node.nodeName != 'X-ROW') {
2330 // If the selection doesn't start on an x-row node, then it must be
2331 // somewhere inside the x-row. Add any characters from previous siblings
2332 // into the start offset.
Robert Ginda0d190502012-10-02 10:59:00 -07002333
2334 if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') {
2335 // If node is the text node in a styled span, move up to the span node.
2336 node = node.parentNode;
2337 }
2338
Robert Gindafdbb3f22012-09-06 20:23:06 -07002339 while (node.previousSibling) {
2340 node = node.previousSibling;
2341 startOffset += node.textContent.length;
2342 }
rgindaa09e7332012-08-17 12:49:51 -07002343 }
2344
2345 // End offset measures from the end of the line.
2346 var endOffset = selection.endNode.textContent.length - selection.endOffset;
2347 var node = selection.endNode;
Robert Ginda0d190502012-10-02 10:59:00 -07002348
Robert Gindafdbb3f22012-09-06 20:23:06 -07002349 if (node.nodeName != 'X-ROW') {
2350 // If the selection doesn't end on an x-row node, then it must be
2351 // somewhere inside the x-row. Add any characters from following siblings
2352 // into the end offset.
Robert Ginda0d190502012-10-02 10:59:00 -07002353
2354 if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') {
2355 // If node is the text node in a styled span, move up to the span node.
2356 node = node.parentNode;
2357 }
2358
Robert Gindafdbb3f22012-09-06 20:23:06 -07002359 while (node.nextSibling) {
2360 node = node.nextSibling;
2361 endOffset += node.textContent.length;
2362 }
rgindaa09e7332012-08-17 12:49:51 -07002363 }
2364
2365 var rv = this.getRowsText(selection.startRow.rowIndex,
2366 selection.endRow.rowIndex + 1);
2367 return rv.substring(startOffset, rv.length - endOffset);
2368};
2369
rginda4bba5e12012-06-20 16:15:30 -07002370/**
2371 * Copy the current selection to the system clipboard, then clear it after a
2372 * short delay.
2373 */
2374hterm.Terminal.prototype.copySelectionToClipboard = function() {
rgindaa09e7332012-08-17 12:49:51 -07002375 var text = this.getSelectionText();
2376 if (text != null)
2377 this.copyStringToClipboard(text);
rginda4bba5e12012-06-20 16:15:30 -07002378};
2379
rgindaf0090c92012-02-10 14:58:52 -08002380hterm.Terminal.prototype.overlaySize = function() {
2381 this.showOverlay(this.screenSize.width + 'x' + this.screenSize.height);
2382};
2383
rginda87b86462011-12-14 13:48:03 -08002384/**
2385 * Invoked by hterm.Terminal.Keyboard when a VT keystroke is detected.
2386 *
Robert Ginda8cb7d902013-06-20 14:37:18 -07002387 * @param {string} string The VT string representing the keystroke, in UTF-16.
rginda87b86462011-12-14 13:48:03 -08002388 */
2389hterm.Terminal.prototype.onVTKeystroke = function(string) {
rginda9f5222b2012-03-05 11:53:28 -08002390 if (this.scrollOnKeystroke_)
rginda87b86462011-12-14 13:48:03 -08002391 this.scrollPort_.scrollRowToBottom(this.getRowCount());
2392
Robert Ginda8cb7d902013-06-20 14:37:18 -07002393 this.io.onVTKeystroke(this.keyboard.encode(string));
rginda8ba33642011-12-14 12:31:31 -08002394};
2395
2396/**
rgindad5613292012-06-19 15:40:37 -07002397 * Add the terminalRow and terminalColumn properties to mouse events and
2398 * then forward on to onMouse().
2399 *
2400 * The terminalRow and terminalColumn properties contain the (row, column)
2401 * coordinates for the mouse event.
2402 */
2403hterm.Terminal.prototype.onMouse_ = function(e) {
rgindafaa74742012-08-21 13:34:03 -07002404 if (e.processedByTerminalHandler_) {
2405 // We register our event handlers on the document, as well as the cursor
2406 // and the scroll blocker. Mouse events that occur on the cursor or
2407 // scroll blocker will also appear on the document, but we don't want to
2408 // process them twice.
2409 //
2410 // We can't just prevent bubbling because that has other side effects, so
2411 // we decorate the event object with this property instead.
2412 return;
2413 }
2414
2415 e.processedByTerminalHandler_ = true;
2416
rginda4bba5e12012-06-20 16:15:30 -07002417 if (e.type == 'mousedown' && e.which == this.mousePasteButton) {
2418 this.paste();
2419 return;
2420 }
2421
2422 if (e.type == 'mouseup' && e.which == 1 && this.copyOnSelect &&
2423 !this.document_.getSelection().isCollapsed) {
rgindafaa74742012-08-21 13:34:03 -07002424 hterm.copySelectionToClipboard(this.document_);
rginda4bba5e12012-06-20 16:15:30 -07002425 return;
2426 }
2427
rgindad5613292012-06-19 15:40:37 -07002428 e.terminalRow = parseInt((e.clientY - this.scrollPort_.visibleRowTopMargin) /
2429 this.scrollPort_.characterSize.height) + 1;
2430 e.terminalColumn = parseInt(e.clientX /
2431 this.scrollPort_.characterSize.width) + 1;
2432
2433 if (e.type == 'mousedown') {
2434 if (e.terminalColumn > this.screenSize.width) {
2435 // Mousedown in the scrollbar area.
2436 return;
2437 }
2438
2439 if (!this.enableMouseDragScroll) {
2440 // Move the scroll-blocker into place if we want to keep the scrollport
2441 // from scrolling.
2442 this.scrollBlockerNode_.engaged = true;
2443 this.scrollBlockerNode_.style.top = (e.clientY - 5) + 'px';
2444 this.scrollBlockerNode_.style.left = (e.clientX - 5) + 'px';
2445 }
2446 } else if (this.scrollBlockerNode_.engaged &&
2447 (e.type == 'mousemove' || e.type == 'mouseup')) {
2448 // Disengage the scroll-blocker after one of these events.
2449 this.scrollBlockerNode_.engaged = false;
2450 this.scrollBlockerNode_.style.top = '-99px';
2451 }
2452
rgindafaa74742012-08-21 13:34:03 -07002453 this.onMouse(e);
rgindad5613292012-06-19 15:40:37 -07002454};
2455
2456/**
2457 * Clients should override this if they care to know about mouse events.
2458 *
2459 * The event parameter will be a normal DOM mouse click event with additional
2460 * 'terminalRow' and 'terminalColumn' properties.
2461 */
2462hterm.Terminal.prototype.onMouse = function(e) { };
2463
2464/**
rginda8e92a692012-05-20 19:37:20 -07002465 * React when focus changes.
2466 */
2467hterm.Terminal.prototype.onFocusChange_ = function(state) {
2468 this.cursorNode_.setAttribute('focus', state ? 'true' : 'false');
2469};
2470
2471/**
rginda8ba33642011-12-14 12:31:31 -08002472 * React when the ScrollPort is scrolled.
2473 */
2474hterm.Terminal.prototype.onScroll_ = function() {
2475 this.scheduleSyncCursorPosition_();
2476};
2477
2478/**
rginda9846e2f2012-01-27 13:53:33 -08002479 * React when text is pasted into the scrollPort.
2480 */
2481hterm.Terminal.prototype.onPaste_ = function(e) {
Robert Ginda8cb7d902013-06-20 14:37:18 -07002482 this.onVTKeystroke(e.text.replace(/\n/mg, '\r'));
rginda9846e2f2012-01-27 13:53:33 -08002483};
2484
2485/**
rgindaa09e7332012-08-17 12:49:51 -07002486 * React when the user tries to copy from the scrollPort.
2487 */
2488hterm.Terminal.prototype.onCopy_ = function(e) {
2489 e.preventDefault();
rgindafaa74742012-08-21 13:34:03 -07002490 this.copySelectionToClipboard();
rgindaa09e7332012-08-17 12:49:51 -07002491};
2492
2493/**
rginda8ba33642011-12-14 12:31:31 -08002494 * React when the ScrollPort is resized.
rgindac9bc5502012-01-18 11:48:44 -08002495 *
2496 * Note: This function should not directly contain code that alters the internal
2497 * state of the terminal. That kind of code belongs in realizeWidth or
2498 * realizeHeight, so that it can be executed synchronously in the case of a
2499 * programmatic width change.
rginda8ba33642011-12-14 12:31:31 -08002500 */
2501hterm.Terminal.prototype.onResize_ = function() {
rgindac9bc5502012-01-18 11:48:44 -08002502 var columnCount = Math.floor(this.scrollPort_.getScreenWidth() /
rginda35c456b2012-02-09 17:29:05 -08002503 this.scrollPort_.characterSize.width);
2504 var rowCount = Math.floor(this.scrollPort_.getScreenHeight() /
2505 this.scrollPort_.characterSize.height);
2506
Robert Ginda4e83f3a2012-09-04 15:25:25 -07002507 if (columnCount <= 0 || rowCount <= 0) {
rginda35c456b2012-02-09 17:29:05 -08002508 // We avoid these situations since they happen sometimes when the terminal
Robert Ginda4e83f3a2012-09-04 15:25:25 -07002509 // gets removed from the document or during the initial load, and we can't
2510 // deal with that.
rginda35c456b2012-02-09 17:29:05 -08002511 return;
2512 }
2513
rgindaa8ba17d2012-08-15 14:41:10 -07002514 var isNewSize = (columnCount != this.screenSize.width ||
2515 rowCount != this.screenSize.height);
2516
2517 // We do this even if the size didn't change, just to be sure everything is
2518 // in sync.
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +04002519 this.realizeSize_(columnCount, rowCount);
rgindaf522ce02012-04-17 17:49:17 -07002520 this.showZoomWarning_(this.scrollPort_.characterSize.zoomFactor != 1);
rgindaa8ba17d2012-08-15 14:41:10 -07002521
2522 if (isNewSize)
2523 this.overlaySize();
2524
2525 this.scheduleSyncCursorPosition_();
rginda8ba33642011-12-14 12:31:31 -08002526};
2527
2528/**
2529 * Service the cursor blink timeout.
2530 */
2531hterm.Terminal.prototype.onCursorBlink_ = function() {
rginda87b86462011-12-14 13:48:03 -08002532 if (this.cursorNode_.style.opacity == '0') {
2533 this.cursorNode_.style.opacity = '1';
rginda8ba33642011-12-14 12:31:31 -08002534 } else {
rginda87b86462011-12-14 13:48:03 -08002535 this.cursorNode_.style.opacity = '0';
rginda8ba33642011-12-14 12:31:31 -08002536 }
2537};
David Reveman8f552492012-03-28 12:18:41 -04002538
2539/**
2540 * Set the scrollbar-visible mode bit.
2541 *
2542 * If scrollbar-visible is on, the vertical scrollbar will be visible.
2543 * Otherwise it will not.
2544 *
2545 * Defaults to on.
2546 *
2547 * @param {boolean} state True to set scrollbar-visible mode, false to unset.
2548 */
2549hterm.Terminal.prototype.setScrollbarVisible = function(state) {
2550 this.scrollPort_.setScrollbarVisible(state);
2551};