blob: 4fe47b86c2fd0f634432eb7b1a18cf9e2c137375 [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
Masaya Suzuki273aa982014-05-31 07:25:55 +09007lib.rtdep('lib.colors', 'lib.PreferenceManager', 'lib.resource', 'lib.wc',
Rob Spiesf4e90e82015-01-28 12:10:13 -08008 'lib.f', 'hterm.Keyboard', 'hterm.Options', 'hterm.PreferenceManager',
Ricky Liang48f05cb2013-12-31 23:35:29 +08009 'hterm.Screen', 'hterm.ScrollPort', 'hterm.Size',
10 'hterm.TextAttributes', 'hterm.VT');
rgindacbbd7482012-06-13 15:06:16 -070011
rginda8ba33642011-12-14 12:31:31 -080012/**
13 * Constructor for the Terminal class.
14 *
15 * A Terminal pulls together the hterm.ScrollPort, hterm.Screen and hterm.VT100
16 * classes to provide the complete terminal functionality.
17 *
18 * There are a number of lower-level Terminal methods that can be called
19 * directly to manipulate the cursor, text, scroll region, and other terminal
20 * attributes. However, the primary method is interpret(), which parses VT
21 * escape sequences and invokes the appropriate Terminal methods.
22 *
23 * This class was heavily influenced by Cory Maccarrone's Framebuffer class.
24 *
25 * TODO(rginda): Eventually we're going to need to support characters which are
26 * displayed twice as wide as standard latin characters. This is to support
27 * CJK (and possibly other character sets).
rginda9f5222b2012-03-05 11:53:28 -080028 *
Robert Ginda57f03b42012-09-13 11:02:48 -070029 * @param {string} opt_profileId Optional preference profile name. If not
rginda9f5222b2012-03-05 11:53:28 -080030 * provided, defaults to 'default'.
rginda8ba33642011-12-14 12:31:31 -080031 */
Robert Ginda57f03b42012-09-13 11:02:48 -070032hterm.Terminal = function(opt_profileId) {
33 this.profileId_ = null;
rginda9f5222b2012-03-05 11:53:28 -080034
rginda8ba33642011-12-14 12:31:31 -080035 // Two screen instances.
36 this.primaryScreen_ = new hterm.Screen();
37 this.alternateScreen_ = new hterm.Screen();
38
39 // The "current" screen.
40 this.screen_ = this.primaryScreen_;
41
rginda8ba33642011-12-14 12:31:31 -080042 // The local notion of the screen size. ScreenBuffers also have a size which
43 // indicates their present size. During size changes, the two may disagree.
44 // Also, the inactive screen's size is not altered until it is made the active
45 // screen.
46 this.screenSize = new hterm.Size(0, 0);
47
rginda8ba33642011-12-14 12:31:31 -080048 // The scroll port we'll be using to display the visible rows.
rginda35c456b2012-02-09 17:29:05 -080049 this.scrollPort_ = new hterm.ScrollPort(this);
rginda8ba33642011-12-14 12:31:31 -080050 this.scrollPort_.subscribe('resize', this.onResize_.bind(this));
51 this.scrollPort_.subscribe('scroll', this.onScroll_.bind(this));
rginda9846e2f2012-01-27 13:53:33 -080052 this.scrollPort_.subscribe('paste', this.onPaste_.bind(this));
rgindaa09e7332012-08-17 12:49:51 -070053 this.scrollPort_.onCopy = this.onCopy_.bind(this);
rginda8ba33642011-12-14 12:31:31 -080054
rginda87b86462011-12-14 13:48:03 -080055 // The div that contains this terminal.
56 this.div_ = null;
57
rgindac9bc5502012-01-18 11:48:44 -080058 // The document that contains the scrollPort. Defaulted to the global
59 // document here so that the terminal is functional even if it hasn't been
60 // inserted into a document yet, but re-set in decorate().
61 this.document_ = window.document;
rginda87b86462011-12-14 13:48:03 -080062
rginda8ba33642011-12-14 12:31:31 -080063 // The rows that have scrolled off screen and are no longer addressable.
64 this.scrollbackRows_ = [];
65
rgindac9bc5502012-01-18 11:48:44 -080066 // Saved tab stops.
67 this.tabStops_ = [];
68
David Benjamin66e954d2012-05-05 21:08:12 -040069 // Keep track of whether default tab stops have been erased; after a TBC
70 // clears all tab stops, defaults aren't restored on resize until a reset.
71 this.defaultTabStops = true;
72
rginda8ba33642011-12-14 12:31:31 -080073 // The VT's notion of the top and bottom rows. Used during some VT
74 // cursor positioning and scrolling commands.
75 this.vtScrollTop_ = null;
76 this.vtScrollBottom_ = null;
77
78 // The DIV element for the visible cursor.
79 this.cursorNode_ = null;
80
Robert Ginda830583c2013-08-07 13:20:46 -070081 // The current cursor shape of the terminal.
82 this.cursorShape_ = hterm.Terminal.cursorShape.BLOCK;
83
84 // The current color of the cursor.
85 this.cursorColor_ = null;
86
Robert Gindaea2183e2014-07-17 09:51:51 -070087 // Cursor blink on/off cycle in ms, overwritten by prefs once they're loaded.
88 this.cursorBlinkCycle_ = [100, 100];
89
90 // Pre-bound onCursorBlink_ handler, so we don't have to do this for each
91 // cursor on/off servicing.
92 this.myOnCursorBlink_ = this.onCursorBlink_.bind(this);
93
rginda9f5222b2012-03-05 11:53:28 -080094 // These prefs are cached so we don't have to read from local storage with
Robert Ginda57f03b42012-09-13 11:02:48 -070095 // each output and keystroke. They are initialized by the preference manager.
Robert Ginda8cb7d902013-06-20 14:37:18 -070096 this.backgroundColor_ = null;
97 this.foregroundColor_ = null;
Robert Ginda57f03b42012-09-13 11:02:48 -070098 this.scrollOnOutput_ = null;
99 this.scrollOnKeystroke_ = null;
rginda9f5222b2012-03-05 11:53:28 -0800100
Robert Ginda928cf632014-03-05 15:07:41 -0800101 // True if we should send mouse events to the vt, false if we want them
102 // to manage the local text selection.
103 this.reportMouseEvents_ = false;
104
rgindaf0090c92012-02-10 14:58:52 -0800105 // Terminal bell sound.
106 this.bellAudio_ = this.document_.createElement('audio');
rgindaf0090c92012-02-10 14:58:52 -0800107 this.bellAudio_.setAttribute('preload', 'auto');
108
Michael Kelly485ecd12014-06-09 11:41:56 -0400109 // All terminal bell notifications that have been generated (not necessarily
110 // shown).
111 this.bellNotificationList_ = [];
112
113 // Whether we have permission to display notifications.
114 this.desktopNotificationBell_ = false;
Michael Kelly485ecd12014-06-09 11:41:56 -0400115
rginda6d397402012-01-17 10:58:29 -0800116 // Cursor position and attributes saved with DECSC.
117 this.savedOptions_ = {};
118
rginda8ba33642011-12-14 12:31:31 -0800119 // The current mode bits for the terminal.
120 this.options_ = new hterm.Options();
121
122 // Timeouts we might need to clear.
123 this.timeouts_ = {};
rginda87b86462011-12-14 13:48:03 -0800124
125 // The VT escape sequence interpreter.
rginda0f5c0292012-01-13 11:00:13 -0800126 this.vt = new hterm.VT(this);
rginda87b86462011-12-14 13:48:03 -0800127
rgindafeaf3142012-01-31 15:14:20 -0800128 // The keyboard hander.
129 this.keyboard = new hterm.Keyboard(this);
130
rginda87b86462011-12-14 13:48:03 -0800131 // General IO interface that can be given to third parties without exposing
132 // the entire terminal object.
133 this.io = new hterm.Terminal.IO(this);
rgindac9bc5502012-01-18 11:48:44 -0800134
rgindad5613292012-06-19 15:40:37 -0700135 // True if mouse-click-drag should scroll the terminal.
136 this.enableMouseDragScroll = true;
137
Robert Ginda57f03b42012-09-13 11:02:48 -0700138 this.copyOnSelect = null;
rginda4bba5e12012-06-20 16:15:30 -0700139 this.mousePasteButton = null;
rginda4bba5e12012-06-20 16:15:30 -0700140
Rob Spies0bec09b2014-06-06 15:58:09 -0700141 // Whether to use the default window copy behaviour.
142 this.useDefaultWindowCopy = false;
143
144 this.clearSelectionAfterCopy = true;
145
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400146 this.realizeSize_(80, 24);
rgindac9bc5502012-01-18 11:48:44 -0800147 this.setDefaultTabStops();
Robert Ginda57f03b42012-09-13 11:02:48 -0700148
149 this.setProfile(opt_profileId || 'default',
150 function() { this.onTerminalReady() }.bind(this));
rginda87b86462011-12-14 13:48:03 -0800151};
152
153/**
Robert Ginda830583c2013-08-07 13:20:46 -0700154 * Possible cursor shapes.
155 */
156hterm.Terminal.cursorShape = {
157 BLOCK: 'BLOCK',
158 BEAM: 'BEAM',
159 UNDERLINE: 'UNDERLINE'
160};
161
162/**
Robert Ginda57f03b42012-09-13 11:02:48 -0700163 * Clients should override this to be notified when the terminal is ready
164 * for use.
165 *
166 * The terminal initialization is asynchronous, and shouldn't be used before
167 * this method is called.
168 */
169hterm.Terminal.prototype.onTerminalReady = function() { };
170
171/**
rginda35c456b2012-02-09 17:29:05 -0800172 * Default tab with of 8 to match xterm.
173 */
174hterm.Terminal.prototype.tabWidth = 8;
175
176/**
rginda9f5222b2012-03-05 11:53:28 -0800177 * Select a preference profile.
178 *
179 * This will load the terminal preferences for the given profile name and
180 * associate subsequent preference changes with the new preference profile.
181 *
182 * @param {string} newName The name of the preference profile. Forward slash
183 * characters will be removed from the name.
Robert Ginda57f03b42012-09-13 11:02:48 -0700184 * @param {function} opt_callback Optional callback to invoke when the profile
185 * transition is complete.
rginda9f5222b2012-03-05 11:53:28 -0800186 */
Robert Ginda57f03b42012-09-13 11:02:48 -0700187hterm.Terminal.prototype.setProfile = function(profileId, opt_callback) {
188 this.profileId_ = profileId.replace(/\//g, '');
rginda9f5222b2012-03-05 11:53:28 -0800189
Robert Ginda57f03b42012-09-13 11:02:48 -0700190 var terminal = this;
rginda9f5222b2012-03-05 11:53:28 -0800191
Robert Ginda57f03b42012-09-13 11:02:48 -0700192 if (this.prefs_)
193 this.prefs_.deactivate();
rginda9f5222b2012-03-05 11:53:28 -0800194
Robert Ginda57f03b42012-09-13 11:02:48 -0700195 this.prefs_ = new hterm.PreferenceManager(this.profileId_);
196 this.prefs_.addObservers(null, {
Robert Ginda034ffa72015-02-26 14:02:37 -0800197 'alt-gr-mode': function(v) {
198 if (v == null) {
199 if (navigator.language.toLowerCase() == 'en-us') {
200 v = 'none';
201 } else {
202 v = 'right-alt';
203 }
204 } else if (typeof v == 'string') {
205 v = v.toLowerCase();
206 } else {
207 v = 'none';
208 }
209
210 if (!/^(none|ctrl-alt|left-alt|right-alt)$/.test(v))
211 v = 'none';
212
213 terminal.keyboard.altGrMode = v;
214 },
215
Andrew de los Reyes574e10e2013-04-04 09:31:57 -0700216 'alt-backspace-is-meta-backspace': function(v) {
217 terminal.keyboard.altBackspaceIsMetaBackspace = v;
218 },
219
Robert Ginda57f03b42012-09-13 11:02:48 -0700220 'alt-is-meta': function(v) {
221 terminal.keyboard.altIsMeta = v;
222 },
223
224 'alt-sends-what': function(v) {
225 if (!/^(escape|8-bit|browser-key)$/.test(v))
226 v = 'escape';
227
228 terminal.keyboard.altSendsWhat = v;
229 },
230
231 'audible-bell-sound': function(v) {
Robert Gindab4839c22013-02-28 16:52:10 -0800232 var ary = v.match(/^lib-resource:(\S+)/);
233 if (ary) {
234 terminal.bellAudio_.setAttribute('src',
235 lib.resource.getDataUrl(ary[1]));
236 } else {
237 terminal.bellAudio_.setAttribute('src', v);
238 }
Robert Ginda57f03b42012-09-13 11:02:48 -0700239 },
240
Michael Kelly485ecd12014-06-09 11:41:56 -0400241 'desktop-notification-bell': function(v) {
242 if (v && Notification) {
Robert Ginda348dc2b2014-06-24 14:42:23 -0700243 terminal.desktopNotificationBell_ =
Michael Kellyb8067862014-06-26 12:59:47 -0400244 Notification.permission === 'granted';
245 if (!terminal.desktopNotificationBell_) {
246 // Note: We don't call Notification.requestPermission here because
247 // Chrome requires the call be the result of a user action (such as an
248 // onclick handler), and pref listeners are run asynchronously.
249 //
250 // A way of working around this would be to display a dialog in the
251 // terminal with a "click-to-request-permission" button.
252 console.warn('desktop-notification-bell is true but we do not have ' +
253 'permission to display notifications.');
Michael Kelly485ecd12014-06-09 11:41:56 -0400254 }
255 } else {
256 terminal.desktopNotificationBell_ = false;
257 }
258 },
259
Robert Ginda57f03b42012-09-13 11:02:48 -0700260 'background-color': function(v) {
261 terminal.setBackgroundColor(v);
262 },
263
264 'background-image': function(v) {
265 terminal.scrollPort_.setBackgroundImage(v);
266 },
267
268 'background-size': function(v) {
269 terminal.scrollPort_.setBackgroundSize(v);
270 },
271
272 'background-position': function(v) {
273 terminal.scrollPort_.setBackgroundPosition(v);
274 },
275
276 'backspace-sends-backspace': function(v) {
277 terminal.keyboard.backspaceSendsBackspace = v;
278 },
279
Brad Town18654b62015-03-12 00:27:45 -0700280 'character-map-overrides': function(v) {
281 if (!(v == null || v instanceof Object)) {
282 console.warn('Preference character-map-modifications is not an ' +
283 'object: ' + v);
284 return;
285 }
286
287 for (var code in v) {
288 var glmap = hterm.VT.CharacterMap.maps[code].glmap;
289 for (var received in v[code]) {
290 glmap[received] = v[code][received];
291 }
292 hterm.VT.CharacterMap.maps[code].reset(glmap);
293 }
294 },
295
Robert Ginda57f03b42012-09-13 11:02:48 -0700296 'cursor-blink': function(v) {
297 terminal.setCursorBlink(!!v);
298 },
299
Robert Gindaea2183e2014-07-17 09:51:51 -0700300 'cursor-blink-cycle': function(v) {
301 if (v instanceof Array &&
302 typeof v[0] == 'number' &&
303 typeof v[1] == 'number') {
304 terminal.cursorBlinkCycle_ = v;
305 } else if (typeof v == 'number') {
306 terminal.cursorBlinkCycle_ = [v, v];
307 } else {
308 // Fast blink indicates an error.
309 terminal.cursorBlinkCycle_ = [100, 100];
310 }
311 },
312
Robert Ginda57f03b42012-09-13 11:02:48 -0700313 'cursor-color': function(v) {
314 terminal.setCursorColor(v);
315 },
316
317 'color-palette-overrides': function(v) {
318 if (!(v == null || v instanceof Object || v instanceof Array)) {
319 console.warn('Preference color-palette-overrides is not an array or ' +
320 'object: ' + v);
321 return;
rginda9f5222b2012-03-05 11:53:28 -0800322 }
rginda9f5222b2012-03-05 11:53:28 -0800323
Robert Ginda57f03b42012-09-13 11:02:48 -0700324 lib.colors.colorPalette = lib.colors.stockColorPalette.concat();
rginda39bdf6f2012-04-10 16:50:55 -0700325
Robert Ginda57f03b42012-09-13 11:02:48 -0700326 if (v) {
327 for (var key in v) {
328 var i = parseInt(key);
329 if (isNaN(i) || i < 0 || i > 255) {
330 console.log('Invalid value in palette: ' + key + ': ' + v[key]);
331 continue;
332 }
333
334 if (v[i]) {
335 var rgb = lib.colors.normalizeCSS(v[i]);
336 if (rgb)
337 lib.colors.colorPalette[i] = rgb;
338 }
339 }
rginda30f20f62012-04-05 16:36:19 -0700340 }
rginda30f20f62012-04-05 16:36:19 -0700341
Robert Ginda57f03b42012-09-13 11:02:48 -0700342 terminal.primaryScreen_.textAttributes.resetColorPalette()
343 terminal.alternateScreen_.textAttributes.resetColorPalette();
344 },
rginda30f20f62012-04-05 16:36:19 -0700345
Robert Ginda57f03b42012-09-13 11:02:48 -0700346 'copy-on-select': function(v) {
347 terminal.copyOnSelect = !!v;
348 },
rginda9f5222b2012-03-05 11:53:28 -0800349
Rob Spies0bec09b2014-06-06 15:58:09 -0700350 'use-default-window-copy': function(v) {
351 terminal.useDefaultWindowCopy = !!v;
352 },
353
354 'clear-selection-after-copy': function(v) {
355 terminal.clearSelectionAfterCopy = !!v;
356 },
357
Robert Ginda7e5e9522014-03-14 12:23:58 -0700358 'ctrl-plus-minus-zero-zoom': function(v) {
359 terminal.keyboard.ctrlPlusMinusZeroZoom = v;
360 },
361
Robert Gindafb5a3f92014-05-13 14:12:00 -0700362 'ctrl-c-copy': function(v) {
363 terminal.keyboard.ctrlCCopy = v;
364 },
365
Leonardo Mesquita61e7c312014-01-04 12:53:12 +0100366 'ctrl-v-paste': function(v) {
367 terminal.keyboard.ctrlVPaste = v;
Rob Spiese52e1842014-07-10 15:32:51 -0700368 terminal.scrollPort_.setCtrlVPaste(v);
Leonardo Mesquita61e7c312014-01-04 12:53:12 +0100369 },
370
Masaya Suzuki273aa982014-05-31 07:25:55 +0900371 'east-asian-ambiguous-as-two-column': function(v) {
372 lib.wc.regardCjkAmbiguous = v;
373 },
374
Robert Ginda57f03b42012-09-13 11:02:48 -0700375 'enable-8-bit-control': function(v) {
376 terminal.vt.enable8BitControl = !!v;
377 },
rginda30f20f62012-04-05 16:36:19 -0700378
Robert Ginda57f03b42012-09-13 11:02:48 -0700379 'enable-bold': function(v) {
380 terminal.syncBoldSafeState();
381 },
Philip Douglass959b49d2012-05-30 13:29:29 -0400382
Robert Ginda3e278d72014-03-25 13:18:51 -0700383 'enable-bold-as-bright': function(v) {
384 terminal.primaryScreen_.textAttributes.enableBoldAsBright = !!v;
385 terminal.alternateScreen_.textAttributes.enableBoldAsBright = !!v;
386 },
387
Robert Ginda57f03b42012-09-13 11:02:48 -0700388 'enable-clipboard-write': function(v) {
389 terminal.vt.enableClipboardWrite = !!v;
390 },
Philip Douglass959b49d2012-05-30 13:29:29 -0400391
Robert Ginda3755e752013-05-31 13:34:09 -0700392 'enable-dec12': function(v) {
393 terminal.vt.enableDec12 = !!v;
394 },
395
Robert Ginda57f03b42012-09-13 11:02:48 -0700396 'font-family': function(v) {
397 terminal.syncFontFamily();
398 },
rginda30f20f62012-04-05 16:36:19 -0700399
Robert Ginda57f03b42012-09-13 11:02:48 -0700400 'font-size': function(v) {
401 terminal.setFontSize(v);
402 },
rginda9875d902012-08-20 16:21:57 -0700403
Robert Ginda57f03b42012-09-13 11:02:48 -0700404 'font-smoothing': function(v) {
405 terminal.syncFontFamily();
406 },
rgindade84e382012-04-20 15:39:31 -0700407
Robert Ginda57f03b42012-09-13 11:02:48 -0700408 'foreground-color': function(v) {
409 terminal.setForegroundColor(v);
410 },
rginda30f20f62012-04-05 16:36:19 -0700411
Robert Ginda57f03b42012-09-13 11:02:48 -0700412 'home-keys-scroll': function(v) {
413 terminal.keyboard.homeKeysScroll = v;
414 },
rginda4bba5e12012-06-20 16:15:30 -0700415
Robert Ginda57f03b42012-09-13 11:02:48 -0700416 'max-string-sequence': function(v) {
417 terminal.vt.maxStringSequence = v;
418 },
rginda11057d52012-04-25 12:29:56 -0700419
Andrew de los Reyes6af23ae2013-04-04 14:17:50 -0700420 'media-keys-are-fkeys': function(v) {
421 terminal.keyboard.mediaKeysAreFKeys = v;
422 },
423
Robert Ginda57f03b42012-09-13 11:02:48 -0700424 'meta-sends-escape': function(v) {
425 terminal.keyboard.metaSendsEscape = v;
426 },
rginda30f20f62012-04-05 16:36:19 -0700427
Robert Ginda57f03b42012-09-13 11:02:48 -0700428 'mouse-paste-button': function(v) {
429 terminal.syncMousePasteButton();
430 },
rgindaa8ba17d2012-08-15 14:41:10 -0700431
Robert Gindae76aa9f2014-03-14 12:29:12 -0700432 'page-keys-scroll': function(v) {
433 terminal.keyboard.pageKeysScroll = v;
434 },
435
Robert Ginda40932892012-12-10 17:26:40 -0800436 'pass-alt-number': function(v) {
437 if (v == null) {
438 var osx = window.navigator.userAgent.match(/Mac OS X/);
439
440 // Let Alt-1..9 pass to the browser (to control tab switching) on
441 // non-OS X systems, or if hterm is not opened in an app window.
442 v = (!osx && hterm.windowType != 'popup');
443 }
444
445 terminal.passAltNumber = v;
446 },
447
448 'pass-ctrl-number': function(v) {
449 if (v == null) {
450 var osx = window.navigator.userAgent.match(/Mac OS X/);
451
452 // Let Ctrl-1..9 pass to the browser (to control tab switching) on
453 // non-OS X systems, or if hterm is not opened in an app window.
454 v = (!osx && hterm.windowType != 'popup');
455 }
456
457 terminal.passCtrlNumber = v;
458 },
459
460 'pass-meta-number': function(v) {
461 if (v == null) {
462 var osx = window.navigator.userAgent.match(/Mac OS X/);
463
464 // Let Meta-1..9 pass to the browser (to control tab switching) on
465 // OS X systems, or if hterm is not opened in an app window.
466 v = (osx && hterm.windowType != 'popup');
467 }
468
469 terminal.passMetaNumber = v;
470 },
471
Marius Schilder77857b32014-05-14 16:21:26 -0700472 'pass-meta-v': function(v) {
Marius Schilder1a567812014-05-15 20:30:02 -0700473 terminal.keyboard.passMetaV = v;
Marius Schilder77857b32014-05-14 16:21:26 -0700474 },
475
Robert Ginda8cb7d902013-06-20 14:37:18 -0700476 'receive-encoding': function(v) {
477 if (!(/^(utf-8|raw)$/).test(v)) {
478 console.warn('Invalid value for "receive-encoding": ' + v);
479 v = 'utf-8';
480 }
481
482 terminal.vt.characterEncoding = v;
483 },
484
Robert Ginda57f03b42012-09-13 11:02:48 -0700485 'scroll-on-keystroke': function(v) {
486 terminal.scrollOnKeystroke_ = v;
487 },
rginda9f5222b2012-03-05 11:53:28 -0800488
Robert Ginda57f03b42012-09-13 11:02:48 -0700489 'scroll-on-output': function(v) {
490 terminal.scrollOnOutput_ = v;
491 },
rginda30f20f62012-04-05 16:36:19 -0700492
Robert Ginda57f03b42012-09-13 11:02:48 -0700493 'scrollbar-visible': function(v) {
494 terminal.setScrollbarVisible(v);
495 },
rginda9f5222b2012-03-05 11:53:28 -0800496
Rob Spies49039e52014-12-17 13:40:04 -0800497 'scroll-wheel-move-multiplier': function(v) {
498 terminal.setScrollWheelMoveMultipler(v);
499 },
500
Robert Ginda8cb7d902013-06-20 14:37:18 -0700501 'send-encoding': function(v) {
502 if (!(/^(utf-8|raw)$/).test(v)) {
503 console.warn('Invalid value for "send-encoding": ' + v);
504 v = 'utf-8';
505 }
506
507 terminal.keyboard.characterEncoding = v;
508 },
509
Robert Ginda57f03b42012-09-13 11:02:48 -0700510 'shift-insert-paste': function(v) {
511 terminal.keyboard.shiftInsertPaste = v;
512 },
rginda9f5222b2012-03-05 11:53:28 -0800513
Robert Gindae76aa9f2014-03-14 12:29:12 -0700514 'user-css': function(v) {
515 terminal.scrollPort_.setUserCss(v);
Robert Ginda57f03b42012-09-13 11:02:48 -0700516 }
517 });
rginda30f20f62012-04-05 16:36:19 -0700518
Robert Ginda57f03b42012-09-13 11:02:48 -0700519 this.prefs_.readStorage(function() {
rginda9f5222b2012-03-05 11:53:28 -0800520 this.prefs_.notifyAll();
Robert Ginda57f03b42012-09-13 11:02:48 -0700521
522 if (opt_callback)
523 opt_callback();
524 }.bind(this));
rginda9f5222b2012-03-05 11:53:28 -0800525};
526
Rob Spies56953412014-04-28 14:09:47 -0700527
528/**
529 * Returns the preferences manager used for configuring this terminal.
530 */
531hterm.Terminal.prototype.getPrefs = function() {
532 return this.prefs_;
533};
534
Robert Gindaa063b202014-07-21 11:08:25 -0700535/**
536 * Enable or disable bracketed paste mode.
537 */
538hterm.Terminal.prototype.setBracketedPaste = function(state) {
539 this.options_.bracketedPaste = state;
540};
Rob Spies56953412014-04-28 14:09:47 -0700541
rginda8e92a692012-05-20 19:37:20 -0700542/**
543 * Set the color for the cursor.
544 *
545 * If you want this setting to persist, set it through prefs_, rather than
546 * with this method.
547 */
548hterm.Terminal.prototype.setCursorColor = function(color) {
Robert Ginda830583c2013-08-07 13:20:46 -0700549 this.cursorColor_ = color;
rginda8e92a692012-05-20 19:37:20 -0700550 this.cursorNode_.style.backgroundColor = color;
551 this.cursorNode_.style.borderColor = color;
552};
553
554/**
555 * Return the current cursor color as a string.
556 */
557hterm.Terminal.prototype.getCursorColor = function() {
Robert Ginda830583c2013-08-07 13:20:46 -0700558 return this.cursorColor_;
rginda8e92a692012-05-20 19:37:20 -0700559};
560
561/**
rgindad5613292012-06-19 15:40:37 -0700562 * Enable or disable mouse based text selection in the terminal.
563 */
564hterm.Terminal.prototype.setSelectionEnabled = function(state) {
565 this.enableMouseDragScroll = state;
rgindad5613292012-06-19 15:40:37 -0700566};
567
568/**
rginda8e92a692012-05-20 19:37:20 -0700569 * Set the background color.
570 *
571 * If you want this setting to persist, set it through prefs_, rather than
572 * with this method.
573 */
574hterm.Terminal.prototype.setBackgroundColor = function(color) {
rgindacbbd7482012-06-13 15:06:16 -0700575 this.backgroundColor_ = lib.colors.normalizeCSS(color);
Robert Ginda57f03b42012-09-13 11:02:48 -0700576 this.primaryScreen_.textAttributes.setDefaults(
577 this.foregroundColor_, this.backgroundColor_);
578 this.alternateScreen_.textAttributes.setDefaults(
579 this.foregroundColor_, this.backgroundColor_);
rginda8e92a692012-05-20 19:37:20 -0700580 this.scrollPort_.setBackgroundColor(color);
581};
582
rginda9f5222b2012-03-05 11:53:28 -0800583/**
584 * Return the current terminal background color.
585 *
586 * Intended for use by other classes, so we don't have to expose the entire
587 * prefs_ object.
588 */
589hterm.Terminal.prototype.getBackgroundColor = function() {
rginda8e92a692012-05-20 19:37:20 -0700590 return this.backgroundColor_;
591};
592
593/**
594 * Set the foreground color.
595 *
596 * If you want this setting to persist, set it through prefs_, rather than
597 * with this method.
598 */
599hterm.Terminal.prototype.setForegroundColor = function(color) {
rgindacbbd7482012-06-13 15:06:16 -0700600 this.foregroundColor_ = lib.colors.normalizeCSS(color);
Robert Ginda57f03b42012-09-13 11:02:48 -0700601 this.primaryScreen_.textAttributes.setDefaults(
602 this.foregroundColor_, this.backgroundColor_);
603 this.alternateScreen_.textAttributes.setDefaults(
604 this.foregroundColor_, this.backgroundColor_);
rginda8e92a692012-05-20 19:37:20 -0700605 this.scrollPort_.setForegroundColor(color);
rginda9f5222b2012-03-05 11:53:28 -0800606};
607
608/**
609 * Return the current terminal foreground color.
610 *
611 * Intended for use by other classes, so we don't have to expose the entire
612 * prefs_ object.
613 */
614hterm.Terminal.prototype.getForegroundColor = function() {
rginda8e92a692012-05-20 19:37:20 -0700615 return this.foregroundColor_;
rginda9f5222b2012-03-05 11:53:28 -0800616};
617
618/**
rginda87b86462011-12-14 13:48:03 -0800619 * Create a new instance of a terminal command and run it with a given
620 * argument string.
621 *
622 * @param {function} commandClass The constructor for a terminal command.
623 * @param {string} argString The argument string to pass to the command.
624 */
625hterm.Terminal.prototype.runCommandClass = function(commandClass, argString) {
rgindaf522ce02012-04-17 17:49:17 -0700626 var environment = this.prefs_.get('environment');
627 if (typeof environment != 'object' || environment == null)
628 environment = {};
629
rginda87b86462011-12-14 13:48:03 -0800630 var self = this;
631 this.command = new commandClass(
632 { argString: argString || '',
633 io: this.io.push(),
rgindaf522ce02012-04-17 17:49:17 -0700634 environment: environment,
rginda87b86462011-12-14 13:48:03 -0800635 onExit: function(code) {
636 self.io.pop();
rgindafeaf3142012-01-31 15:14:20 -0800637 self.uninstallKeyboard();
rginda9875d902012-08-20 16:21:57 -0700638 if (self.prefs_.get('close-on-exit'))
639 window.close();
rginda87b86462011-12-14 13:48:03 -0800640 }
641 });
642
rgindafeaf3142012-01-31 15:14:20 -0800643 this.installKeyboard();
rginda87b86462011-12-14 13:48:03 -0800644 this.command.run();
645};
646
647/**
rgindafeaf3142012-01-31 15:14:20 -0800648 * Returns true if the current screen is the primary screen, false otherwise.
649 */
650hterm.Terminal.prototype.isPrimaryScreen = function() {
rgindaf522ce02012-04-17 17:49:17 -0700651 return this.screen_ == this.primaryScreen_;
rgindafeaf3142012-01-31 15:14:20 -0800652};
653
654/**
655 * Install the keyboard handler for this terminal.
656 *
657 * This will prevent the browser from seeing any keystrokes sent to the
658 * terminal.
659 */
660hterm.Terminal.prototype.installKeyboard = function() {
Rob Spies06533ba2014-04-24 11:20:37 -0700661 this.keyboard.installKeyboard(this.scrollPort_.getDocument().body);
rgindafeaf3142012-01-31 15:14:20 -0800662}
663
664/**
665 * Uninstall the keyboard handler for this terminal.
666 */
667hterm.Terminal.prototype.uninstallKeyboard = function() {
668 this.keyboard.installKeyboard(null);
669}
670
671/**
rginda35c456b2012-02-09 17:29:05 -0800672 * Set the font size for this terminal.
rginda9f5222b2012-03-05 11:53:28 -0800673 *
674 * Call setFontSize(0) to reset to the default font size.
675 *
676 * This function does not modify the font-size preference.
677 *
678 * @param {number} px The desired font size, in pixels.
rginda35c456b2012-02-09 17:29:05 -0800679 */
680hterm.Terminal.prototype.setFontSize = function(px) {
rginda9f5222b2012-03-05 11:53:28 -0800681 if (px === 0)
682 px = this.prefs_.get('font-size');
683
rginda35c456b2012-02-09 17:29:05 -0800684 this.scrollPort_.setFontSize(px);
Ricky Liang48f05cb2013-12-31 23:35:29 +0800685 if (this.wcCssRule_) {
686 this.wcCssRule_.style.width = this.scrollPort_.characterSize.width * 2 +
687 'px';
688 }
rginda35c456b2012-02-09 17:29:05 -0800689};
690
691/**
692 * Get the current font size.
693 */
694hterm.Terminal.prototype.getFontSize = function() {
695 return this.scrollPort_.getFontSize();
696};
697
698/**
rginda8e92a692012-05-20 19:37:20 -0700699 * Get the current font family.
700 */
701hterm.Terminal.prototype.getFontFamily = function() {
702 return this.scrollPort_.getFontFamily();
703};
704
705/**
rginda35c456b2012-02-09 17:29:05 -0800706 * Set the CSS "font-family" for this terminal.
707 */
rginda9f5222b2012-03-05 11:53:28 -0800708hterm.Terminal.prototype.syncFontFamily = function() {
709 this.scrollPort_.setFontFamily(this.prefs_.get('font-family'),
710 this.prefs_.get('font-smoothing'));
711 this.syncBoldSafeState();
712};
713
rginda4bba5e12012-06-20 16:15:30 -0700714/**
715 * Set this.mousePasteButton based on the mouse-paste-button pref,
716 * autodetecting if necessary.
717 */
718hterm.Terminal.prototype.syncMousePasteButton = function() {
719 var button = this.prefs_.get('mouse-paste-button');
720 if (typeof button == 'number') {
721 this.mousePasteButton = button;
722 return;
723 }
724
725 var ary = navigator.userAgent.match(/\(X11;\s+(\S+)/);
726 if (!ary || ary[2] == 'CrOS') {
727 this.mousePasteButton = 2;
728 } else {
729 this.mousePasteButton = 3;
730 }
731};
732
733/**
734 * Enable or disable bold based on the enable-bold pref, autodetecting if
735 * necessary.
736 */
rginda9f5222b2012-03-05 11:53:28 -0800737hterm.Terminal.prototype.syncBoldSafeState = function() {
738 var enableBold = this.prefs_.get('enable-bold');
739 if (enableBold !== null) {
Robert Gindaed016262012-10-26 16:27:09 -0700740 this.primaryScreen_.textAttributes.enableBold = enableBold;
741 this.alternateScreen_.textAttributes.enableBold = enableBold;
rginda9f5222b2012-03-05 11:53:28 -0800742 return;
743 }
744
rgindaf7521392012-02-28 17:20:34 -0800745 var normalSize = this.scrollPort_.measureCharacterSize();
746 var boldSize = this.scrollPort_.measureCharacterSize('bold');
747
748 var isBoldSafe = normalSize.equals(boldSize);
rgindaf7521392012-02-28 17:20:34 -0800749 if (!isBoldSafe) {
750 console.warn('Bold characters disabled: Size of bold weight differs ' +
rgindac9759de2012-03-19 13:21:41 -0700751 'from normal. Font family is: ' +
752 this.scrollPort_.getFontFamily());
rgindaf7521392012-02-28 17:20:34 -0800753 }
rginda9f5222b2012-03-05 11:53:28 -0800754
Robert Gindaed016262012-10-26 16:27:09 -0700755 this.primaryScreen_.textAttributes.enableBold = isBoldSafe;
756 this.alternateScreen_.textAttributes.enableBold = isBoldSafe;
rginda35c456b2012-02-09 17:29:05 -0800757};
758
759/**
rginda87b86462011-12-14 13:48:03 -0800760 * Return a copy of the current cursor position.
761 *
762 * @return {hterm.RowCol} The RowCol object representing the current position.
763 */
764hterm.Terminal.prototype.saveCursor = function() {
765 return this.screen_.cursorPosition.clone();
766};
767
rgindaa19afe22012-01-25 15:40:22 -0800768hterm.Terminal.prototype.getTextAttributes = function() {
769 return this.screen_.textAttributes;
770};
771
rginda1a09aa02012-06-18 21:11:25 -0700772hterm.Terminal.prototype.setTextAttributes = function(textAttributes) {
773 this.screen_.textAttributes = textAttributes;
774};
775
rginda87b86462011-12-14 13:48:03 -0800776/**
rgindaf522ce02012-04-17 17:49:17 -0700777 * Return the current browser zoom factor applied to the terminal.
778 *
779 * @return {number} The current browser zoom factor.
780 */
781hterm.Terminal.prototype.getZoomFactor = function() {
782 return this.scrollPort_.characterSize.zoomFactor;
783};
784
785/**
rginda9846e2f2012-01-27 13:53:33 -0800786 * Change the title of this terminal's window.
787 */
788hterm.Terminal.prototype.setWindowTitle = function(title) {
rgindafeaf3142012-01-31 15:14:20 -0800789 window.document.title = title;
rginda9846e2f2012-01-27 13:53:33 -0800790};
791
792/**
rginda87b86462011-12-14 13:48:03 -0800793 * Restore a previously saved cursor position.
794 *
795 * @param {hterm.RowCol} cursor The position to restore.
796 */
797hterm.Terminal.prototype.restoreCursor = function(cursor) {
rgindacbbd7482012-06-13 15:06:16 -0700798 var row = lib.f.clamp(cursor.row, 0, this.screenSize.height - 1);
799 var column = lib.f.clamp(cursor.column, 0, this.screenSize.width - 1);
rginda35c456b2012-02-09 17:29:05 -0800800 this.screen_.setCursorPosition(row, column);
801 if (cursor.column > column ||
802 cursor.column == column && cursor.overflow) {
803 this.screen_.cursorPosition.overflow = true;
804 }
rginda87b86462011-12-14 13:48:03 -0800805};
806
807/**
David Benjamin54e8bf62012-06-01 22:31:40 -0400808 * Clear the cursor's overflow flag.
809 */
810hterm.Terminal.prototype.clearCursorOverflow = function() {
811 this.screen_.cursorPosition.overflow = false;
812};
813
814/**
Robert Ginda830583c2013-08-07 13:20:46 -0700815 * Sets the cursor shape
816 */
817hterm.Terminal.prototype.setCursorShape = function(shape) {
818 this.cursorShape_ = shape;
Robert Gindafb1be6a2013-12-11 11:56:22 -0800819 this.restyleCursor_();
Robert Ginda830583c2013-08-07 13:20:46 -0700820}
821
822/**
823 * Get the cursor shape
824 */
825hterm.Terminal.prototype.getCursorShape = function() {
826 return this.cursorShape_;
827}
828
829/**
rginda87b86462011-12-14 13:48:03 -0800830 * Set the width of the terminal, resizing the UI to match.
831 */
832hterm.Terminal.prototype.setWidth = function(columnCount) {
rgindaf0090c92012-02-10 14:58:52 -0800833 if (columnCount == null) {
834 this.div_.style.width = '100%';
835 return;
836 }
837
Robert Ginda26806d12014-07-24 13:44:07 -0700838 this.div_.style.width = Math.ceil(
839 this.scrollPort_.characterSize.width *
840 columnCount + this.scrollPort_.currentScrollbarWidthPx) + 'px';
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400841 this.realizeSize_(columnCount, this.screenSize.height);
rgindac9bc5502012-01-18 11:48:44 -0800842 this.scheduleSyncCursorPosition_();
843};
rginda87b86462011-12-14 13:48:03 -0800844
rgindac9bc5502012-01-18 11:48:44 -0800845/**
rginda35c456b2012-02-09 17:29:05 -0800846 * Set the height of the terminal, resizing the UI to match.
847 */
848hterm.Terminal.prototype.setHeight = function(rowCount) {
rgindaf0090c92012-02-10 14:58:52 -0800849 if (rowCount == null) {
850 this.div_.style.height = '100%';
851 return;
852 }
853
rginda35c456b2012-02-09 17:29:05 -0800854 this.div_.style.height =
rginda30f20f62012-04-05 16:36:19 -0700855 this.scrollPort_.characterSize.height * rowCount + 'px';
rginda35c456b2012-02-09 17:29:05 -0800856 this.realizeSize_(this.screenSize.width, rowCount);
857 this.scheduleSyncCursorPosition_();
858};
859
860/**
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400861 * Deal with terminal size changes.
862 *
863 */
864hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) {
865 if (columnCount != this.screenSize.width)
866 this.realizeWidth_(columnCount);
867
868 if (rowCount != this.screenSize.height)
869 this.realizeHeight_(rowCount);
870
871 // Send new terminal size to plugin.
Robert Gindae81427f2013-05-24 10:34:46 -0700872 this.io.onTerminalResize_(columnCount, rowCount);
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400873};
874
875/**
rgindac9bc5502012-01-18 11:48:44 -0800876 * Deal with terminal width changes.
877 *
878 * This function does what needs to be done when the terminal width changes
879 * out from under us. It happens here rather than in onResize_() because this
880 * code may need to run synchronously to handle programmatic changes of
881 * terminal width.
882 *
883 * Relying on the browser to send us an async resize event means we may not be
884 * in the correct state yet when the next escape sequence hits.
885 */
886hterm.Terminal.prototype.realizeWidth_ = function(columnCount) {
Robert Ginda4e83f3a2012-09-04 15:25:25 -0700887 if (columnCount <= 0)
888 throw new Error('Attempt to realize bad width: ' + columnCount);
889
rgindac9bc5502012-01-18 11:48:44 -0800890 var deltaColumns = columnCount - this.screen_.getWidth();
891
rginda87b86462011-12-14 13:48:03 -0800892 this.screenSize.width = columnCount;
893 this.screen_.setColumnCount(columnCount);
rgindac9bc5502012-01-18 11:48:44 -0800894
895 if (deltaColumns > 0) {
David Benjamin66e954d2012-05-05 21:08:12 -0400896 if (this.defaultTabStops)
897 this.setDefaultTabStops(this.screenSize.width - deltaColumns);
rgindac9bc5502012-01-18 11:48:44 -0800898 } else {
899 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
David Benjamin66e954d2012-05-05 21:08:12 -0400900 if (this.tabStops_[i] < columnCount)
rgindac9bc5502012-01-18 11:48:44 -0800901 break;
902
903 this.tabStops_.pop();
904 }
905 }
906
907 this.screen_.setColumnCount(this.screenSize.width);
908};
909
910/**
911 * Deal with terminal height changes.
912 *
913 * This function does what needs to be done when the terminal height changes
914 * out from under us. It happens here rather than in onResize_() because this
915 * code may need to run synchronously to handle programmatic changes of
916 * terminal height.
917 *
918 * Relying on the browser to send us an async resize event means we may not be
919 * in the correct state yet when the next escape sequence hits.
920 */
921hterm.Terminal.prototype.realizeHeight_ = function(rowCount) {
Robert Ginda4e83f3a2012-09-04 15:25:25 -0700922 if (rowCount <= 0)
923 throw new Error('Attempt to realize bad height: ' + rowCount);
924
rgindac9bc5502012-01-18 11:48:44 -0800925 var deltaRows = rowCount - this.screen_.getHeight();
926
927 this.screenSize.height = rowCount;
928
929 var cursor = this.saveCursor();
930
931 if (deltaRows < 0) {
932 // Screen got smaller.
933 deltaRows *= -1;
934 while (deltaRows) {
935 var lastRow = this.getRowCount() - 1;
936 if (lastRow - this.scrollbackRows_.length == cursor.row)
937 break;
938
939 if (this.getRowText(lastRow))
940 break;
941
942 this.screen_.popRow();
943 deltaRows--;
944 }
945
946 var ary = this.screen_.shiftRows(deltaRows);
947 this.scrollbackRows_.push.apply(this.scrollbackRows_, ary);
948
949 // We just removed rows from the top of the screen, we need to update
950 // the cursor to match.
rginda35c456b2012-02-09 17:29:05 -0800951 cursor.row = Math.max(cursor.row - deltaRows, 0);
rgindac9bc5502012-01-18 11:48:44 -0800952 } else if (deltaRows > 0) {
953 // Screen got larger.
954
955 if (deltaRows <= this.scrollbackRows_.length) {
956 var scrollbackCount = Math.min(deltaRows, this.scrollbackRows_.length);
957 var rows = this.scrollbackRows_.splice(
958 this.scrollbackRows_.length - scrollbackCount, scrollbackCount);
959 this.screen_.unshiftRows(rows);
960 deltaRows -= scrollbackCount;
961 cursor.row += scrollbackCount;
962 }
963
964 if (deltaRows)
965 this.appendRows_(deltaRows);
966 }
967
rginda35c456b2012-02-09 17:29:05 -0800968 this.setVTScrollRegion(null, null);
rgindac9bc5502012-01-18 11:48:44 -0800969 this.restoreCursor(cursor);
rginda87b86462011-12-14 13:48:03 -0800970};
971
972/**
973 * Scroll the terminal to the top of the scrollback buffer.
974 */
975hterm.Terminal.prototype.scrollHome = function() {
976 this.scrollPort_.scrollRowToTop(0);
977};
978
979/**
980 * Scroll the terminal to the end.
981 */
982hterm.Terminal.prototype.scrollEnd = function() {
983 this.scrollPort_.scrollRowToBottom(this.getRowCount());
984};
985
986/**
987 * Scroll the terminal one page up (minus one line) relative to the current
988 * position.
989 */
990hterm.Terminal.prototype.scrollPageUp = function() {
991 var i = this.scrollPort_.getTopRowIndex();
992 this.scrollPort_.scrollRowToTop(i - this.screenSize.height + 1);
993};
994
995/**
996 * Scroll the terminal one page down (minus one line) relative to the current
997 * position.
998 */
999hterm.Terminal.prototype.scrollPageDown = function() {
1000 var i = this.scrollPort_.getTopRowIndex();
1001 this.scrollPort_.scrollRowToTop(i + this.screenSize.height - 1);
rginda8ba33642011-12-14 12:31:31 -08001002};
1003
rgindac9bc5502012-01-18 11:48:44 -08001004/**
Robert Ginda40932892012-12-10 17:26:40 -08001005 * Clear primary screen, secondary screen, and the scrollback buffer.
1006 */
1007hterm.Terminal.prototype.wipeContents = function() {
1008 this.scrollbackRows_.length = 0;
1009 this.scrollPort_.resetCache();
1010
1011 [this.primaryScreen_, this.alternateScreen_].forEach(function(screen) {
1012 var bottom = screen.getHeight();
1013 if (bottom > 0) {
1014 this.renumberRows_(0, bottom);
1015 this.clearHome(screen);
1016 }
1017 }.bind(this));
1018
1019 this.syncCursorPosition_();
Andrew de los Reyes68e07802013-04-04 15:38:55 -07001020 this.scrollPort_.invalidate();
Robert Ginda40932892012-12-10 17:26:40 -08001021};
1022
1023/**
rgindac9bc5502012-01-18 11:48:44 -08001024 * Full terminal reset.
1025 */
rginda87b86462011-12-14 13:48:03 -08001026hterm.Terminal.prototype.reset = function() {
rgindac9bc5502012-01-18 11:48:44 -08001027 this.clearAllTabStops();
1028 this.setDefaultTabStops();
rginda9ea433c2012-03-16 11:57:00 -07001029
1030 this.clearHome(this.primaryScreen_);
1031 this.primaryScreen_.textAttributes.reset();
1032
1033 this.clearHome(this.alternateScreen_);
1034 this.alternateScreen_.textAttributes.reset();
1035
rgindab8bc8932012-04-27 12:45:03 -07001036 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
1037
Robert Ginda92e18102013-03-14 13:56:37 -07001038 this.vt.reset();
1039
rgindac9bc5502012-01-18 11:48:44 -08001040 this.softReset();
rginda87b86462011-12-14 13:48:03 -08001041};
1042
rgindac9bc5502012-01-18 11:48:44 -08001043/**
1044 * Soft terminal reset.
rgindab8bc8932012-04-27 12:45:03 -07001045 *
1046 * Perform a soft reset to the default values listed in
1047 * http://www.vt100.net/docs/vt510-rm/DECSTR#T5-9
rgindac9bc5502012-01-18 11:48:44 -08001048 */
rginda0f5c0292012-01-13 11:00:13 -08001049hterm.Terminal.prototype.softReset = function() {
rgindab8bc8932012-04-27 12:45:03 -07001050 // Reset terminal options to their default values.
rgindac9bc5502012-01-18 11:48:44 -08001051 this.options_ = new hterm.Options();
rgindaf522ce02012-04-17 17:49:17 -07001052
Brad Townb62dfdc2015-03-16 19:07:15 -07001053 // We show the cursor on soft reset but do not alter the blink state.
1054 this.options_.cursorBlink = !!this.timeouts_.cursorBlink;
1055
rgindab8bc8932012-04-27 12:45:03 -07001056 // Xterm also resets the color palette on soft reset, even though it doesn't
1057 // seem to be documented anywhere.
rgindaf522ce02012-04-17 17:49:17 -07001058 this.primaryScreen_.textAttributes.resetColorPalette();
1059 this.alternateScreen_.textAttributes.resetColorPalette();
1060
rgindab8bc8932012-04-27 12:45:03 -07001061 // The xterm man page explicitly says this will happen on soft reset.
1062 this.setVTScrollRegion(null, null);
1063
1064 // Xterm also shows the cursor on soft reset, but does not alter the blink
1065 // state.
rgindaa19afe22012-01-25 15:40:22 -08001066 this.setCursorVisible(true);
rginda0f5c0292012-01-13 11:00:13 -08001067};
1068
rgindac9bc5502012-01-18 11:48:44 -08001069/**
1070 * Move the cursor forward to the next tab stop, or to the last column
1071 * if no more tab stops are set.
1072 */
1073hterm.Terminal.prototype.forwardTabStop = function() {
1074 var column = this.screen_.cursorPosition.column;
1075
1076 for (var i = 0; i < this.tabStops_.length; i++) {
1077 if (this.tabStops_[i] > column) {
1078 this.setCursorColumn(this.tabStops_[i]);
1079 return;
1080 }
1081 }
1082
David Benjamin66e954d2012-05-05 21:08:12 -04001083 // xterm does not clear the overflow flag on HT or CHT.
1084 var overflow = this.screen_.cursorPosition.overflow;
rgindac9bc5502012-01-18 11:48:44 -08001085 this.setCursorColumn(this.screenSize.width - 1);
David Benjamin66e954d2012-05-05 21:08:12 -04001086 this.screen_.cursorPosition.overflow = overflow;
rginda0f5c0292012-01-13 11:00:13 -08001087};
1088
rgindac9bc5502012-01-18 11:48:44 -08001089/**
1090 * Move the cursor backward to the previous tab stop, or to the first column
1091 * if no previous tab stops are set.
1092 */
1093hterm.Terminal.prototype.backwardTabStop = function() {
1094 var column = this.screen_.cursorPosition.column;
1095
1096 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
1097 if (this.tabStops_[i] < column) {
1098 this.setCursorColumn(this.tabStops_[i]);
1099 return;
1100 }
1101 }
1102
1103 this.setCursorColumn(1);
rginda0f5c0292012-01-13 11:00:13 -08001104};
1105
rgindac9bc5502012-01-18 11:48:44 -08001106/**
1107 * Set a tab stop at the given column.
1108 *
1109 * @param {int} column Zero based column.
1110 */
1111hterm.Terminal.prototype.setTabStop = function(column) {
1112 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
1113 if (this.tabStops_[i] == column)
1114 return;
1115
1116 if (this.tabStops_[i] < column) {
1117 this.tabStops_.splice(i + 1, 0, column);
1118 return;
1119 }
1120 }
1121
1122 this.tabStops_.splice(0, 0, column);
rginda87b86462011-12-14 13:48:03 -08001123};
1124
rgindac9bc5502012-01-18 11:48:44 -08001125/**
1126 * Clear the tab stop at the current cursor position.
1127 *
1128 * No effect if there is no tab stop at the current cursor position.
1129 */
1130hterm.Terminal.prototype.clearTabStopAtCursor = function() {
1131 var column = this.screen_.cursorPosition.column;
1132
1133 var i = this.tabStops_.indexOf(column);
1134 if (i == -1)
1135 return;
1136
1137 this.tabStops_.splice(i, 1);
1138};
1139
1140/**
1141 * Clear all tab stops.
1142 */
1143hterm.Terminal.prototype.clearAllTabStops = function() {
1144 this.tabStops_.length = 0;
David Benjamin66e954d2012-05-05 21:08:12 -04001145 this.defaultTabStops = false;
rgindac9bc5502012-01-18 11:48:44 -08001146};
1147
1148/**
1149 * Set up the default tab stops, starting from a given column.
1150 *
1151 * This sets a tabstop every (column % this.tabWidth) column, starting
David Benjamin66e954d2012-05-05 21:08:12 -04001152 * from the specified column, or 0 if no column is provided. It also flags
1153 * future resizes to set them up.
rgindac9bc5502012-01-18 11:48:44 -08001154 *
1155 * This does not clear the existing tab stops first, use clearAllTabStops
1156 * for that.
1157 *
1158 * @param {int} opt_start Optional starting zero based starting column, useful
1159 * for filling out missing tab stops when the terminal is resized.
1160 */
1161hterm.Terminal.prototype.setDefaultTabStops = function(opt_start) {
1162 var start = opt_start || 0;
1163 var w = this.tabWidth;
David Benjamin66e954d2012-05-05 21:08:12 -04001164 // Round start up to a default tab stop.
1165 start = start - 1 - ((start - 1) % w) + w;
1166 for (var i = start; i < this.screenSize.width; i += w) {
1167 this.setTabStop(i);
rgindac9bc5502012-01-18 11:48:44 -08001168 }
David Benjamin66e954d2012-05-05 21:08:12 -04001169
1170 this.defaultTabStops = true;
rginda87b86462011-12-14 13:48:03 -08001171};
1172
rginda6d397402012-01-17 10:58:29 -08001173/**
rginda8ba33642011-12-14 12:31:31 -08001174 * Interpret a sequence of characters.
1175 *
1176 * Incomplete escape sequences are buffered until the next call.
1177 *
1178 * @param {string} str Sequence of characters to interpret or pass through.
1179 */
1180hterm.Terminal.prototype.interpret = function(str) {
rginda0f5c0292012-01-13 11:00:13 -08001181 this.vt.interpret(str);
rginda8ba33642011-12-14 12:31:31 -08001182 this.scheduleSyncCursorPosition_();
1183};
1184
1185/**
1186 * Take over the given DIV for use as the terminal display.
1187 *
1188 * @param {HTMLDivElement} div The div to use as the terminal display.
1189 */
1190hterm.Terminal.prototype.decorate = function(div) {
rginda87b86462011-12-14 13:48:03 -08001191 this.div_ = div;
1192
rginda8ba33642011-12-14 12:31:31 -08001193 this.scrollPort_.decorate(div);
rginda30f20f62012-04-05 16:36:19 -07001194 this.scrollPort_.setBackgroundImage(this.prefs_.get('background-image'));
Philip Douglass959b49d2012-05-30 13:29:29 -04001195 this.scrollPort_.setBackgroundSize(this.prefs_.get('background-size'));
1196 this.scrollPort_.setBackgroundPosition(
1197 this.prefs_.get('background-position'));
Robert Gindae76aa9f2014-03-14 12:29:12 -07001198 this.scrollPort_.setUserCss(this.prefs_.get('user-css'));
rginda30f20f62012-04-05 16:36:19 -07001199
rginda0918b652012-04-04 11:26:24 -07001200 this.div_.focus = this.focus.bind(this);
rgindaf7521392012-02-28 17:20:34 -08001201
rginda9f5222b2012-03-05 11:53:28 -08001202 this.setFontSize(this.prefs_.get('font-size'));
1203 this.syncFontFamily();
rgindaa19afe22012-01-25 15:40:22 -08001204
David Reveman8f552492012-03-28 12:18:41 -04001205 this.setScrollbarVisible(this.prefs_.get('scrollbar-visible'));
Rob Spies49039e52014-12-17 13:40:04 -08001206 this.setScrollWheelMoveMultipler(
1207 this.prefs_.get('scroll-wheel-move-multiplier'));
David Reveman8f552492012-03-28 12:18:41 -04001208
rginda8ba33642011-12-14 12:31:31 -08001209 this.document_ = this.scrollPort_.getDocument();
1210
rginda4bba5e12012-06-20 16:15:30 -07001211 this.document_.body.oncontextmenu = function() { return false };
1212
1213 var onMouse = this.onMouse_.bind(this);
Toni Barzic0bfa8922013-11-22 11:18:35 -08001214 var screenNode = this.scrollPort_.getScreenNode();
1215 screenNode.addEventListener('mousedown', onMouse);
1216 screenNode.addEventListener('mouseup', onMouse);
1217 screenNode.addEventListener('mousemove', onMouse);
rginda4bba5e12012-06-20 16:15:30 -07001218 this.scrollPort_.onScrollWheel = onMouse;
1219
Toni Barzic0bfa8922013-11-22 11:18:35 -08001220 screenNode.addEventListener(
rginda8e92a692012-05-20 19:37:20 -07001221 'focus', this.onFocusChange_.bind(this, true));
Rob Spies06533ba2014-04-24 11:20:37 -07001222 // Listen for mousedown events on the screenNode as in FF the focus
1223 // events don't bubble.
1224 screenNode.addEventListener('mousedown', function() {
1225 setTimeout(this.onFocusChange_.bind(this, true));
1226 }.bind(this));
1227
Toni Barzic0bfa8922013-11-22 11:18:35 -08001228 screenNode.addEventListener(
rginda8e92a692012-05-20 19:37:20 -07001229 'blur', this.onFocusChange_.bind(this, false));
1230
1231 var style = this.document_.createElement('style');
1232 style.textContent =
1233 ('.cursor-node[focus="false"] {' +
1234 ' box-sizing: border-box;' +
1235 ' background-color: transparent !important;' +
1236 ' border-width: 2px;' +
1237 ' border-style: solid;' +
Ricky Liang48f05cb2013-12-31 23:35:29 +08001238 '}' +
1239 '.wc-node {' +
1240 ' display: inline-block;' +
1241 ' text-align: center;' +
1242 ' width: ' + this.scrollPort_.characterSize.width * 2 + 'px;' +
rginda8e92a692012-05-20 19:37:20 -07001243 '}');
1244 this.document_.head.appendChild(style);
1245
Ricky Liang48f05cb2013-12-31 23:35:29 +08001246 var styleSheets = this.document_.styleSheets;
1247 var cssRules = styleSheets[styleSheets.length - 1].cssRules;
1248 this.wcCssRule_ = cssRules[cssRules.length - 1];
1249
rginda8ba33642011-12-14 12:31:31 -08001250 this.cursorNode_ = this.document_.createElement('div');
rginda8e92a692012-05-20 19:37:20 -07001251 this.cursorNode_.className = 'cursor-node';
rginda8ba33642011-12-14 12:31:31 -08001252 this.cursorNode_.style.cssText =
1253 ('position: absolute;' +
rginda87b86462011-12-14 13:48:03 -08001254 'top: -99px;' +
1255 'display: block;' +
rginda35c456b2012-02-09 17:29:05 -08001256 'width: ' + this.scrollPort_.characterSize.width + 'px;' +
1257 'height: ' + this.scrollPort_.characterSize.height + 'px;' +
Rob Spies06533ba2014-04-24 11:20:37 -07001258 '-webkit-transition: opacity, background-color 100ms linear;' +
1259 '-moz-transition: opacity, background-color 100ms linear;');
Robert Gindafb1be6a2013-12-11 11:56:22 -08001260
rginda8e92a692012-05-20 19:37:20 -07001261 this.setCursorColor(this.prefs_.get('cursor-color'));
Robert Gindafb1be6a2013-12-11 11:56:22 -08001262 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
1263 this.restyleCursor_();
rgindad5613292012-06-19 15:40:37 -07001264
rginda8ba33642011-12-14 12:31:31 -08001265 this.document_.body.appendChild(this.cursorNode_);
1266
rgindad5613292012-06-19 15:40:37 -07001267 // When 'enableMouseDragScroll' is off we reposition this element directly
1268 // under the mouse cursor after a click. This makes Chrome associate
1269 // subsequent mousemove events with the scroll-blocker. Since the
1270 // scroll-blocker is a peer (not a child) of the scrollport, the mousemove
1271 // events do not cause the scrollport to scroll.
1272 //
1273 // It's a hack, but it's the cleanest way I could find.
1274 this.scrollBlockerNode_ = this.document_.createElement('div');
1275 this.scrollBlockerNode_.style.cssText =
1276 ('position: absolute;' +
1277 'top: -99px;' +
1278 'display: block;' +
1279 'width: 10px;' +
1280 'height: 10px;');
1281 this.document_.body.appendChild(this.scrollBlockerNode_);
1282
1283 var onMouse = this.onMouse_.bind(this);
1284 this.scrollPort_.onScrollWheel = onMouse;
1285 ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick',
1286 ].forEach(function(event) {
1287 this.scrollBlockerNode_.addEventListener(event, onMouse);
1288 this.cursorNode_.addEventListener(event, onMouse);
1289 this.document_.addEventListener(event, onMouse);
1290 }.bind(this));
1291
1292 this.cursorNode_.addEventListener('mousedown', function() {
1293 setTimeout(this.focus.bind(this));
1294 }.bind(this));
1295
rginda8ba33642011-12-14 12:31:31 -08001296 this.setReverseVideo(false);
rginda87b86462011-12-14 13:48:03 -08001297
rginda87b86462011-12-14 13:48:03 -08001298 this.scrollPort_.focus();
rginda6d397402012-01-17 10:58:29 -08001299 this.scrollPort_.scheduleRedraw();
rginda87b86462011-12-14 13:48:03 -08001300};
1301
rginda0918b652012-04-04 11:26:24 -07001302/**
1303 * Return the HTML document that contains the terminal DOM nodes.
1304 */
rginda87b86462011-12-14 13:48:03 -08001305hterm.Terminal.prototype.getDocument = function() {
1306 return this.document_;
rginda8ba33642011-12-14 12:31:31 -08001307};
1308
1309/**
rginda0918b652012-04-04 11:26:24 -07001310 * Focus the terminal.
1311 */
1312hterm.Terminal.prototype.focus = function() {
1313 this.scrollPort_.focus();
1314};
1315
1316/**
rginda8ba33642011-12-14 12:31:31 -08001317 * Return the HTML Element for a given row index.
1318 *
1319 * This is a method from the RowProvider interface. The ScrollPort uses
1320 * it to fetch rows on demand as they are scrolled into view.
1321 *
1322 * TODO(rginda): Consider saving scrollback rows as (HTML source, text content)
1323 * pairs to conserve memory.
1324 *
1325 * @param {integer} index The zero-based row index, measured relative to the
1326 * start of the scrollback buffer. On-screen rows will always have the
1327 * largest indicies.
1328 * @return {HTMLElement} The 'x-row' element containing for the requested row.
1329 */
1330hterm.Terminal.prototype.getRowNode = function(index) {
1331 if (index < this.scrollbackRows_.length)
1332 return this.scrollbackRows_[index];
1333
1334 var screenIndex = index - this.scrollbackRows_.length;
1335 return this.screen_.rowsArray[screenIndex];
1336};
1337
1338/**
1339 * Return the text content for a given range of rows.
1340 *
1341 * This is a method from the RowProvider interface. The ScrollPort uses
1342 * it to fetch text content on demand when the user attempts to copy their
1343 * selection to the clipboard.
1344 *
1345 * @param {integer} start The zero-based row index to start from, measured
1346 * relative to the start of the scrollback buffer. On-screen rows will
1347 * always have the largest indicies.
1348 * @param {integer} end The zero-based row index to end on, measured
1349 * relative to the start of the scrollback buffer.
1350 * @return {string} A single string containing the text value of the range of
1351 * rows. Lines will be newline delimited, with no trailing newline.
1352 */
1353hterm.Terminal.prototype.getRowsText = function(start, end) {
1354 var ary = [];
1355 for (var i = start; i < end; i++) {
1356 var node = this.getRowNode(i);
1357 ary.push(node.textContent);
rgindaa09e7332012-08-17 12:49:51 -07001358 if (i < end - 1 && !node.getAttribute('line-overflow'))
1359 ary.push('\n');
rginda8ba33642011-12-14 12:31:31 -08001360 }
1361
rgindaa09e7332012-08-17 12:49:51 -07001362 return ary.join('');
rginda8ba33642011-12-14 12:31:31 -08001363};
1364
1365/**
1366 * Return the text content for a given row.
1367 *
1368 * This is a method from the RowProvider interface. The ScrollPort uses
1369 * it to fetch text content on demand when the user attempts to copy their
1370 * selection to the clipboard.
1371 *
1372 * @param {integer} index The zero-based row index to return, measured
1373 * relative to the start of the scrollback buffer. On-screen rows will
1374 * always have the largest indicies.
1375 * @return {string} A string containing the text value of the selected row.
1376 */
1377hterm.Terminal.prototype.getRowText = function(index) {
1378 var node = this.getRowNode(index);
rginda87b86462011-12-14 13:48:03 -08001379 return node.textContent;
rginda8ba33642011-12-14 12:31:31 -08001380};
1381
1382/**
1383 * Return the total number of rows in the addressable screen and in the
1384 * scrollback buffer of this terminal.
1385 *
1386 * This is a method from the RowProvider interface. The ScrollPort uses
1387 * it to compute the size of the scrollbar.
1388 *
1389 * @return {integer} The number of rows in this terminal.
1390 */
1391hterm.Terminal.prototype.getRowCount = function() {
1392 return this.scrollbackRows_.length + this.screen_.rowsArray.length;
1393};
1394
1395/**
1396 * Create DOM nodes for new rows and append them to the end of the terminal.
1397 *
1398 * This is the only correct way to add a new DOM node for a row. Notice that
1399 * the new row is appended to the bottom of the list of rows, and does not
1400 * require renumbering (of the rowIndex property) of previous rows.
1401 *
1402 * If you think you want a new blank row somewhere in the middle of the
1403 * terminal, look into moveRows_().
1404 *
1405 * This method does not pay attention to vtScrollTop/Bottom, since you should
1406 * be using moveRows() in cases where they would matter.
1407 *
1408 * The cursor will be positioned at column 0 of the first inserted line.
1409 */
1410hterm.Terminal.prototype.appendRows_ = function(count) {
1411 var cursorRow = this.screen_.rowsArray.length;
1412 var offset = this.scrollbackRows_.length + cursorRow;
1413 for (var i = 0; i < count; i++) {
1414 var row = this.document_.createElement('x-row');
1415 row.appendChild(this.document_.createTextNode(''));
1416 row.rowIndex = offset + i;
1417 this.screen_.pushRow(row);
1418 }
1419
1420 var extraRows = this.screen_.rowsArray.length - this.screenSize.height;
1421 if (extraRows > 0) {
1422 var ary = this.screen_.shiftRows(extraRows);
1423 Array.prototype.push.apply(this.scrollbackRows_, ary);
Robert Ginda36c5aa62012-10-15 11:17:47 -07001424 if (this.scrollPort_.isScrolledEnd)
1425 this.scheduleScrollDown_();
rginda8ba33642011-12-14 12:31:31 -08001426 }
1427
1428 if (cursorRow >= this.screen_.rowsArray.length)
1429 cursorRow = this.screen_.rowsArray.length - 1;
1430
rginda87b86462011-12-14 13:48:03 -08001431 this.setAbsoluteCursorPosition(cursorRow, 0);
rginda8ba33642011-12-14 12:31:31 -08001432};
1433
1434/**
1435 * Relocate rows from one part of the addressable screen to another.
1436 *
1437 * This is used to recycle rows during VT scrolls (those which are driven
1438 * by VT commands, rather than by the user manipulating the scrollbar.)
1439 *
1440 * In this case, the blank lines scrolled into the scroll region are made of
1441 * the nodes we scrolled off. These have their rowIndex properties carefully
1442 * renumbered so as not to confuse the ScrollPort.
rginda8ba33642011-12-14 12:31:31 -08001443 */
1444hterm.Terminal.prototype.moveRows_ = function(fromIndex, count, toIndex) {
1445 var ary = this.screen_.removeRows(fromIndex, count);
1446 this.screen_.insertRows(toIndex, ary);
1447
1448 var start, end;
1449 if (fromIndex < toIndex) {
1450 start = fromIndex;
rginda87b86462011-12-14 13:48:03 -08001451 end = toIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001452 } else {
1453 start = toIndex;
rginda87b86462011-12-14 13:48:03 -08001454 end = fromIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001455 }
1456
1457 this.renumberRows_(start, end);
rginda2312fff2012-01-05 16:20:52 -08001458 this.scrollPort_.scheduleInvalidate();
rginda8ba33642011-12-14 12:31:31 -08001459};
1460
1461/**
1462 * Renumber the rowIndex property of the given range of rows.
1463 *
1464 * The start and end indicies are relative to the screen, not the scrollback.
1465 * Rows in the scrollback buffer cannot be renumbered. Since they are not
rginda2312fff2012-01-05 16:20:52 -08001466 * addressable (you can't delete them, scroll them, etc), you should have
rginda8ba33642011-12-14 12:31:31 -08001467 * no need to renumber scrollback rows.
1468 */
Robert Ginda40932892012-12-10 17:26:40 -08001469hterm.Terminal.prototype.renumberRows_ = function(start, end, opt_screen) {
1470 var screen = opt_screen || this.screen_;
1471
rginda8ba33642011-12-14 12:31:31 -08001472 var offset = this.scrollbackRows_.length;
1473 for (var i = start; i < end; i++) {
Robert Ginda40932892012-12-10 17:26:40 -08001474 screen.rowsArray[i].rowIndex = offset + i;
rginda8ba33642011-12-14 12:31:31 -08001475 }
1476};
1477
1478/**
1479 * Print a string to the terminal.
1480 *
1481 * This respects the current insert and wraparound modes. It will add new lines
1482 * to the end of the terminal, scrolling off the top into the scrollback buffer
1483 * if necessary.
1484 *
1485 * The string is *not* parsed for escape codes. Use the interpret() method if
1486 * that's what you're after.
1487 *
1488 * @param{string} str The string to print.
1489 */
1490hterm.Terminal.prototype.print = function(str) {
rgindaa9abdd82012-08-06 18:05:09 -07001491 var startOffset = 0;
rginda2312fff2012-01-05 16:20:52 -08001492
Ricky Liang48f05cb2013-12-31 23:35:29 +08001493 var strWidth = lib.wc.strWidth(str);
1494
1495 while (startOffset < strWidth) {
rgindaa09e7332012-08-17 12:49:51 -07001496 if (this.options_.wraparound && this.screen_.cursorPosition.overflow) {
1497 this.screen_.commitLineOverflow();
rginda35c456b2012-02-09 17:29:05 -08001498 this.newLine();
rgindaa09e7332012-08-17 12:49:51 -07001499 }
rgindaa19afe22012-01-25 15:40:22 -08001500
Ricky Liang48f05cb2013-12-31 23:35:29 +08001501 var count = strWidth - startOffset;
rgindaa9abdd82012-08-06 18:05:09 -07001502 var didOverflow = false;
1503 var substr;
rgindaa19afe22012-01-25 15:40:22 -08001504
rgindaa9abdd82012-08-06 18:05:09 -07001505 if (this.screen_.cursorPosition.column + count >= this.screenSize.width) {
1506 didOverflow = true;
1507 count = this.screenSize.width - this.screen_.cursorPosition.column;
1508 }
rgindaa19afe22012-01-25 15:40:22 -08001509
rgindaa9abdd82012-08-06 18:05:09 -07001510 if (didOverflow && !this.options_.wraparound) {
1511 // If the string overflowed the line but wraparound is off, then the
1512 // last printed character should be the last of the string.
1513 // TODO: This will add to our problems with multibyte UTF-16 characters.
Ricky Liang48f05cb2013-12-31 23:35:29 +08001514 substr = lib.wc.substr(str, startOffset, count - 1) +
1515 lib.wc.substr(str, strWidth - 1);
1516 count = strWidth;
rgindaa9abdd82012-08-06 18:05:09 -07001517 } else {
Ricky Liang48f05cb2013-12-31 23:35:29 +08001518 substr = lib.wc.substr(str, startOffset, count);
rgindaa9abdd82012-08-06 18:05:09 -07001519 }
rgindaa19afe22012-01-25 15:40:22 -08001520
Ricky Liang48f05cb2013-12-31 23:35:29 +08001521 var tokens = hterm.TextAttributes.splitWidecharString(substr);
1522 for (var i = 0; i < tokens.length; i++) {
1523 if (tokens[i].wcNode)
1524 this.screen_.textAttributes.wcNode = true;
1525
1526 if (this.options_.insertMode) {
1527 this.screen_.insertString(tokens[i].str);
1528 } else {
1529 this.screen_.overwriteString(tokens[i].str);
1530 }
1531 this.screen_.textAttributes.wcNode = false;
rgindaa9abdd82012-08-06 18:05:09 -07001532 }
1533
1534 this.screen_.maybeClipCurrentRow();
1535 startOffset += count;
rgindaa19afe22012-01-25 15:40:22 -08001536 }
rginda8ba33642011-12-14 12:31:31 -08001537
1538 this.scheduleSyncCursorPosition_();
rginda0f5c0292012-01-13 11:00:13 -08001539
rginda9f5222b2012-03-05 11:53:28 -08001540 if (this.scrollOnOutput_)
rginda0f5c0292012-01-13 11:00:13 -08001541 this.scrollPort_.scrollRowToBottom(this.getRowCount());
rginda8ba33642011-12-14 12:31:31 -08001542};
1543
1544/**
rginda87b86462011-12-14 13:48:03 -08001545 * Set the VT scroll region.
1546 *
rginda87b86462011-12-14 13:48:03 -08001547 * This also resets the cursor position to the absolute (0, 0) position, since
1548 * that's what xterm appears to do.
1549 *
Robert Ginda5b9fbe62013-10-30 14:05:53 -07001550 * Setting the scroll region to the full height of the terminal will clear
1551 * the scroll region. This is *NOT* what most terminals do. We're explicitly
1552 * going "off-spec" here because it makes `screen` and `tmux` overflow into the
1553 * local scrollback buffer, which means the scrollbars and shift-pgup/pgdn
1554 * continue to work as most users would expect.
1555 *
rginda87b86462011-12-14 13:48:03 -08001556 * @param {integer} scrollTop The zero-based top of the scroll region.
1557 * @param {integer} scrollBottom The zero-based bottom of the scroll region,
1558 * inclusive.
1559 */
1560hterm.Terminal.prototype.setVTScrollRegion = function(scrollTop, scrollBottom) {
Robert Ginda5b9fbe62013-10-30 14:05:53 -07001561 if (scrollTop == 0 && scrollBottom == this.screenSize.height - 1) {
Robert Ginda43684e22013-11-25 14:18:52 -08001562 this.vtScrollTop_ = null;
1563 this.vtScrollBottom_ = null;
Robert Ginda5b9fbe62013-10-30 14:05:53 -07001564 } else {
1565 this.vtScrollTop_ = scrollTop;
1566 this.vtScrollBottom_ = scrollBottom;
1567 }
rginda87b86462011-12-14 13:48:03 -08001568};
1569
1570/**
rginda8ba33642011-12-14 12:31:31 -08001571 * Return the top row index according to the VT.
1572 *
1573 * This will return 0 unless the terminal has been told to restrict scrolling
1574 * to some lower row. It is used for some VT cursor positioning and scrolling
1575 * commands.
1576 *
1577 * @return {integer} The topmost row in the terminal's scroll region.
1578 */
1579hterm.Terminal.prototype.getVTScrollTop = function() {
1580 if (this.vtScrollTop_ != null)
1581 return this.vtScrollTop_;
1582
1583 return 0;
rginda87b86462011-12-14 13:48:03 -08001584};
rginda8ba33642011-12-14 12:31:31 -08001585
1586/**
1587 * Return the bottom row index according to the VT.
1588 *
1589 * This will return the height of the terminal unless the it has been told to
1590 * restrict scrolling to some higher row. It is used for some VT cursor
1591 * positioning and scrolling commands.
1592 *
1593 * @return {integer} The bottommost row in the terminal's scroll region.
1594 */
1595hterm.Terminal.prototype.getVTScrollBottom = function() {
1596 if (this.vtScrollBottom_ != null)
1597 return this.vtScrollBottom_;
1598
rginda87b86462011-12-14 13:48:03 -08001599 return this.screenSize.height - 1;
rginda8ba33642011-12-14 12:31:31 -08001600}
1601
1602/**
1603 * Process a '\n' character.
1604 *
1605 * If the cursor is on the final row of the terminal this will append a new
1606 * blank row to the screen and scroll the topmost row into the scrollback
1607 * buffer.
1608 *
1609 * Otherwise, this moves the cursor to column zero of the next row.
1610 */
1611hterm.Terminal.prototype.newLine = function() {
Robert Ginda9937abc2013-07-25 16:09:23 -07001612 var cursorAtEndOfScreen = (this.screen_.cursorPosition.row ==
1613 this.screen_.rowsArray.length - 1);
1614
1615 if (this.vtScrollBottom_ != null) {
1616 // A VT Scroll region is active, we never append new rows.
1617 if (this.screen_.cursorPosition.row == this.vtScrollBottom_) {
1618 // We're at the end of the VT Scroll Region, perform a VT scroll.
1619 this.vtScrollUp(1);
1620 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
1621 } else if (cursorAtEndOfScreen) {
1622 // We're at the end of the screen, the only thing to do is put the
1623 // cursor to column 0.
1624 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
1625 } else {
1626 // Anywhere else, advance the cursor row, and reset the column.
1627 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
1628 }
1629 } else if (cursorAtEndOfScreen) {
Robert Ginda1b06b372013-07-19 15:22:51 -07001630 // We're at the end of the screen. Append a new row to the terminal,
1631 // shifting the top row into the scrollback.
1632 this.appendRows_(1);
rginda8ba33642011-12-14 12:31:31 -08001633 } else {
rginda87b86462011-12-14 13:48:03 -08001634 // Anywhere else in the screen just moves the cursor.
1635 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
rginda8ba33642011-12-14 12:31:31 -08001636 }
1637};
1638
1639/**
1640 * Like newLine(), except maintain the cursor column.
1641 */
1642hterm.Terminal.prototype.lineFeed = function() {
1643 var column = this.screen_.cursorPosition.column;
1644 this.newLine();
1645 this.setCursorColumn(column);
1646};
1647
1648/**
rginda87b86462011-12-14 13:48:03 -08001649 * If autoCarriageReturn is set then newLine(), else lineFeed().
1650 */
1651hterm.Terminal.prototype.formFeed = function() {
1652 if (this.options_.autoCarriageReturn) {
1653 this.newLine();
1654 } else {
1655 this.lineFeed();
1656 }
1657};
1658
1659/**
1660 * Move the cursor up one row, possibly inserting a blank line.
1661 *
1662 * The cursor column is not changed.
1663 */
1664hterm.Terminal.prototype.reverseLineFeed = function() {
1665 var scrollTop = this.getVTScrollTop();
1666 var currentRow = this.screen_.cursorPosition.row;
1667
1668 if (currentRow == scrollTop) {
1669 this.insertLines(1);
1670 } else {
1671 this.setAbsoluteCursorRow(currentRow - 1);
1672 }
1673};
1674
1675/**
rginda8ba33642011-12-14 12:31:31 -08001676 * Replace all characters to the left of the current cursor with the space
1677 * character.
1678 *
1679 * TODO(rginda): This should probably *remove* the characters (not just replace
1680 * with a space) if there are no characters at or beyond the current cursor
Robert Gindaf2547f12012-10-25 20:36:21 -07001681 * position.
rginda8ba33642011-12-14 12:31:31 -08001682 */
1683hterm.Terminal.prototype.eraseToLeft = function() {
rginda87b86462011-12-14 13:48:03 -08001684 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001685 this.setCursorColumn(0);
rgindacbbd7482012-06-13 15:06:16 -07001686 this.screen_.overwriteString(lib.f.getWhitespace(cursor.column + 1));
rginda87b86462011-12-14 13:48:03 -08001687 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001688};
1689
1690/**
David Benjamin684a9b72012-05-01 17:19:58 -04001691 * Erase a given number of characters to the right of the cursor.
rginda8ba33642011-12-14 12:31:31 -08001692 *
1693 * The cursor position is unchanged.
1694 *
Robert Gindaf2547f12012-10-25 20:36:21 -07001695 * If the current background color is not the default background color this
1696 * will insert spaces rather than delete. This is unfortunate because the
1697 * trailing space will affect text selection, but it's difficult to come up
1698 * with a way to style empty space that wouldn't trip up the hterm.Screen
1699 * code.
Robert Gindacd5637d2013-10-30 14:59:10 -07001700 *
1701 * eraseToRight is ignored in the presence of a cursor overflow. This deviates
1702 * from xterm, but agrees with gnome-terminal and konsole, xfce4-terminal. See
1703 * crbug.com/232390 for details.
rginda8ba33642011-12-14 12:31:31 -08001704 */
1705hterm.Terminal.prototype.eraseToRight = function(opt_count) {
Robert Gindacd5637d2013-10-30 14:59:10 -07001706 if (this.screen_.cursorPosition.overflow)
1707 return;
1708
Robert Ginda7fd57082012-09-25 14:41:47 -07001709 var maxCount = this.screenSize.width - this.screen_.cursorPosition.column;
1710 var count = opt_count ? Math.min(opt_count, maxCount) : maxCount;
Robert Gindaf2547f12012-10-25 20:36:21 -07001711
1712 if (this.screen_.textAttributes.background ===
1713 this.screen_.textAttributes.DEFAULT_COLOR) {
1714 var cursorRow = this.screen_.rowsArray[this.screen_.cursorPosition.row];
Ricky Liang48f05cb2013-12-31 23:35:29 +08001715 if (hterm.TextAttributes.nodeWidth(cursorRow) <=
Robert Gindaf2547f12012-10-25 20:36:21 -07001716 this.screen_.cursorPosition.column + count) {
1717 this.screen_.deleteChars(count);
1718 this.clearCursorOverflow();
1719 return;
1720 }
1721 }
1722
rginda87b86462011-12-14 13:48:03 -08001723 var cursor = this.saveCursor();
Robert Ginda7fd57082012-09-25 14:41:47 -07001724 this.screen_.overwriteString(lib.f.getWhitespace(count));
rginda87b86462011-12-14 13:48:03 -08001725 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001726 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001727};
1728
1729/**
1730 * Erase the current line.
1731 *
1732 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001733 */
1734hterm.Terminal.prototype.eraseLine = function() {
rginda87b86462011-12-14 13:48:03 -08001735 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001736 this.screen_.clearCursorRow();
rginda87b86462011-12-14 13:48:03 -08001737 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001738 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001739};
1740
1741/**
David Benjamina08d78f2012-05-05 00:28:49 -04001742 * Erase all characters from the start of the screen to the current cursor
1743 * position, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001744 *
1745 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001746 */
1747hterm.Terminal.prototype.eraseAbove = function() {
rginda87b86462011-12-14 13:48:03 -08001748 var cursor = this.saveCursor();
1749
1750 this.eraseToLeft();
rginda8ba33642011-12-14 12:31:31 -08001751
David Benjamina08d78f2012-05-05 00:28:49 -04001752 for (var i = 0; i < cursor.row; i++) {
rginda87b86462011-12-14 13:48:03 -08001753 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001754 this.screen_.clearCursorRow();
1755 }
1756
rginda87b86462011-12-14 13:48:03 -08001757 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001758 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001759};
1760
1761/**
1762 * Erase all characters from the current cursor position to the end of the
David Benjamina08d78f2012-05-05 00:28:49 -04001763 * screen, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001764 *
1765 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001766 */
1767hterm.Terminal.prototype.eraseBelow = function() {
rginda87b86462011-12-14 13:48:03 -08001768 var cursor = this.saveCursor();
1769
1770 this.eraseToRight();
rginda8ba33642011-12-14 12:31:31 -08001771
David Benjamina08d78f2012-05-05 00:28:49 -04001772 var bottom = this.screenSize.height - 1;
rginda87b86462011-12-14 13:48:03 -08001773 for (var i = cursor.row + 1; i <= bottom; i++) {
1774 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001775 this.screen_.clearCursorRow();
1776 }
1777
rginda87b86462011-12-14 13:48:03 -08001778 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001779 this.clearCursorOverflow();
rginda87b86462011-12-14 13:48:03 -08001780};
1781
1782/**
1783 * Fill the terminal with a given character.
1784 *
1785 * This methods does not respect the VT scroll region.
1786 *
1787 * @param {string} ch The character to use for the fill.
1788 */
1789hterm.Terminal.prototype.fill = function(ch) {
1790 var cursor = this.saveCursor();
1791
1792 this.setAbsoluteCursorPosition(0, 0);
1793 for (var row = 0; row < this.screenSize.height; row++) {
1794 for (var col = 0; col < this.screenSize.width; col++) {
1795 this.setAbsoluteCursorPosition(row, col);
1796 this.screen_.overwriteString(ch);
1797 }
1798 }
1799
1800 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001801};
1802
1803/**
rginda9ea433c2012-03-16 11:57:00 -07001804 * Erase the entire display and leave the cursor at (0, 0).
rginda8ba33642011-12-14 12:31:31 -08001805 *
rginda9ea433c2012-03-16 11:57:00 -07001806 * This does not respect the scroll region.
1807 *
1808 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1809 * to the current screen.
rginda8ba33642011-12-14 12:31:31 -08001810 */
rginda9ea433c2012-03-16 11:57:00 -07001811hterm.Terminal.prototype.clearHome = function(opt_screen) {
1812 var screen = opt_screen || this.screen_;
1813 var bottom = screen.getHeight();
rginda8ba33642011-12-14 12:31:31 -08001814
rginda11057d52012-04-25 12:29:56 -07001815 if (bottom == 0) {
1816 // Empty screen, nothing to do.
1817 return;
1818 }
1819
rgindae4d29232012-01-19 10:47:13 -08001820 for (var i = 0; i < bottom; i++) {
rginda9ea433c2012-03-16 11:57:00 -07001821 screen.setCursorPosition(i, 0);
1822 screen.clearCursorRow();
rginda8ba33642011-12-14 12:31:31 -08001823 }
1824
rginda9ea433c2012-03-16 11:57:00 -07001825 screen.setCursorPosition(0, 0);
1826};
1827
1828/**
1829 * Erase the entire display without changing the cursor position.
1830 *
1831 * The cursor position is unchanged. This does not respect the scroll
1832 * region.
1833 *
1834 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1835 * to the current screen.
rginda9ea433c2012-03-16 11:57:00 -07001836 */
1837hterm.Terminal.prototype.clear = function(opt_screen) {
1838 var screen = opt_screen || this.screen_;
1839 var cursor = screen.cursorPosition.clone();
1840 this.clearHome(screen);
1841 screen.setCursorPosition(cursor.row, cursor.column);
rginda8ba33642011-12-14 12:31:31 -08001842};
1843
1844/**
1845 * VT command to insert lines at the current cursor row.
1846 *
1847 * This respects the current scroll region. Rows pushed off the bottom are
1848 * lost (they won't show up in the scrollback buffer).
1849 *
rginda8ba33642011-12-14 12:31:31 -08001850 * @param {integer} count The number of lines to insert.
1851 */
1852hterm.Terminal.prototype.insertLines = function(count) {
Robert Ginda579186b2012-09-26 11:40:04 -07001853 var cursorRow = this.screen_.cursorPosition.row;
rginda8ba33642011-12-14 12:31:31 -08001854
1855 var bottom = this.getVTScrollBottom();
Robert Ginda579186b2012-09-26 11:40:04 -07001856 count = Math.min(count, bottom - cursorRow);
rginda8ba33642011-12-14 12:31:31 -08001857
Robert Ginda579186b2012-09-26 11:40:04 -07001858 // The moveCount is the number of rows we need to relocate to make room for
1859 // the new row(s). The count is the distance to move them.
1860 var moveCount = bottom - cursorRow - count + 1;
1861 if (moveCount)
1862 this.moveRows_(cursorRow, moveCount, cursorRow + count);
rginda8ba33642011-12-14 12:31:31 -08001863
Robert Ginda579186b2012-09-26 11:40:04 -07001864 for (var i = count - 1; i >= 0; i--) {
1865 this.setAbsoluteCursorPosition(cursorRow + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001866 this.screen_.clearCursorRow();
1867 }
rginda8ba33642011-12-14 12:31:31 -08001868};
1869
1870/**
1871 * VT command to delete lines at the current cursor row.
1872 *
1873 * New rows are added to the bottom of scroll region to take their place. New
1874 * rows are strictly there to take up space and have no content or style.
1875 */
1876hterm.Terminal.prototype.deleteLines = function(count) {
rginda87b86462011-12-14 13:48:03 -08001877 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001878
rginda87b86462011-12-14 13:48:03 -08001879 var top = cursor.row;
rginda8ba33642011-12-14 12:31:31 -08001880 var bottom = this.getVTScrollBottom();
1881
rginda87b86462011-12-14 13:48:03 -08001882 var maxCount = bottom - top + 1;
rginda8ba33642011-12-14 12:31:31 -08001883 count = Math.min(count, maxCount);
1884
rginda87b86462011-12-14 13:48:03 -08001885 var moveStart = bottom - count + 1;
rginda8ba33642011-12-14 12:31:31 -08001886 if (count != maxCount)
1887 this.moveRows_(top, count, moveStart);
1888
1889 for (var i = 0; i < count; i++) {
rginda87b86462011-12-14 13:48:03 -08001890 this.setAbsoluteCursorPosition(moveStart + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001891 this.screen_.clearCursorRow();
1892 }
1893
rginda87b86462011-12-14 13:48:03 -08001894 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001895 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001896};
1897
1898/**
1899 * Inserts the given number of spaces at the current cursor position.
1900 *
rginda87b86462011-12-14 13:48:03 -08001901 * The cursor position is not changed.
rginda8ba33642011-12-14 12:31:31 -08001902 */
1903hterm.Terminal.prototype.insertSpace = function(count) {
rginda87b86462011-12-14 13:48:03 -08001904 var cursor = this.saveCursor();
1905
rgindacbbd7482012-06-13 15:06:16 -07001906 var ws = lib.f.getWhitespace(count || 1);
rginda8ba33642011-12-14 12:31:31 -08001907 this.screen_.insertString(ws);
rgindaa19afe22012-01-25 15:40:22 -08001908 this.screen_.maybeClipCurrentRow();
rginda87b86462011-12-14 13:48:03 -08001909
1910 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001911 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001912};
1913
1914/**
1915 * Forward-delete the specified number of characters starting at the cursor
1916 * position.
1917 *
1918 * @param {integer} count The number of characters to delete.
1919 */
1920hterm.Terminal.prototype.deleteChars = function(count) {
Robert Ginda7fd57082012-09-25 14:41:47 -07001921 var deleted = this.screen_.deleteChars(count);
1922 if (deleted && !this.screen_.textAttributes.isDefault()) {
1923 var cursor = this.saveCursor();
1924 this.setCursorColumn(this.screenSize.width - deleted);
1925 this.screen_.insertString(lib.f.getWhitespace(deleted));
1926 this.restoreCursor(cursor);
1927 }
1928
David Benjamin54e8bf62012-06-01 22:31:40 -04001929 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001930};
1931
1932/**
1933 * Shift rows in the scroll region upwards by a given number of lines.
1934 *
1935 * New rows are inserted at the bottom of the scroll region to fill the
1936 * vacated rows. The new rows not filled out with the current text attributes.
1937 *
1938 * This function does not affect the scrollback rows at all. Rows shifted
1939 * off the top are lost.
1940 *
rginda87b86462011-12-14 13:48:03 -08001941 * The cursor position is not altered.
1942 *
rginda8ba33642011-12-14 12:31:31 -08001943 * @param {integer} count The number of rows to scroll.
1944 */
1945hterm.Terminal.prototype.vtScrollUp = function(count) {
rginda87b86462011-12-14 13:48:03 -08001946 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001947
rginda87b86462011-12-14 13:48:03 -08001948 this.setAbsoluteCursorRow(this.getVTScrollTop());
rginda8ba33642011-12-14 12:31:31 -08001949 this.deleteLines(count);
1950
rginda87b86462011-12-14 13:48:03 -08001951 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001952};
1953
1954/**
1955 * Shift rows below the cursor down by a given number of lines.
1956 *
1957 * This function respects the current scroll region.
1958 *
1959 * New rows are inserted at the top of the scroll region to fill the
1960 * vacated rows. The new rows not filled out with the current text attributes.
1961 *
1962 * This function does not affect the scrollback rows at all. Rows shifted
1963 * off the bottom are lost.
1964 *
1965 * @param {integer} count The number of rows to scroll.
1966 */
1967hterm.Terminal.prototype.vtScrollDown = function(opt_count) {
rginda87b86462011-12-14 13:48:03 -08001968 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001969
rginda87b86462011-12-14 13:48:03 -08001970 this.setAbsoluteCursorPosition(this.getVTScrollTop(), 0);
rginda8ba33642011-12-14 12:31:31 -08001971 this.insertLines(opt_count);
1972
rginda87b86462011-12-14 13:48:03 -08001973 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001974};
1975
rginda87b86462011-12-14 13:48:03 -08001976
rginda8ba33642011-12-14 12:31:31 -08001977/**
1978 * Set the cursor position.
1979 *
1980 * The cursor row is relative to the scroll region if the terminal has
1981 * 'origin mode' enabled, or relative to the addressable screen otherwise.
1982 *
1983 * @param {integer} row The new zero-based cursor row.
1984 * @param {integer} row The new zero-based cursor column.
1985 */
1986hterm.Terminal.prototype.setCursorPosition = function(row, column) {
1987 if (this.options_.originMode) {
rginda87b86462011-12-14 13:48:03 -08001988 this.setRelativeCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001989 } else {
rginda87b86462011-12-14 13:48:03 -08001990 this.setAbsoluteCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001991 }
rginda87b86462011-12-14 13:48:03 -08001992};
rginda8ba33642011-12-14 12:31:31 -08001993
rginda87b86462011-12-14 13:48:03 -08001994hterm.Terminal.prototype.setRelativeCursorPosition = function(row, column) {
1995 var scrollTop = this.getVTScrollTop();
rgindacbbd7482012-06-13 15:06:16 -07001996 row = lib.f.clamp(row + scrollTop, scrollTop, this.getVTScrollBottom());
1997 column = lib.f.clamp(column, 0, this.screenSize.width - 1);
rginda87b86462011-12-14 13:48:03 -08001998 this.screen_.setCursorPosition(row, column);
1999};
2000
2001hterm.Terminal.prototype.setAbsoluteCursorPosition = function(row, column) {
rgindacbbd7482012-06-13 15:06:16 -07002002 row = lib.f.clamp(row, 0, this.screenSize.height - 1);
2003 column = lib.f.clamp(column, 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08002004 this.screen_.setCursorPosition(row, column);
2005};
2006
2007/**
2008 * Set the cursor column.
2009 *
2010 * @param {integer} column The new zero-based cursor column.
2011 */
2012hterm.Terminal.prototype.setCursorColumn = function(column) {
rginda87b86462011-12-14 13:48:03 -08002013 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, column);
rginda8ba33642011-12-14 12:31:31 -08002014};
2015
2016/**
2017 * Return the cursor column.
2018 *
2019 * @return {integer} The zero-based cursor column.
2020 */
2021hterm.Terminal.prototype.getCursorColumn = function() {
2022 return this.screen_.cursorPosition.column;
2023};
2024
2025/**
2026 * Set the cursor row.
2027 *
2028 * The cursor row is relative to the scroll region if the terminal has
2029 * 'origin mode' enabled, or relative to the addressable screen otherwise.
2030 *
2031 * @param {integer} row The new cursor row.
2032 */
rginda87b86462011-12-14 13:48:03 -08002033hterm.Terminal.prototype.setAbsoluteCursorRow = function(row) {
2034 this.setAbsoluteCursorPosition(row, this.screen_.cursorPosition.column);
rginda8ba33642011-12-14 12:31:31 -08002035};
2036
2037/**
2038 * Return the cursor row.
2039 *
2040 * @return {integer} The zero-based cursor row.
2041 */
2042hterm.Terminal.prototype.getCursorRow = function(row) {
2043 return this.screen_.cursorPosition.row;
2044};
2045
2046/**
2047 * Request that the ScrollPort redraw itself soon.
2048 *
2049 * The redraw will happen asynchronously, soon after the call stack winds down.
2050 * Multiple calls will be coalesced into a single redraw.
2051 */
2052hterm.Terminal.prototype.scheduleRedraw_ = function() {
rginda87b86462011-12-14 13:48:03 -08002053 if (this.timeouts_.redraw)
2054 return;
rginda8ba33642011-12-14 12:31:31 -08002055
2056 var self = this;
rginda87b86462011-12-14 13:48:03 -08002057 this.timeouts_.redraw = setTimeout(function() {
2058 delete self.timeouts_.redraw;
rginda8ba33642011-12-14 12:31:31 -08002059 self.scrollPort_.redraw_();
2060 }, 0);
2061};
2062
2063/**
2064 * Request that the ScrollPort be scrolled to the bottom.
2065 *
2066 * The scroll will happen asynchronously, soon after the call stack winds down.
2067 * Multiple calls will be coalesced into a single scroll.
2068 *
2069 * This affects the scrollbar position of the ScrollPort, and has nothing to
2070 * do with the VT scroll commands.
2071 */
2072hterm.Terminal.prototype.scheduleScrollDown_ = function() {
2073 if (this.timeouts_.scrollDown)
rginda87b86462011-12-14 13:48:03 -08002074 return;
rginda8ba33642011-12-14 12:31:31 -08002075
2076 var self = this;
2077 this.timeouts_.scrollDown = setTimeout(function() {
2078 delete self.timeouts_.scrollDown;
2079 self.scrollPort_.scrollRowToBottom(self.getRowCount());
2080 }, 10);
2081};
2082
2083/**
2084 * Move the cursor up a specified number of rows.
2085 *
2086 * @param {integer} count The number of rows to move the cursor.
2087 */
2088hterm.Terminal.prototype.cursorUp = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08002089 return this.cursorDown(-(count || 1));
rginda8ba33642011-12-14 12:31:31 -08002090};
2091
2092/**
2093 * Move the cursor down a specified number of rows.
2094 *
2095 * @param {integer} count The number of rows to move the cursor.
2096 */
2097hterm.Terminal.prototype.cursorDown = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08002098 count = count || 1;
rginda8ba33642011-12-14 12:31:31 -08002099 var minHeight = (this.options_.originMode ? this.getVTScrollTop() : 0);
2100 var maxHeight = (this.options_.originMode ? this.getVTScrollBottom() :
2101 this.screenSize.height - 1);
2102
rgindacbbd7482012-06-13 15:06:16 -07002103 var row = lib.f.clamp(this.screen_.cursorPosition.row + count,
rginda8ba33642011-12-14 12:31:31 -08002104 minHeight, maxHeight);
rginda87b86462011-12-14 13:48:03 -08002105 this.setAbsoluteCursorRow(row);
rginda8ba33642011-12-14 12:31:31 -08002106};
2107
2108/**
2109 * Move the cursor left a specified number of columns.
2110 *
Robert Gindaaaba6132014-07-16 16:33:07 -07002111 * If reverse wraparound mode is enabled and the previous row wrapped into
2112 * the current row then we back up through the wraparound as well.
2113 *
rginda8ba33642011-12-14 12:31:31 -08002114 * @param {integer} count The number of columns to move the cursor.
2115 */
2116hterm.Terminal.prototype.cursorLeft = function(count) {
Robert Gindaaaba6132014-07-16 16:33:07 -07002117 count = count || 1;
2118
2119 if (count < 1)
2120 return;
2121
2122 var currentColumn = this.screen_.cursorPosition.column;
Robert Gindabfb32622014-07-17 13:20:27 -07002123 if (this.options_.reverseWraparound) {
2124 if (this.screen_.cursorPosition.overflow) {
2125 // If this cursor is in the right margin, consume one count to get it
2126 // back to the last column. This only applies when we're in reverse
2127 // wraparound mode.
2128 count--;
2129 this.clearCursorOverflow();
2130
2131 if (!count)
Robert Gindaaaba6132014-07-16 16:33:07 -07002132 return;
Robert Gindaaaba6132014-07-16 16:33:07 -07002133 }
2134
Robert Gindabfb32622014-07-17 13:20:27 -07002135 var newRow = this.screen_.cursorPosition.row;
2136 var newColumn = currentColumn - count;
2137 if (newColumn < 0) {
2138 newRow = newRow - Math.floor(count / this.screenSize.width) - 1;
2139 if (newRow < 0) {
2140 // xterm also wraps from row 0 to the last row.
2141 newRow = this.screenSize.height + newRow % this.screenSize.height;
2142 }
2143 newColumn = this.screenSize.width + newColumn % this.screenSize.width;
2144 }
Robert Gindaaaba6132014-07-16 16:33:07 -07002145
Robert Gindabfb32622014-07-17 13:20:27 -07002146 this.setCursorPosition(Math.max(newRow, 0), newColumn);
2147
2148 } else {
2149 var newColumn = Math.max(currentColumn - count, 0);
2150 this.setCursorColumn(newColumn);
2151 }
rginda8ba33642011-12-14 12:31:31 -08002152};
2153
2154/**
2155 * Move the cursor right a specified number of columns.
2156 *
2157 * @param {integer} count The number of columns to move the cursor.
2158 */
2159hterm.Terminal.prototype.cursorRight = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08002160 count = count || 1;
Robert Gindaaaba6132014-07-16 16:33:07 -07002161
2162 if (count < 1)
2163 return;
2164
rgindacbbd7482012-06-13 15:06:16 -07002165 var column = lib.f.clamp(this.screen_.cursorPosition.column + count,
rginda87b86462011-12-14 13:48:03 -08002166 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08002167 this.setCursorColumn(column);
2168};
2169
2170/**
2171 * Reverse the foreground and background colors of the terminal.
2172 *
2173 * This only affects text that was drawn with no attributes.
2174 *
2175 * TODO(rginda): Test xterm to see if reverse is respected for text that has
2176 * been drawn with attributes that happen to coincide with the default
2177 * 'no-attribute' colors. My guess is probably not.
2178 */
2179hterm.Terminal.prototype.setReverseVideo = function(state) {
rginda87b86462011-12-14 13:48:03 -08002180 this.options_.reverseVideo = state;
rginda8ba33642011-12-14 12:31:31 -08002181 if (state) {
rginda9f5222b2012-03-05 11:53:28 -08002182 this.scrollPort_.setForegroundColor(this.prefs_.get('background-color'));
2183 this.scrollPort_.setBackgroundColor(this.prefs_.get('foreground-color'));
rginda8ba33642011-12-14 12:31:31 -08002184 } else {
rginda9f5222b2012-03-05 11:53:28 -08002185 this.scrollPort_.setForegroundColor(this.prefs_.get('foreground-color'));
2186 this.scrollPort_.setBackgroundColor(this.prefs_.get('background-color'));
rginda8ba33642011-12-14 12:31:31 -08002187 }
2188};
2189
2190/**
rginda87b86462011-12-14 13:48:03 -08002191 * Ring the terminal bell.
Robert Ginda92e18102013-03-14 13:56:37 -07002192 *
2193 * This will not play the bell audio more than once per second.
rginda87b86462011-12-14 13:48:03 -08002194 */
2195hterm.Terminal.prototype.ringBell = function() {
rginda6d397402012-01-17 10:58:29 -08002196 this.cursorNode_.style.backgroundColor =
2197 this.scrollPort_.getForegroundColor();
rginda87b86462011-12-14 13:48:03 -08002198
2199 var self = this;
2200 setTimeout(function() {
rginda9f5222b2012-03-05 11:53:28 -08002201 self.cursorNode_.style.backgroundColor = self.prefs_.get('cursor-color');
rginda6d397402012-01-17 10:58:29 -08002202 }, 200);
Robert Ginda92e18102013-03-14 13:56:37 -07002203
Michael Kelly485ecd12014-06-09 11:41:56 -04002204 // bellSquelchTimeout_ affects both audio and notification bells.
2205 if (this.bellSquelchTimeout_)
2206 return;
2207
Robert Ginda92e18102013-03-14 13:56:37 -07002208 if (this.bellAudio_.getAttribute('src')) {
Robert Ginda92e18102013-03-14 13:56:37 -07002209 this.bellAudio_.play();
Robert Ginda92e18102013-03-14 13:56:37 -07002210 this.bellSequelchTimeout_ = setTimeout(function() {
2211 delete this.bellSquelchTimeout_;
Robert Gindaa6331372013-03-19 10:35:39 -07002212 }.bind(this), 500);
Robert Ginda92e18102013-03-14 13:56:37 -07002213 } else {
2214 delete this.bellSquelchTimeout_;
2215 }
Michael Kelly485ecd12014-06-09 11:41:56 -04002216
2217 if (this.desktopNotificationBell_ && !this.document_.hasFocus()) {
2218 var n = new Notification(
2219 lib.f.replaceVars(hterm.desktopNotificationTitle,
Robert Ginda348dc2b2014-06-24 14:42:23 -07002220 {'title': window.document.title || 'hterm'}));
Michael Kelly485ecd12014-06-09 11:41:56 -04002221 this.bellNotificationList_.push(n);
2222 // TODO: Should we try to raise the window here?
2223 n.onclick = function() { self.closeBellNotifications_(); };
2224 }
rginda87b86462011-12-14 13:48:03 -08002225};
2226
2227/**
rginda8ba33642011-12-14 12:31:31 -08002228 * Set the origin mode bit.
2229 *
2230 * If origin mode is on, certain VT cursor and scrolling commands measure their
2231 * row parameter relative to the VT scroll region. Otherwise, row 0 corresponds
2232 * to the top of the addressable screen.
2233 *
2234 * Defaults to off.
2235 *
2236 * @param {boolean} state True to set origin mode, false to unset.
2237 */
2238hterm.Terminal.prototype.setOriginMode = function(state) {
2239 this.options_.originMode = state;
rgindae4d29232012-01-19 10:47:13 -08002240 this.setCursorPosition(0, 0);
rginda8ba33642011-12-14 12:31:31 -08002241};
2242
2243/**
2244 * Set the insert mode bit.
2245 *
2246 * If insert mode is on, existing text beyond the cursor position will be
2247 * shifted right to make room for new text. Otherwise, new text overwrites
2248 * any existing text.
2249 *
2250 * Defaults to off.
2251 *
2252 * @param {boolean} state True to set insert mode, false to unset.
2253 */
2254hterm.Terminal.prototype.setInsertMode = function(state) {
2255 this.options_.insertMode = state;
2256};
2257
2258/**
rginda87b86462011-12-14 13:48:03 -08002259 * Set the auto carriage return bit.
2260 *
2261 * If auto carriage return is on then a formfeed character is interpreted
2262 * as a newline, otherwise it's the same as a linefeed. The difference boils
2263 * down to whether or not the cursor column is reset.
2264 */
2265hterm.Terminal.prototype.setAutoCarriageReturn = function(state) {
2266 this.options_.autoCarriageReturn = state;
2267};
2268
2269/**
rginda8ba33642011-12-14 12:31:31 -08002270 * Set the wraparound mode bit.
2271 *
2272 * If wraparound mode is on, certain VT commands will allow the cursor to wrap
2273 * to the start of the following row. Otherwise, the cursor is clamped to the
2274 * end of the screen and attempts to write past it are ignored.
2275 *
2276 * Defaults to on.
2277 *
2278 * @param {boolean} state True to set wraparound mode, false to unset.
2279 */
2280hterm.Terminal.prototype.setWraparound = function(state) {
2281 this.options_.wraparound = state;
2282};
2283
2284/**
2285 * Set the reverse-wraparound mode bit.
2286 *
2287 * If wraparound mode is off, certain VT commands will allow the cursor to wrap
2288 * to the end of the previous row. Otherwise, the cursor is clamped to column
2289 * 0.
2290 *
2291 * Defaults to off.
2292 *
2293 * @param {boolean} state True to set reverse-wraparound mode, false to unset.
2294 */
2295hterm.Terminal.prototype.setReverseWraparound = function(state) {
2296 this.options_.reverseWraparound = state;
2297};
2298
2299/**
2300 * Selects between the primary and alternate screens.
2301 *
2302 * If alternate mode is on, the alternate screen is active. Otherwise the
2303 * primary screen is active.
2304 *
2305 * Swapping screens has no effect on the scrollback buffer.
2306 *
2307 * Each screen maintains its own cursor position.
2308 *
2309 * Defaults to off.
2310 *
2311 * @param {boolean} state True to set alternate mode, false to unset.
2312 */
2313hterm.Terminal.prototype.setAlternateMode = function(state) {
rginda6d397402012-01-17 10:58:29 -08002314 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08002315 this.screen_ = state ? this.alternateScreen_ : this.primaryScreen_;
2316
rginda35c456b2012-02-09 17:29:05 -08002317 if (this.screen_.rowsArray.length &&
2318 this.screen_.rowsArray[0].rowIndex != this.scrollbackRows_.length) {
2319 // If the screen changed sizes while we were away, our rowIndexes may
2320 // be incorrect.
2321 var offset = this.scrollbackRows_.length;
2322 var ary = this.screen_.rowsArray;
rgindacbbd7482012-06-13 15:06:16 -07002323 for (var i = 0; i < ary.length; i++) {
rginda35c456b2012-02-09 17:29:05 -08002324 ary[i].rowIndex = offset + i;
2325 }
2326 }
rginda8ba33642011-12-14 12:31:31 -08002327
rginda35c456b2012-02-09 17:29:05 -08002328 this.realizeWidth_(this.screenSize.width);
2329 this.realizeHeight_(this.screenSize.height);
2330 this.scrollPort_.syncScrollHeight();
2331 this.scrollPort_.invalidate();
rginda8ba33642011-12-14 12:31:31 -08002332
rginda6d397402012-01-17 10:58:29 -08002333 this.restoreCursor(cursor);
rginda35c456b2012-02-09 17:29:05 -08002334 this.scrollPort_.resize();
rginda8ba33642011-12-14 12:31:31 -08002335};
2336
2337/**
2338 * Set the cursor-blink mode bit.
2339 *
2340 * If cursor-blink is on, the cursor will blink when it is visible. Otherwise
2341 * a visible cursor does not blink.
2342 *
2343 * You should make sure to turn blinking off if you're going to dispose of a
2344 * terminal, otherwise you'll leak a timeout.
2345 *
2346 * Defaults to on.
2347 *
2348 * @param {boolean} state True to set cursor-blink mode, false to unset.
2349 */
2350hterm.Terminal.prototype.setCursorBlink = function(state) {
2351 this.options_.cursorBlink = state;
2352
2353 if (!state && this.timeouts_.cursorBlink) {
2354 clearTimeout(this.timeouts_.cursorBlink);
2355 delete this.timeouts_.cursorBlink;
2356 }
2357
2358 if (this.options_.cursorVisible)
2359 this.setCursorVisible(true);
2360};
2361
2362/**
2363 * Set the cursor-visible mode bit.
2364 *
2365 * If cursor-visible is on, the cursor will be visible. Otherwise it will not.
2366 *
2367 * Defaults to on.
2368 *
2369 * @param {boolean} state True to set cursor-visible mode, false to unset.
2370 */
2371hterm.Terminal.prototype.setCursorVisible = function(state) {
2372 this.options_.cursorVisible = state;
2373
2374 if (!state) {
Brad Town1c2afa82015-03-11 21:36:58 -07002375 if (this.timeouts_.cursorBlink) {
2376 clearTimeout(this.timeouts_.cursorBlink);
2377 delete this.timeouts_.cursorBlink;
2378 }
rginda87b86462011-12-14 13:48:03 -08002379 this.cursorNode_.style.opacity = '0';
rginda8ba33642011-12-14 12:31:31 -08002380 return;
2381 }
2382
rginda87b86462011-12-14 13:48:03 -08002383 this.syncCursorPosition_();
2384
2385 this.cursorNode_.style.opacity = '1';
rginda8ba33642011-12-14 12:31:31 -08002386
2387 if (this.options_.cursorBlink) {
2388 if (this.timeouts_.cursorBlink)
2389 return;
2390
Robert Gindaea2183e2014-07-17 09:51:51 -07002391 this.onCursorBlink_();
rginda8ba33642011-12-14 12:31:31 -08002392 } else {
2393 if (this.timeouts_.cursorBlink) {
2394 clearTimeout(this.timeouts_.cursorBlink);
2395 delete this.timeouts_.cursorBlink;
2396 }
2397 }
2398};
2399
2400/**
rginda87b86462011-12-14 13:48:03 -08002401 * Synchronizes the visible cursor and document selection with the current
2402 * cursor coordinates.
rginda8ba33642011-12-14 12:31:31 -08002403 */
2404hterm.Terminal.prototype.syncCursorPosition_ = function() {
2405 var topRowIndex = this.scrollPort_.getTopRowIndex();
2406 var bottomRowIndex = this.scrollPort_.getBottomRowIndex(topRowIndex);
2407 var cursorRowIndex = this.scrollbackRows_.length +
2408 this.screen_.cursorPosition.row;
2409
2410 if (cursorRowIndex > bottomRowIndex) {
2411 // Cursor is scrolled off screen, move it outside of the visible area.
rginda35c456b2012-02-09 17:29:05 -08002412 this.cursorNode_.style.top = -this.scrollPort_.characterSize.height + 'px';
rginda8ba33642011-12-14 12:31:31 -08002413 return;
2414 }
2415
Robert Gindab837c052014-08-11 11:17:51 -07002416 if (this.options_.cursorVisible &&
2417 this.cursorNode_.style.display == 'none') {
2418 // Re-display the terminal cursor if it was hidden by the mouse cursor.
2419 this.cursorNode_.style.display = '';
2420 }
2421
2422
rginda8ba33642011-12-14 12:31:31 -08002423 this.cursorNode_.style.top = this.scrollPort_.visibleRowTopMargin +
rginda35c456b2012-02-09 17:29:05 -08002424 this.scrollPort_.characterSize.height * (cursorRowIndex - topRowIndex) +
2425 'px';
2426 this.cursorNode_.style.left = this.scrollPort_.characterSize.width *
2427 this.screen_.cursorPosition.column + 'px';
rginda87b86462011-12-14 13:48:03 -08002428
2429 this.cursorNode_.setAttribute('title',
2430 '(' + this.screen_.cursorPosition.row +
2431 ', ' + this.screen_.cursorPosition.column +
2432 ')');
2433
2434 // Update the caret for a11y purposes.
2435 var selection = this.document_.getSelection();
2436 if (selection && selection.isCollapsed)
2437 this.screen_.syncSelectionCaret(selection);
rginda8ba33642011-12-14 12:31:31 -08002438};
2439
Robert Gindafb1be6a2013-12-11 11:56:22 -08002440/**
2441 * Adjusts the style of this.cursorNode_ according to the current cursor shape
2442 * and character cell dimensions.
2443 */
Robert Ginda830583c2013-08-07 13:20:46 -07002444hterm.Terminal.prototype.restyleCursor_ = function() {
2445 var shape = this.cursorShape_;
2446
2447 if (this.cursorNode_.getAttribute('focus') == 'false') {
2448 // Always show a block cursor when unfocused.
2449 shape = hterm.Terminal.cursorShape.BLOCK;
2450 }
2451
2452 var style = this.cursorNode_.style;
2453
Robert Gindafb1be6a2013-12-11 11:56:22 -08002454 style.width = this.scrollPort_.characterSize.width + 'px';
2455
Robert Ginda830583c2013-08-07 13:20:46 -07002456 switch (shape) {
2457 case hterm.Terminal.cursorShape.BEAM:
2458 style.height = this.scrollPort_.characterSize.height + 'px';
2459 style.backgroundColor = 'transparent';
2460 style.borderBottomStyle = null;
2461 style.borderLeftStyle = 'solid';
2462 break;
2463
2464 case hterm.Terminal.cursorShape.UNDERLINE:
2465 style.height = this.scrollPort_.characterSize.baseline + 'px';
2466 style.backgroundColor = 'transparent';
2467 style.borderBottomStyle = 'solid';
2468 // correct the size to put it exactly at the baseline
2469 style.borderLeftStyle = null;
2470 break;
2471
2472 default:
2473 style.height = this.scrollPort_.characterSize.height + 'px';
2474 style.backgroundColor = this.cursorColor_;
2475 style.borderBottomStyle = null;
2476 style.borderLeftStyle = null;
2477 break;
2478 }
2479};
2480
rginda8ba33642011-12-14 12:31:31 -08002481/**
2482 * Synchronizes the visible cursor with the current cursor coordinates.
2483 *
2484 * The sync will happen asynchronously, soon after the call stack winds down.
2485 * Multiple calls will be coalesced into a single sync.
2486 */
2487hterm.Terminal.prototype.scheduleSyncCursorPosition_ = function() {
2488 if (this.timeouts_.syncCursor)
rginda87b86462011-12-14 13:48:03 -08002489 return;
rginda8ba33642011-12-14 12:31:31 -08002490
2491 var self = this;
2492 this.timeouts_.syncCursor = setTimeout(function() {
2493 self.syncCursorPosition_();
2494 delete self.timeouts_.syncCursor;
rginda87b86462011-12-14 13:48:03 -08002495 }, 0);
2496};
2497
rgindacc2996c2012-02-24 14:59:31 -08002498/**
rgindaf522ce02012-04-17 17:49:17 -07002499 * Show or hide the zoom warning.
2500 *
2501 * The zoom warning is a message warning the user that their browser zoom must
2502 * be set to 100% in order for hterm to function properly.
2503 *
2504 * @param {boolean} state True to show the message, false to hide it.
2505 */
2506hterm.Terminal.prototype.showZoomWarning_ = function(state) {
2507 if (!this.zoomWarningNode_) {
2508 if (!state)
2509 return;
2510
2511 this.zoomWarningNode_ = this.document_.createElement('div');
2512 this.zoomWarningNode_.style.cssText = (
2513 'color: black;' +
2514 'background-color: #ff2222;' +
2515 'font-size: large;' +
2516 'border-radius: 8px;' +
2517 'opacity: 0.75;' +
2518 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2519 'top: 0.5em;' +
2520 'right: 1.2em;' +
2521 'position: absolute;' +
2522 '-webkit-text-size-adjust: none;' +
Rob Spies06533ba2014-04-24 11:20:37 -07002523 '-webkit-user-select: none;' +
2524 '-moz-text-size-adjust: none;' +
2525 '-moz-user-select: none;');
rgindaf522ce02012-04-17 17:49:17 -07002526 }
2527
Robert Gindab4839c22013-02-28 16:52:10 -08002528 this.zoomWarningNode_.textContent = lib.MessageManager.replaceReferences(
2529 hterm.zoomWarningMessage,
2530 [parseInt(this.scrollPort_.characterSize.zoomFactor * 100)]);
2531
rgindaf522ce02012-04-17 17:49:17 -07002532 this.zoomWarningNode_.style.fontFamily = this.prefs_.get('font-family');
2533
2534 if (state) {
2535 if (!this.zoomWarningNode_.parentNode)
2536 this.div_.parentNode.appendChild(this.zoomWarningNode_);
2537 } else if (this.zoomWarningNode_.parentNode) {
2538 this.zoomWarningNode_.parentNode.removeChild(this.zoomWarningNode_);
2539 }
2540};
2541
2542/**
rgindacc2996c2012-02-24 14:59:31 -08002543 * Show the terminal overlay for a given amount of time.
2544 *
2545 * The terminal overlay appears in inverse video in a large font, centered
2546 * over the terminal. You should probably keep the overlay message brief,
2547 * since it's in a large font and you probably aren't going to check the size
2548 * of the terminal first.
2549 *
2550 * @param {string} msg The text (not HTML) message to display in the overlay.
2551 * @param {number} opt_timeout The amount of time to wait before fading out
2552 * the overlay. Defaults to 1.5 seconds. Pass null to have the overlay
2553 * stay up forever (or until the next overlay).
2554 */
2555hterm.Terminal.prototype.showOverlay = function(msg, opt_timeout) {
rgindaf0090c92012-02-10 14:58:52 -08002556 if (!this.overlayNode_) {
2557 if (!this.div_)
2558 return;
2559
2560 this.overlayNode_ = this.document_.createElement('div');
2561 this.overlayNode_.style.cssText = (
rgindaf0090c92012-02-10 14:58:52 -08002562 'border-radius: 15px;' +
rgindaf0090c92012-02-10 14:58:52 -08002563 'font-size: xx-large;' +
2564 'opacity: 0.75;' +
2565 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2566 'position: absolute;' +
2567 '-webkit-user-select: none;' +
Rob Spies06533ba2014-04-24 11:20:37 -07002568 '-webkit-transition: opacity 180ms ease-in;' +
2569 '-moz-user-select: none;' +
2570 '-moz-transition: opacity 180ms ease-in;');
Robert Ginda70926e42013-11-25 14:56:36 -08002571
2572 this.overlayNode_.addEventListener('mousedown', function(e) {
2573 e.preventDefault();
2574 e.stopPropagation();
2575 }, true);
rgindaf0090c92012-02-10 14:58:52 -08002576 }
2577
rginda9f5222b2012-03-05 11:53:28 -08002578 this.overlayNode_.style.color = this.prefs_.get('background-color');
2579 this.overlayNode_.style.backgroundColor = this.prefs_.get('foreground-color');
2580 this.overlayNode_.style.fontFamily = this.prefs_.get('font-family');
2581
rgindaf0090c92012-02-10 14:58:52 -08002582 this.overlayNode_.textContent = msg;
2583 this.overlayNode_.style.opacity = '0.75';
2584
2585 if (!this.overlayNode_.parentNode)
2586 this.div_.appendChild(this.overlayNode_);
2587
Robert Ginda97769282013-02-01 15:30:30 -08002588 var divSize = hterm.getClientSize(this.div_);
2589 var overlaySize = hterm.getClientSize(this.overlayNode_);
2590
Robert Ginda8a59f762014-07-23 11:29:55 -07002591 this.overlayNode_.style.top =
2592 (divSize.height - overlaySize.height) / 2 + 'px';
Robert Ginda97769282013-02-01 15:30:30 -08002593 this.overlayNode_.style.left = (divSize.width - overlaySize.width -
Robert Ginda8a59f762014-07-23 11:29:55 -07002594 this.scrollPort_.currentScrollbarWidthPx) / 2 + 'px';
rgindaf0090c92012-02-10 14:58:52 -08002595
2596 var self = this;
2597
2598 if (this.overlayTimeout_)
2599 clearTimeout(this.overlayTimeout_);
2600
rgindacc2996c2012-02-24 14:59:31 -08002601 if (opt_timeout === null)
2602 return;
2603
rgindaf0090c92012-02-10 14:58:52 -08002604 this.overlayTimeout_ = setTimeout(function() {
2605 self.overlayNode_.style.opacity = '0';
Robert Ginda70926e42013-11-25 14:56:36 -08002606 self.overlayTimeout_ = setTimeout(function() {
rginda259dcca2012-03-14 16:37:11 -07002607 if (self.overlayNode_.parentNode)
2608 self.overlayNode_.parentNode.removeChild(self.overlayNode_);
rgindaf0090c92012-02-10 14:58:52 -08002609 self.overlayTimeout_ = null;
2610 self.overlayNode_.style.opacity = '0.75';
2611 }, 200);
rgindacc2996c2012-02-24 14:59:31 -08002612 }, opt_timeout || 1500);
rgindaf0090c92012-02-10 14:58:52 -08002613};
2614
rginda4bba5e12012-06-20 16:15:30 -07002615/**
2616 * Paste from the system clipboard to the terminal.
2617 */
2618hterm.Terminal.prototype.paste = function() {
2619 hterm.pasteFromClipboard(this.document_);
2620};
2621
2622/**
2623 * Copy a string to the system clipboard.
2624 *
2625 * Note: If there is a selected range in the terminal, it'll be cleared.
2626 */
2627hterm.Terminal.prototype.copyStringToClipboard = function(str) {
Robert Ginda4e4d42c2014-03-04 14:07:23 -08002628 if (this.prefs_.get('enable-clipboard-notice'))
2629 setTimeout(this.showOverlay.bind(this, hterm.notifyCopyMessage, 500), 200);
2630
rgindaa09e7332012-08-17 12:49:51 -07002631 var copySource = this.document_.createElement('pre');
rginda4bba5e12012-06-20 16:15:30 -07002632 copySource.textContent = str;
2633 copySource.style.cssText = (
2634 '-webkit-user-select: text;' +
Rob Spies06533ba2014-04-24 11:20:37 -07002635 '-moz-user-select: text;' +
rginda4bba5e12012-06-20 16:15:30 -07002636 'position: absolute;' +
2637 'top: -99px');
2638
2639 this.document_.body.appendChild(copySource);
rgindafaa74742012-08-21 13:34:03 -07002640
rginda4bba5e12012-06-20 16:15:30 -07002641 var selection = this.document_.getSelection();
rgindafaa74742012-08-21 13:34:03 -07002642 var anchorNode = selection.anchorNode;
2643 var anchorOffset = selection.anchorOffset;
2644 var focusNode = selection.focusNode;
2645 var focusOffset = selection.focusOffset;
2646
rginda4bba5e12012-06-20 16:15:30 -07002647 selection.selectAllChildren(copySource);
2648
rgindaa09e7332012-08-17 12:49:51 -07002649 hterm.copySelectionToClipboard(this.document_);
rginda4bba5e12012-06-20 16:15:30 -07002650
Rob Spies56953412014-04-28 14:09:47 -07002651 // IE doesn't support selection.extend. This means that the selection
2652 // won't return on IE.
Robert Ginda6f4f0aa2014-07-28 10:21:39 -07002653 if (selection.extend) {
Rob Spies56953412014-04-28 14:09:47 -07002654 selection.collapse(anchorNode, anchorOffset);
2655 selection.extend(focusNode, focusOffset);
2656 }
rgindafaa74742012-08-21 13:34:03 -07002657
rginda4bba5e12012-06-20 16:15:30 -07002658 copySource.parentNode.removeChild(copySource);
2659};
2660
rgindaa09e7332012-08-17 12:49:51 -07002661hterm.Terminal.prototype.getSelectionText = function() {
2662 var selection = this.scrollPort_.selection;
2663 selection.sync();
2664
2665 if (selection.isCollapsed)
2666 return null;
2667
2668
2669 // Start offset measures from the beginning of the line.
2670 var startOffset = selection.startOffset;
2671 var node = selection.startNode;
Robert Ginda0d190502012-10-02 10:59:00 -07002672
Robert Gindafdbb3f22012-09-06 20:23:06 -07002673 if (node.nodeName != 'X-ROW') {
2674 // If the selection doesn't start on an x-row node, then it must be
2675 // somewhere inside the x-row. Add any characters from previous siblings
2676 // into the start offset.
Robert Ginda0d190502012-10-02 10:59:00 -07002677
2678 if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') {
2679 // If node is the text node in a styled span, move up to the span node.
2680 node = node.parentNode;
2681 }
2682
Robert Gindafdbb3f22012-09-06 20:23:06 -07002683 while (node.previousSibling) {
2684 node = node.previousSibling;
Ricky Liang48f05cb2013-12-31 23:35:29 +08002685 startOffset += hterm.TextAttributes.nodeWidth(node);
Robert Gindafdbb3f22012-09-06 20:23:06 -07002686 }
rgindaa09e7332012-08-17 12:49:51 -07002687 }
2688
2689 // End offset measures from the end of the line.
Ricky Liang48f05cb2013-12-31 23:35:29 +08002690 var endOffset = (hterm.TextAttributes.nodeWidth(selection.endNode) -
2691 selection.endOffset);
rgindaa09e7332012-08-17 12:49:51 -07002692 var node = selection.endNode;
Robert Ginda0d190502012-10-02 10:59:00 -07002693
Robert Gindafdbb3f22012-09-06 20:23:06 -07002694 if (node.nodeName != 'X-ROW') {
2695 // If the selection doesn't end on an x-row node, then it must be
2696 // somewhere inside the x-row. Add any characters from following siblings
2697 // into the end offset.
Robert Ginda0d190502012-10-02 10:59:00 -07002698
2699 if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') {
2700 // If node is the text node in a styled span, move up to the span node.
2701 node = node.parentNode;
2702 }
2703
Robert Gindafdbb3f22012-09-06 20:23:06 -07002704 while (node.nextSibling) {
2705 node = node.nextSibling;
Ricky Liang48f05cb2013-12-31 23:35:29 +08002706 endOffset += hterm.TextAttributes.nodeWidth(node);
Robert Gindafdbb3f22012-09-06 20:23:06 -07002707 }
rgindaa09e7332012-08-17 12:49:51 -07002708 }
2709
2710 var rv = this.getRowsText(selection.startRow.rowIndex,
2711 selection.endRow.rowIndex + 1);
Ricky Liang48f05cb2013-12-31 23:35:29 +08002712 return lib.wc.substring(rv, startOffset, lib.wc.strWidth(rv) - endOffset);
rgindaa09e7332012-08-17 12:49:51 -07002713};
2714
rginda4bba5e12012-06-20 16:15:30 -07002715/**
2716 * Copy the current selection to the system clipboard, then clear it after a
2717 * short delay.
2718 */
2719hterm.Terminal.prototype.copySelectionToClipboard = function() {
rgindaa09e7332012-08-17 12:49:51 -07002720 var text = this.getSelectionText();
2721 if (text != null)
2722 this.copyStringToClipboard(text);
rginda4bba5e12012-06-20 16:15:30 -07002723};
2724
rgindaf0090c92012-02-10 14:58:52 -08002725hterm.Terminal.prototype.overlaySize = function() {
2726 this.showOverlay(this.screenSize.width + 'x' + this.screenSize.height);
2727};
2728
rginda87b86462011-12-14 13:48:03 -08002729/**
2730 * Invoked by hterm.Terminal.Keyboard when a VT keystroke is detected.
2731 *
Robert Ginda8cb7d902013-06-20 14:37:18 -07002732 * @param {string} string The VT string representing the keystroke, in UTF-16.
rginda87b86462011-12-14 13:48:03 -08002733 */
2734hterm.Terminal.prototype.onVTKeystroke = function(string) {
rginda9f5222b2012-03-05 11:53:28 -08002735 if (this.scrollOnKeystroke_)
rginda87b86462011-12-14 13:48:03 -08002736 this.scrollPort_.scrollRowToBottom(this.getRowCount());
2737
Robert Ginda8cb7d902013-06-20 14:37:18 -07002738 this.io.onVTKeystroke(this.keyboard.encode(string));
rginda8ba33642011-12-14 12:31:31 -08002739};
2740
2741/**
rgindad5613292012-06-19 15:40:37 -07002742 * Add the terminalRow and terminalColumn properties to mouse events and
2743 * then forward on to onMouse().
2744 *
2745 * The terminalRow and terminalColumn properties contain the (row, column)
2746 * coordinates for the mouse event.
2747 */
2748hterm.Terminal.prototype.onMouse_ = function(e) {
rgindafaa74742012-08-21 13:34:03 -07002749 if (e.processedByTerminalHandler_) {
2750 // We register our event handlers on the document, as well as the cursor
2751 // and the scroll blocker. Mouse events that occur on the cursor or
2752 // scroll blocker will also appear on the document, but we don't want to
2753 // process them twice.
2754 //
2755 // We can't just prevent bubbling because that has other side effects, so
2756 // we decorate the event object with this property instead.
2757 return;
2758 }
2759
2760 e.processedByTerminalHandler_ = true;
2761
Robert Gindaeda48db2014-07-17 09:25:30 -07002762 // One based row/column stored on the mouse event.
2763 e.terminalRow = parseInt((e.clientY - this.scrollPort_.visibleRowTopMargin) /
2764 this.scrollPort_.characterSize.height) + 1;
2765 e.terminalColumn = parseInt(e.clientX /
2766 this.scrollPort_.characterSize.width) + 1;
2767
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002768 if (e.type == 'mousedown' && e.terminalColumn > this.screenSize.width) {
2769 // Mousedown in the scrollbar area.
rginda4bba5e12012-06-20 16:15:30 -07002770 return;
2771 }
2772
Robert Gindab837c052014-08-11 11:17:51 -07002773 if (this.options_.cursorVisible &&
2774 this.vt.mouseReport == this.vt.MOUSE_REPORT_DISABLED) {
2775 // If the cursor is visible and we're not sending mouse events to the
2776 // host app, then we want to hide the terminal cursor when the mouse
2777 // cursor is over top. This keeps the terminal cursor from interfering
2778 // with local text selection.
Robert Gindaeda48db2014-07-17 09:25:30 -07002779 if (e.terminalRow - 1 == this.screen_.cursorPosition.row &&
2780 e.terminalColumn - 1 == this.screen_.cursorPosition.column) {
2781 this.cursorNode_.style.display = 'none';
2782 } else if (this.cursorNode_.style.display == 'none') {
2783 this.cursorNode_.style.display = '';
2784 }
2785 }
rgindad5613292012-06-19 15:40:37 -07002786
Robert Ginda928cf632014-03-05 15:07:41 -08002787 if (e.type == 'mousedown') {
2788 if (e.altKey || this.vt.mouseReport == this.vt.MOUSE_REPORT_DISABLED) {
2789 // If VT mouse reporting is disabled, or has been defeated with
2790 // alt-mousedown, then the mouse will act on the local selection.
2791 this.reportMouseEvents_ = false;
2792 this.setSelectionEnabled(true);
2793 } else {
2794 // Otherwise we defer ownership of the mouse to the VT.
2795 this.reportMouseEvents_ = true;
Robert Ginda3ae37822014-05-15 13:05:35 -07002796 this.document_.getSelection().collapseToEnd();
Robert Ginda928cf632014-03-05 15:07:41 -08002797 this.setSelectionEnabled(false);
2798 e.preventDefault();
2799 }
2800 }
2801
2802 if (!this.reportMouseEvents_) {
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002803 if (e.type == 'dblclick') {
2804 this.screen_.expandSelection(this.document_.getSelection());
2805 hterm.copySelectionToClipboard(this.document_);
rgindad5613292012-06-19 15:40:37 -07002806 }
2807
Robert Ginda928cf632014-03-05 15:07:41 -08002808 if (e.type == 'mousedown' && e.which == this.mousePasteButton)
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002809 this.paste();
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002810
2811 if (e.type == 'mouseup' && e.which == 1 && this.copyOnSelect &&
2812 !this.document_.getSelection().isCollapsed) {
2813 hterm.copySelectionToClipboard(this.document_);
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002814 }
2815
2816 if ((e.type == 'mousemove' || e.type == 'mouseup') &&
2817 this.scrollBlockerNode_.engaged) {
2818 // Disengage the scroll-blocker after one of these events.
2819 this.scrollBlockerNode_.engaged = false;
2820 this.scrollBlockerNode_.style.top = '-99px';
2821 }
2822
Robert Ginda928cf632014-03-05 15:07:41 -08002823 } else /* if (this.reportMouseEvents) */ {
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002824 if (!this.scrollBlockerNode_.engaged) {
2825 if (e.type == 'mousedown') {
2826 // Move the scroll-blocker into place if we want to keep the scrollport
2827 // from scrolling.
2828 this.scrollBlockerNode_.engaged = true;
2829 this.scrollBlockerNode_.style.top = (e.clientY - 5) + 'px';
2830 this.scrollBlockerNode_.style.left = (e.clientX - 5) + 'px';
2831 } else if (e.type == 'mousemove') {
2832 // Oh. This means that drag-scroll was disabled AFTER the mouse down,
2833 // in which case it's too late to engage the scroll-blocker.
Robert Ginda3ae37822014-05-15 13:05:35 -07002834 this.document_.getSelection().collapseToEnd();
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002835 e.preventDefault();
2836 }
2837 }
Robert Ginda928cf632014-03-05 15:07:41 -08002838
2839 this.onMouse(e);
rgindad5613292012-06-19 15:40:37 -07002840 }
2841
Robert Ginda928cf632014-03-05 15:07:41 -08002842 if (e.type == 'mouseup' && this.document_.getSelection().isCollapsed) {
2843 // Restore this on mouseup in case it was temporarily defeated with a
2844 // alt-mousedown. Only do this when the selection is empty so that
2845 // we don't immediately kill the users selection.
2846 this.reportMouseEvents_ = (this.vt.mouseReport !=
2847 this.vt.MOUSE_REPORT_DISABLED);
2848 }
rgindad5613292012-06-19 15:40:37 -07002849};
2850
2851/**
2852 * Clients should override this if they care to know about mouse events.
2853 *
2854 * The event parameter will be a normal DOM mouse click event with additional
2855 * 'terminalRow' and 'terminalColumn' properties.
2856 */
2857hterm.Terminal.prototype.onMouse = function(e) { };
2858
2859/**
rginda8e92a692012-05-20 19:37:20 -07002860 * React when focus changes.
2861 */
Rob Spies06533ba2014-04-24 11:20:37 -07002862hterm.Terminal.prototype.onFocusChange_ = function(focused) {
2863 this.cursorNode_.setAttribute('focus', focused);
Robert Ginda830583c2013-08-07 13:20:46 -07002864 this.restyleCursor_();
Michael Kelly485ecd12014-06-09 11:41:56 -04002865 if (focused === true)
2866 this.closeBellNotifications_();
rginda8e92a692012-05-20 19:37:20 -07002867};
2868
2869/**
rginda8ba33642011-12-14 12:31:31 -08002870 * React when the ScrollPort is scrolled.
2871 */
2872hterm.Terminal.prototype.onScroll_ = function() {
2873 this.scheduleSyncCursorPosition_();
2874};
2875
2876/**
rginda9846e2f2012-01-27 13:53:33 -08002877 * React when text is pasted into the scrollPort.
2878 */
2879hterm.Terminal.prototype.onPaste_ = function(e) {
Robert Gindaa063b202014-07-21 11:08:25 -07002880 var data = e.text.replace(/\n/mg, '\r');
Connor Hegartyf525ceb2014-09-03 13:36:03 -07002881 data = this.keyboard.encode(data);
Robert Gindaa063b202014-07-21 11:08:25 -07002882 if (this.options_.bracketedPaste)
2883 data = '\x1b[200~' + data + '\x1b[201~';
2884
2885 this.io.sendString(data);
rginda9846e2f2012-01-27 13:53:33 -08002886};
2887
2888/**
rgindaa09e7332012-08-17 12:49:51 -07002889 * React when the user tries to copy from the scrollPort.
2890 */
2891hterm.Terminal.prototype.onCopy_ = function(e) {
Rob Spies0bec09b2014-06-06 15:58:09 -07002892 if (!this.useDefaultWindowCopy) {
2893 e.preventDefault();
2894 setTimeout(this.copySelectionToClipboard.bind(this), 0);
2895 }
rgindaa09e7332012-08-17 12:49:51 -07002896};
2897
2898/**
rginda8ba33642011-12-14 12:31:31 -08002899 * React when the ScrollPort is resized.
rgindac9bc5502012-01-18 11:48:44 -08002900 *
2901 * Note: This function should not directly contain code that alters the internal
2902 * state of the terminal. That kind of code belongs in realizeWidth or
2903 * realizeHeight, so that it can be executed synchronously in the case of a
2904 * programmatic width change.
rginda8ba33642011-12-14 12:31:31 -08002905 */
2906hterm.Terminal.prototype.onResize_ = function() {
Robert Ginda19f61292014-03-04 14:07:57 -08002907 var columnCount = Math.floor(this.scrollPort_.getScreenWidth() /
rginda35c456b2012-02-09 17:29:05 -08002908 this.scrollPort_.characterSize.width);
Rob Spiesf4e90e82015-01-28 12:10:13 -08002909 var rowCount = lib.f.smartFloorDivide(this.scrollPort_.getScreenHeight(),
rginda35c456b2012-02-09 17:29:05 -08002910 this.scrollPort_.characterSize.height);
2911
Robert Ginda4e83f3a2012-09-04 15:25:25 -07002912 if (columnCount <= 0 || rowCount <= 0) {
rginda35c456b2012-02-09 17:29:05 -08002913 // We avoid these situations since they happen sometimes when the terminal
Robert Ginda4e83f3a2012-09-04 15:25:25 -07002914 // gets removed from the document or during the initial load, and we can't
2915 // deal with that.
rginda35c456b2012-02-09 17:29:05 -08002916 return;
2917 }
2918
rgindaa8ba17d2012-08-15 14:41:10 -07002919 var isNewSize = (columnCount != this.screenSize.width ||
2920 rowCount != this.screenSize.height);
2921
2922 // We do this even if the size didn't change, just to be sure everything is
2923 // in sync.
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +04002924 this.realizeSize_(columnCount, rowCount);
rgindaf522ce02012-04-17 17:49:17 -07002925 this.showZoomWarning_(this.scrollPort_.characterSize.zoomFactor != 1);
rgindaa8ba17d2012-08-15 14:41:10 -07002926
2927 if (isNewSize)
2928 this.overlaySize();
2929
Robert Gindafb1be6a2013-12-11 11:56:22 -08002930 this.restyleCursor_();
rgindaa8ba17d2012-08-15 14:41:10 -07002931 this.scheduleSyncCursorPosition_();
rginda8ba33642011-12-14 12:31:31 -08002932};
2933
2934/**
2935 * Service the cursor blink timeout.
2936 */
2937hterm.Terminal.prototype.onCursorBlink_ = function() {
Robert Gindaea2183e2014-07-17 09:51:51 -07002938 if (!this.options_.cursorBlink) {
2939 delete this.timeouts_.cursorBlink;
2940 return;
2941 }
2942
Robert Ginda830583c2013-08-07 13:20:46 -07002943 if (this.cursorNode_.getAttribute('focus') == 'false' ||
2944 this.cursorNode_.style.opacity == '0') {
rginda87b86462011-12-14 13:48:03 -08002945 this.cursorNode_.style.opacity = '1';
Robert Gindaea2183e2014-07-17 09:51:51 -07002946 this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_,
2947 this.cursorBlinkCycle_[0]);
rginda8ba33642011-12-14 12:31:31 -08002948 } else {
rginda87b86462011-12-14 13:48:03 -08002949 this.cursorNode_.style.opacity = '0';
Robert Gindaea2183e2014-07-17 09:51:51 -07002950 this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_,
2951 this.cursorBlinkCycle_[1]);
rginda8ba33642011-12-14 12:31:31 -08002952 }
2953};
David Reveman8f552492012-03-28 12:18:41 -04002954
2955/**
2956 * Set the scrollbar-visible mode bit.
2957 *
2958 * If scrollbar-visible is on, the vertical scrollbar will be visible.
2959 * Otherwise it will not.
2960 *
2961 * Defaults to on.
2962 *
2963 * @param {boolean} state True to set scrollbar-visible mode, false to unset.
2964 */
2965hterm.Terminal.prototype.setScrollbarVisible = function(state) {
2966 this.scrollPort_.setScrollbarVisible(state);
2967};
Michael Kelly485ecd12014-06-09 11:41:56 -04002968
2969/**
Rob Spies49039e52014-12-17 13:40:04 -08002970 * Set the scroll wheel move multiplier. This will affect how fast the page
2971 * scrolls on mousewheel events.
2972 *
2973 * Defaults to 1.
2974 *
2975 * @param {number} multiplier.
2976 */
2977hterm.Terminal.prototype.setScrollWheelMoveMultipler = function(multiplier) {
2978 this.scrollPort_.setScrollWheelMoveMultipler(multiplier);
2979};
2980
2981/**
Michael Kelly485ecd12014-06-09 11:41:56 -04002982 * Close all web notifications created by terminal bells.
2983 */
2984hterm.Terminal.prototype.closeBellNotifications_ = function() {
2985 this.bellNotificationList_.forEach(function(n) {
2986 n.close();
2987 });
2988 this.bellNotificationList_.length = 0;
2989};