blob: 0960666ccb727b3616e4c59a9a51ebf086bcc953 [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
280 'cursor-blink': function(v) {
281 terminal.setCursorBlink(!!v);
282 },
283
Robert Gindaea2183e2014-07-17 09:51:51 -0700284 'cursor-blink-cycle': function(v) {
285 if (v instanceof Array &&
286 typeof v[0] == 'number' &&
287 typeof v[1] == 'number') {
288 terminal.cursorBlinkCycle_ = v;
289 } else if (typeof v == 'number') {
290 terminal.cursorBlinkCycle_ = [v, v];
291 } else {
292 // Fast blink indicates an error.
293 terminal.cursorBlinkCycle_ = [100, 100];
294 }
295 },
296
Robert Ginda57f03b42012-09-13 11:02:48 -0700297 'cursor-color': function(v) {
298 terminal.setCursorColor(v);
299 },
300
301 'color-palette-overrides': function(v) {
302 if (!(v == null || v instanceof Object || v instanceof Array)) {
303 console.warn('Preference color-palette-overrides is not an array or ' +
304 'object: ' + v);
305 return;
rginda9f5222b2012-03-05 11:53:28 -0800306 }
rginda9f5222b2012-03-05 11:53:28 -0800307
Robert Ginda57f03b42012-09-13 11:02:48 -0700308 lib.colors.colorPalette = lib.colors.stockColorPalette.concat();
rginda39bdf6f2012-04-10 16:50:55 -0700309
Robert Ginda57f03b42012-09-13 11:02:48 -0700310 if (v) {
311 for (var key in v) {
312 var i = parseInt(key);
313 if (isNaN(i) || i < 0 || i > 255) {
314 console.log('Invalid value in palette: ' + key + ': ' + v[key]);
315 continue;
316 }
317
318 if (v[i]) {
319 var rgb = lib.colors.normalizeCSS(v[i]);
320 if (rgb)
321 lib.colors.colorPalette[i] = rgb;
322 }
323 }
rginda30f20f62012-04-05 16:36:19 -0700324 }
rginda30f20f62012-04-05 16:36:19 -0700325
Robert Ginda57f03b42012-09-13 11:02:48 -0700326 terminal.primaryScreen_.textAttributes.resetColorPalette()
327 terminal.alternateScreen_.textAttributes.resetColorPalette();
328 },
rginda30f20f62012-04-05 16:36:19 -0700329
Robert Ginda57f03b42012-09-13 11:02:48 -0700330 'copy-on-select': function(v) {
331 terminal.copyOnSelect = !!v;
332 },
rginda9f5222b2012-03-05 11:53:28 -0800333
Rob Spies0bec09b2014-06-06 15:58:09 -0700334 'use-default-window-copy': function(v) {
335 terminal.useDefaultWindowCopy = !!v;
336 },
337
338 'clear-selection-after-copy': function(v) {
339 terminal.clearSelectionAfterCopy = !!v;
340 },
341
Robert Ginda7e5e9522014-03-14 12:23:58 -0700342 'ctrl-plus-minus-zero-zoom': function(v) {
343 terminal.keyboard.ctrlPlusMinusZeroZoom = v;
344 },
345
Robert Gindafb5a3f92014-05-13 14:12:00 -0700346 'ctrl-c-copy': function(v) {
347 terminal.keyboard.ctrlCCopy = v;
348 },
349
Leonardo Mesquita61e7c312014-01-04 12:53:12 +0100350 'ctrl-v-paste': function(v) {
351 terminal.keyboard.ctrlVPaste = v;
Rob Spiese52e1842014-07-10 15:32:51 -0700352 terminal.scrollPort_.setCtrlVPaste(v);
Leonardo Mesquita61e7c312014-01-04 12:53:12 +0100353 },
354
Masaya Suzuki273aa982014-05-31 07:25:55 +0900355 'east-asian-ambiguous-as-two-column': function(v) {
356 lib.wc.regardCjkAmbiguous = v;
357 },
358
Robert Ginda57f03b42012-09-13 11:02:48 -0700359 'enable-8-bit-control': function(v) {
360 terminal.vt.enable8BitControl = !!v;
361 },
rginda30f20f62012-04-05 16:36:19 -0700362
Robert Ginda57f03b42012-09-13 11:02:48 -0700363 'enable-bold': function(v) {
364 terminal.syncBoldSafeState();
365 },
Philip Douglass959b49d2012-05-30 13:29:29 -0400366
Robert Ginda3e278d72014-03-25 13:18:51 -0700367 'enable-bold-as-bright': function(v) {
368 terminal.primaryScreen_.textAttributes.enableBoldAsBright = !!v;
369 terminal.alternateScreen_.textAttributes.enableBoldAsBright = !!v;
370 },
371
Robert Ginda57f03b42012-09-13 11:02:48 -0700372 'enable-clipboard-write': function(v) {
373 terminal.vt.enableClipboardWrite = !!v;
374 },
Philip Douglass959b49d2012-05-30 13:29:29 -0400375
Robert Ginda3755e752013-05-31 13:34:09 -0700376 'enable-dec12': function(v) {
377 terminal.vt.enableDec12 = !!v;
378 },
379
Robert Ginda57f03b42012-09-13 11:02:48 -0700380 'font-family': function(v) {
381 terminal.syncFontFamily();
382 },
rginda30f20f62012-04-05 16:36:19 -0700383
Robert Ginda57f03b42012-09-13 11:02:48 -0700384 'font-size': function(v) {
385 terminal.setFontSize(v);
386 },
rginda9875d902012-08-20 16:21:57 -0700387
Robert Ginda57f03b42012-09-13 11:02:48 -0700388 'font-smoothing': function(v) {
389 terminal.syncFontFamily();
390 },
rgindade84e382012-04-20 15:39:31 -0700391
Robert Ginda57f03b42012-09-13 11:02:48 -0700392 'foreground-color': function(v) {
393 terminal.setForegroundColor(v);
394 },
rginda30f20f62012-04-05 16:36:19 -0700395
Robert Ginda57f03b42012-09-13 11:02:48 -0700396 'home-keys-scroll': function(v) {
397 terminal.keyboard.homeKeysScroll = v;
398 },
rginda4bba5e12012-06-20 16:15:30 -0700399
Robert Ginda57f03b42012-09-13 11:02:48 -0700400 'max-string-sequence': function(v) {
401 terminal.vt.maxStringSequence = v;
402 },
rginda11057d52012-04-25 12:29:56 -0700403
Andrew de los Reyes6af23ae2013-04-04 14:17:50 -0700404 'media-keys-are-fkeys': function(v) {
405 terminal.keyboard.mediaKeysAreFKeys = v;
406 },
407
Robert Ginda57f03b42012-09-13 11:02:48 -0700408 'meta-sends-escape': function(v) {
409 terminal.keyboard.metaSendsEscape = v;
410 },
rginda30f20f62012-04-05 16:36:19 -0700411
Robert Ginda57f03b42012-09-13 11:02:48 -0700412 'mouse-paste-button': function(v) {
413 terminal.syncMousePasteButton();
414 },
rgindaa8ba17d2012-08-15 14:41:10 -0700415
Robert Gindae76aa9f2014-03-14 12:29:12 -0700416 'page-keys-scroll': function(v) {
417 terminal.keyboard.pageKeysScroll = v;
418 },
419
Robert Ginda40932892012-12-10 17:26:40 -0800420 'pass-alt-number': function(v) {
421 if (v == null) {
422 var osx = window.navigator.userAgent.match(/Mac OS X/);
423
424 // Let Alt-1..9 pass to the browser (to control tab switching) on
425 // non-OS X systems, or if hterm is not opened in an app window.
426 v = (!osx && hterm.windowType != 'popup');
427 }
428
429 terminal.passAltNumber = v;
430 },
431
432 'pass-ctrl-number': function(v) {
433 if (v == null) {
434 var osx = window.navigator.userAgent.match(/Mac OS X/);
435
436 // Let Ctrl-1..9 pass to the browser (to control tab switching) on
437 // non-OS X systems, or if hterm is not opened in an app window.
438 v = (!osx && hterm.windowType != 'popup');
439 }
440
441 terminal.passCtrlNumber = v;
442 },
443
444 'pass-meta-number': function(v) {
445 if (v == null) {
446 var osx = window.navigator.userAgent.match(/Mac OS X/);
447
448 // Let Meta-1..9 pass to the browser (to control tab switching) on
449 // OS X systems, or if hterm is not opened in an app window.
450 v = (osx && hterm.windowType != 'popup');
451 }
452
453 terminal.passMetaNumber = v;
454 },
455
Marius Schilder77857b32014-05-14 16:21:26 -0700456 'pass-meta-v': function(v) {
Marius Schilder1a567812014-05-15 20:30:02 -0700457 terminal.keyboard.passMetaV = v;
Marius Schilder77857b32014-05-14 16:21:26 -0700458 },
459
Robert Ginda8cb7d902013-06-20 14:37:18 -0700460 'receive-encoding': function(v) {
461 if (!(/^(utf-8|raw)$/).test(v)) {
462 console.warn('Invalid value for "receive-encoding": ' + v);
463 v = 'utf-8';
464 }
465
466 terminal.vt.characterEncoding = v;
467 },
468
Robert Ginda57f03b42012-09-13 11:02:48 -0700469 'scroll-on-keystroke': function(v) {
470 terminal.scrollOnKeystroke_ = v;
471 },
rginda9f5222b2012-03-05 11:53:28 -0800472
Robert Ginda57f03b42012-09-13 11:02:48 -0700473 'scroll-on-output': function(v) {
474 terminal.scrollOnOutput_ = v;
475 },
rginda30f20f62012-04-05 16:36:19 -0700476
Robert Ginda57f03b42012-09-13 11:02:48 -0700477 'scrollbar-visible': function(v) {
478 terminal.setScrollbarVisible(v);
479 },
rginda9f5222b2012-03-05 11:53:28 -0800480
Rob Spies49039e52014-12-17 13:40:04 -0800481 'scroll-wheel-move-multiplier': function(v) {
482 terminal.setScrollWheelMoveMultipler(v);
483 },
484
Robert Ginda8cb7d902013-06-20 14:37:18 -0700485 'send-encoding': function(v) {
486 if (!(/^(utf-8|raw)$/).test(v)) {
487 console.warn('Invalid value for "send-encoding": ' + v);
488 v = 'utf-8';
489 }
490
491 terminal.keyboard.characterEncoding = v;
492 },
493
Robert Ginda57f03b42012-09-13 11:02:48 -0700494 'shift-insert-paste': function(v) {
495 terminal.keyboard.shiftInsertPaste = v;
496 },
rginda9f5222b2012-03-05 11:53:28 -0800497
Robert Gindae76aa9f2014-03-14 12:29:12 -0700498 'user-css': function(v) {
499 terminal.scrollPort_.setUserCss(v);
Robert Ginda57f03b42012-09-13 11:02:48 -0700500 }
501 });
rginda30f20f62012-04-05 16:36:19 -0700502
Robert Ginda57f03b42012-09-13 11:02:48 -0700503 this.prefs_.readStorage(function() {
rginda9f5222b2012-03-05 11:53:28 -0800504 this.prefs_.notifyAll();
Robert Ginda57f03b42012-09-13 11:02:48 -0700505
506 if (opt_callback)
507 opt_callback();
508 }.bind(this));
rginda9f5222b2012-03-05 11:53:28 -0800509};
510
Rob Spies56953412014-04-28 14:09:47 -0700511
512/**
513 * Returns the preferences manager used for configuring this terminal.
514 */
515hterm.Terminal.prototype.getPrefs = function() {
516 return this.prefs_;
517};
518
Robert Gindaa063b202014-07-21 11:08:25 -0700519/**
520 * Enable or disable bracketed paste mode.
521 */
522hterm.Terminal.prototype.setBracketedPaste = function(state) {
523 this.options_.bracketedPaste = state;
524};
Rob Spies56953412014-04-28 14:09:47 -0700525
rginda8e92a692012-05-20 19:37:20 -0700526/**
527 * Set the color for the cursor.
528 *
529 * If you want this setting to persist, set it through prefs_, rather than
530 * with this method.
531 */
532hterm.Terminal.prototype.setCursorColor = function(color) {
Robert Ginda830583c2013-08-07 13:20:46 -0700533 this.cursorColor_ = color;
rginda8e92a692012-05-20 19:37:20 -0700534 this.cursorNode_.style.backgroundColor = color;
535 this.cursorNode_.style.borderColor = color;
536};
537
538/**
539 * Return the current cursor color as a string.
540 */
541hterm.Terminal.prototype.getCursorColor = function() {
Robert Ginda830583c2013-08-07 13:20:46 -0700542 return this.cursorColor_;
rginda8e92a692012-05-20 19:37:20 -0700543};
544
545/**
rgindad5613292012-06-19 15:40:37 -0700546 * Enable or disable mouse based text selection in the terminal.
547 */
548hterm.Terminal.prototype.setSelectionEnabled = function(state) {
549 this.enableMouseDragScroll = state;
rgindad5613292012-06-19 15:40:37 -0700550};
551
552/**
rginda8e92a692012-05-20 19:37:20 -0700553 * Set the background color.
554 *
555 * If you want this setting to persist, set it through prefs_, rather than
556 * with this method.
557 */
558hterm.Terminal.prototype.setBackgroundColor = function(color) {
rgindacbbd7482012-06-13 15:06:16 -0700559 this.backgroundColor_ = lib.colors.normalizeCSS(color);
Robert Ginda57f03b42012-09-13 11:02:48 -0700560 this.primaryScreen_.textAttributes.setDefaults(
561 this.foregroundColor_, this.backgroundColor_);
562 this.alternateScreen_.textAttributes.setDefaults(
563 this.foregroundColor_, this.backgroundColor_);
rginda8e92a692012-05-20 19:37:20 -0700564 this.scrollPort_.setBackgroundColor(color);
565};
566
rginda9f5222b2012-03-05 11:53:28 -0800567/**
568 * Return the current terminal background color.
569 *
570 * Intended for use by other classes, so we don't have to expose the entire
571 * prefs_ object.
572 */
573hterm.Terminal.prototype.getBackgroundColor = function() {
rginda8e92a692012-05-20 19:37:20 -0700574 return this.backgroundColor_;
575};
576
577/**
578 * Set the foreground color.
579 *
580 * If you want this setting to persist, set it through prefs_, rather than
581 * with this method.
582 */
583hterm.Terminal.prototype.setForegroundColor = function(color) {
rgindacbbd7482012-06-13 15:06:16 -0700584 this.foregroundColor_ = lib.colors.normalizeCSS(color);
Robert Ginda57f03b42012-09-13 11:02:48 -0700585 this.primaryScreen_.textAttributes.setDefaults(
586 this.foregroundColor_, this.backgroundColor_);
587 this.alternateScreen_.textAttributes.setDefaults(
588 this.foregroundColor_, this.backgroundColor_);
rginda8e92a692012-05-20 19:37:20 -0700589 this.scrollPort_.setForegroundColor(color);
rginda9f5222b2012-03-05 11:53:28 -0800590};
591
592/**
593 * Return the current terminal foreground color.
594 *
595 * Intended for use by other classes, so we don't have to expose the entire
596 * prefs_ object.
597 */
598hterm.Terminal.prototype.getForegroundColor = function() {
rginda8e92a692012-05-20 19:37:20 -0700599 return this.foregroundColor_;
rginda9f5222b2012-03-05 11:53:28 -0800600};
601
602/**
rginda87b86462011-12-14 13:48:03 -0800603 * Create a new instance of a terminal command and run it with a given
604 * argument string.
605 *
606 * @param {function} commandClass The constructor for a terminal command.
607 * @param {string} argString The argument string to pass to the command.
608 */
609hterm.Terminal.prototype.runCommandClass = function(commandClass, argString) {
rgindaf522ce02012-04-17 17:49:17 -0700610 var environment = this.prefs_.get('environment');
611 if (typeof environment != 'object' || environment == null)
612 environment = {};
613
rginda87b86462011-12-14 13:48:03 -0800614 var self = this;
615 this.command = new commandClass(
616 { argString: argString || '',
617 io: this.io.push(),
rgindaf522ce02012-04-17 17:49:17 -0700618 environment: environment,
rginda87b86462011-12-14 13:48:03 -0800619 onExit: function(code) {
620 self.io.pop();
rgindafeaf3142012-01-31 15:14:20 -0800621 self.uninstallKeyboard();
rginda9875d902012-08-20 16:21:57 -0700622 if (self.prefs_.get('close-on-exit'))
623 window.close();
rginda87b86462011-12-14 13:48:03 -0800624 }
625 });
626
rgindafeaf3142012-01-31 15:14:20 -0800627 this.installKeyboard();
rginda87b86462011-12-14 13:48:03 -0800628 this.command.run();
629};
630
631/**
rgindafeaf3142012-01-31 15:14:20 -0800632 * Returns true if the current screen is the primary screen, false otherwise.
633 */
634hterm.Terminal.prototype.isPrimaryScreen = function() {
rgindaf522ce02012-04-17 17:49:17 -0700635 return this.screen_ == this.primaryScreen_;
rgindafeaf3142012-01-31 15:14:20 -0800636};
637
638/**
639 * Install the keyboard handler for this terminal.
640 *
641 * This will prevent the browser from seeing any keystrokes sent to the
642 * terminal.
643 */
644hterm.Terminal.prototype.installKeyboard = function() {
Rob Spies06533ba2014-04-24 11:20:37 -0700645 this.keyboard.installKeyboard(this.scrollPort_.getDocument().body);
rgindafeaf3142012-01-31 15:14:20 -0800646}
647
648/**
649 * Uninstall the keyboard handler for this terminal.
650 */
651hterm.Terminal.prototype.uninstallKeyboard = function() {
652 this.keyboard.installKeyboard(null);
653}
654
655/**
rginda35c456b2012-02-09 17:29:05 -0800656 * Set the font size for this terminal.
rginda9f5222b2012-03-05 11:53:28 -0800657 *
658 * Call setFontSize(0) to reset to the default font size.
659 *
660 * This function does not modify the font-size preference.
661 *
662 * @param {number} px The desired font size, in pixels.
rginda35c456b2012-02-09 17:29:05 -0800663 */
664hterm.Terminal.prototype.setFontSize = function(px) {
rginda9f5222b2012-03-05 11:53:28 -0800665 if (px === 0)
666 px = this.prefs_.get('font-size');
667
rginda35c456b2012-02-09 17:29:05 -0800668 this.scrollPort_.setFontSize(px);
Ricky Liang48f05cb2013-12-31 23:35:29 +0800669 if (this.wcCssRule_) {
670 this.wcCssRule_.style.width = this.scrollPort_.characterSize.width * 2 +
671 'px';
672 }
rginda35c456b2012-02-09 17:29:05 -0800673};
674
675/**
676 * Get the current font size.
677 */
678hterm.Terminal.prototype.getFontSize = function() {
679 return this.scrollPort_.getFontSize();
680};
681
682/**
rginda8e92a692012-05-20 19:37:20 -0700683 * Get the current font family.
684 */
685hterm.Terminal.prototype.getFontFamily = function() {
686 return this.scrollPort_.getFontFamily();
687};
688
689/**
rginda35c456b2012-02-09 17:29:05 -0800690 * Set the CSS "font-family" for this terminal.
691 */
rginda9f5222b2012-03-05 11:53:28 -0800692hterm.Terminal.prototype.syncFontFamily = function() {
693 this.scrollPort_.setFontFamily(this.prefs_.get('font-family'),
694 this.prefs_.get('font-smoothing'));
695 this.syncBoldSafeState();
696};
697
rginda4bba5e12012-06-20 16:15:30 -0700698/**
699 * Set this.mousePasteButton based on the mouse-paste-button pref,
700 * autodetecting if necessary.
701 */
702hterm.Terminal.prototype.syncMousePasteButton = function() {
703 var button = this.prefs_.get('mouse-paste-button');
704 if (typeof button == 'number') {
705 this.mousePasteButton = button;
706 return;
707 }
708
709 var ary = navigator.userAgent.match(/\(X11;\s+(\S+)/);
710 if (!ary || ary[2] == 'CrOS') {
711 this.mousePasteButton = 2;
712 } else {
713 this.mousePasteButton = 3;
714 }
715};
716
717/**
718 * Enable or disable bold based on the enable-bold pref, autodetecting if
719 * necessary.
720 */
rginda9f5222b2012-03-05 11:53:28 -0800721hterm.Terminal.prototype.syncBoldSafeState = function() {
722 var enableBold = this.prefs_.get('enable-bold');
723 if (enableBold !== null) {
Robert Gindaed016262012-10-26 16:27:09 -0700724 this.primaryScreen_.textAttributes.enableBold = enableBold;
725 this.alternateScreen_.textAttributes.enableBold = enableBold;
rginda9f5222b2012-03-05 11:53:28 -0800726 return;
727 }
728
rgindaf7521392012-02-28 17:20:34 -0800729 var normalSize = this.scrollPort_.measureCharacterSize();
730 var boldSize = this.scrollPort_.measureCharacterSize('bold');
731
732 var isBoldSafe = normalSize.equals(boldSize);
rgindaf7521392012-02-28 17:20:34 -0800733 if (!isBoldSafe) {
734 console.warn('Bold characters disabled: Size of bold weight differs ' +
rgindac9759de2012-03-19 13:21:41 -0700735 'from normal. Font family is: ' +
736 this.scrollPort_.getFontFamily());
rgindaf7521392012-02-28 17:20:34 -0800737 }
rginda9f5222b2012-03-05 11:53:28 -0800738
Robert Gindaed016262012-10-26 16:27:09 -0700739 this.primaryScreen_.textAttributes.enableBold = isBoldSafe;
740 this.alternateScreen_.textAttributes.enableBold = isBoldSafe;
rginda35c456b2012-02-09 17:29:05 -0800741};
742
743/**
rginda87b86462011-12-14 13:48:03 -0800744 * Return a copy of the current cursor position.
745 *
746 * @return {hterm.RowCol} The RowCol object representing the current position.
747 */
748hterm.Terminal.prototype.saveCursor = function() {
749 return this.screen_.cursorPosition.clone();
750};
751
rgindaa19afe22012-01-25 15:40:22 -0800752hterm.Terminal.prototype.getTextAttributes = function() {
753 return this.screen_.textAttributes;
754};
755
rginda1a09aa02012-06-18 21:11:25 -0700756hterm.Terminal.prototype.setTextAttributes = function(textAttributes) {
757 this.screen_.textAttributes = textAttributes;
758};
759
rginda87b86462011-12-14 13:48:03 -0800760/**
rgindaf522ce02012-04-17 17:49:17 -0700761 * Return the current browser zoom factor applied to the terminal.
762 *
763 * @return {number} The current browser zoom factor.
764 */
765hterm.Terminal.prototype.getZoomFactor = function() {
766 return this.scrollPort_.characterSize.zoomFactor;
767};
768
769/**
rginda9846e2f2012-01-27 13:53:33 -0800770 * Change the title of this terminal's window.
771 */
772hterm.Terminal.prototype.setWindowTitle = function(title) {
rgindafeaf3142012-01-31 15:14:20 -0800773 window.document.title = title;
rginda9846e2f2012-01-27 13:53:33 -0800774};
775
776/**
rginda87b86462011-12-14 13:48:03 -0800777 * Restore a previously saved cursor position.
778 *
779 * @param {hterm.RowCol} cursor The position to restore.
780 */
781hterm.Terminal.prototype.restoreCursor = function(cursor) {
rgindacbbd7482012-06-13 15:06:16 -0700782 var row = lib.f.clamp(cursor.row, 0, this.screenSize.height - 1);
783 var column = lib.f.clamp(cursor.column, 0, this.screenSize.width - 1);
rginda35c456b2012-02-09 17:29:05 -0800784 this.screen_.setCursorPosition(row, column);
785 if (cursor.column > column ||
786 cursor.column == column && cursor.overflow) {
787 this.screen_.cursorPosition.overflow = true;
788 }
rginda87b86462011-12-14 13:48:03 -0800789};
790
791/**
David Benjamin54e8bf62012-06-01 22:31:40 -0400792 * Clear the cursor's overflow flag.
793 */
794hterm.Terminal.prototype.clearCursorOverflow = function() {
795 this.screen_.cursorPosition.overflow = false;
796};
797
798/**
Robert Ginda830583c2013-08-07 13:20:46 -0700799 * Sets the cursor shape
800 */
801hterm.Terminal.prototype.setCursorShape = function(shape) {
802 this.cursorShape_ = shape;
Robert Gindafb1be6a2013-12-11 11:56:22 -0800803 this.restyleCursor_();
Robert Ginda830583c2013-08-07 13:20:46 -0700804}
805
806/**
807 * Get the cursor shape
808 */
809hterm.Terminal.prototype.getCursorShape = function() {
810 return this.cursorShape_;
811}
812
813/**
rginda87b86462011-12-14 13:48:03 -0800814 * Set the width of the terminal, resizing the UI to match.
815 */
816hterm.Terminal.prototype.setWidth = function(columnCount) {
rgindaf0090c92012-02-10 14:58:52 -0800817 if (columnCount == null) {
818 this.div_.style.width = '100%';
819 return;
820 }
821
Robert Ginda26806d12014-07-24 13:44:07 -0700822 this.div_.style.width = Math.ceil(
823 this.scrollPort_.characterSize.width *
824 columnCount + this.scrollPort_.currentScrollbarWidthPx) + 'px';
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400825 this.realizeSize_(columnCount, this.screenSize.height);
rgindac9bc5502012-01-18 11:48:44 -0800826 this.scheduleSyncCursorPosition_();
827};
rginda87b86462011-12-14 13:48:03 -0800828
rgindac9bc5502012-01-18 11:48:44 -0800829/**
rginda35c456b2012-02-09 17:29:05 -0800830 * Set the height of the terminal, resizing the UI to match.
831 */
832hterm.Terminal.prototype.setHeight = function(rowCount) {
rgindaf0090c92012-02-10 14:58:52 -0800833 if (rowCount == null) {
834 this.div_.style.height = '100%';
835 return;
836 }
837
rginda35c456b2012-02-09 17:29:05 -0800838 this.div_.style.height =
rginda30f20f62012-04-05 16:36:19 -0700839 this.scrollPort_.characterSize.height * rowCount + 'px';
rginda35c456b2012-02-09 17:29:05 -0800840 this.realizeSize_(this.screenSize.width, rowCount);
841 this.scheduleSyncCursorPosition_();
842};
843
844/**
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400845 * Deal with terminal size changes.
846 *
847 */
848hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) {
849 if (columnCount != this.screenSize.width)
850 this.realizeWidth_(columnCount);
851
852 if (rowCount != this.screenSize.height)
853 this.realizeHeight_(rowCount);
854
855 // Send new terminal size to plugin.
Robert Gindae81427f2013-05-24 10:34:46 -0700856 this.io.onTerminalResize_(columnCount, rowCount);
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +0400857};
858
859/**
rgindac9bc5502012-01-18 11:48:44 -0800860 * Deal with terminal width changes.
861 *
862 * This function does what needs to be done when the terminal width changes
863 * out from under us. It happens here rather than in onResize_() because this
864 * code may need to run synchronously to handle programmatic changes of
865 * terminal width.
866 *
867 * Relying on the browser to send us an async resize event means we may not be
868 * in the correct state yet when the next escape sequence hits.
869 */
870hterm.Terminal.prototype.realizeWidth_ = function(columnCount) {
Robert Ginda4e83f3a2012-09-04 15:25:25 -0700871 if (columnCount <= 0)
872 throw new Error('Attempt to realize bad width: ' + columnCount);
873
rgindac9bc5502012-01-18 11:48:44 -0800874 var deltaColumns = columnCount - this.screen_.getWidth();
875
rginda87b86462011-12-14 13:48:03 -0800876 this.screenSize.width = columnCount;
877 this.screen_.setColumnCount(columnCount);
rgindac9bc5502012-01-18 11:48:44 -0800878
879 if (deltaColumns > 0) {
David Benjamin66e954d2012-05-05 21:08:12 -0400880 if (this.defaultTabStops)
881 this.setDefaultTabStops(this.screenSize.width - deltaColumns);
rgindac9bc5502012-01-18 11:48:44 -0800882 } else {
883 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
David Benjamin66e954d2012-05-05 21:08:12 -0400884 if (this.tabStops_[i] < columnCount)
rgindac9bc5502012-01-18 11:48:44 -0800885 break;
886
887 this.tabStops_.pop();
888 }
889 }
890
891 this.screen_.setColumnCount(this.screenSize.width);
892};
893
894/**
895 * Deal with terminal height changes.
896 *
897 * This function does what needs to be done when the terminal height changes
898 * out from under us. It happens here rather than in onResize_() because this
899 * code may need to run synchronously to handle programmatic changes of
900 * terminal height.
901 *
902 * Relying on the browser to send us an async resize event means we may not be
903 * in the correct state yet when the next escape sequence hits.
904 */
905hterm.Terminal.prototype.realizeHeight_ = function(rowCount) {
Robert Ginda4e83f3a2012-09-04 15:25:25 -0700906 if (rowCount <= 0)
907 throw new Error('Attempt to realize bad height: ' + rowCount);
908
rgindac9bc5502012-01-18 11:48:44 -0800909 var deltaRows = rowCount - this.screen_.getHeight();
910
911 this.screenSize.height = rowCount;
912
913 var cursor = this.saveCursor();
914
915 if (deltaRows < 0) {
916 // Screen got smaller.
917 deltaRows *= -1;
918 while (deltaRows) {
919 var lastRow = this.getRowCount() - 1;
920 if (lastRow - this.scrollbackRows_.length == cursor.row)
921 break;
922
923 if (this.getRowText(lastRow))
924 break;
925
926 this.screen_.popRow();
927 deltaRows--;
928 }
929
930 var ary = this.screen_.shiftRows(deltaRows);
931 this.scrollbackRows_.push.apply(this.scrollbackRows_, ary);
932
933 // We just removed rows from the top of the screen, we need to update
934 // the cursor to match.
rginda35c456b2012-02-09 17:29:05 -0800935 cursor.row = Math.max(cursor.row - deltaRows, 0);
rgindac9bc5502012-01-18 11:48:44 -0800936 } else if (deltaRows > 0) {
937 // Screen got larger.
938
939 if (deltaRows <= this.scrollbackRows_.length) {
940 var scrollbackCount = Math.min(deltaRows, this.scrollbackRows_.length);
941 var rows = this.scrollbackRows_.splice(
942 this.scrollbackRows_.length - scrollbackCount, scrollbackCount);
943 this.screen_.unshiftRows(rows);
944 deltaRows -= scrollbackCount;
945 cursor.row += scrollbackCount;
946 }
947
948 if (deltaRows)
949 this.appendRows_(deltaRows);
950 }
951
rginda35c456b2012-02-09 17:29:05 -0800952 this.setVTScrollRegion(null, null);
rgindac9bc5502012-01-18 11:48:44 -0800953 this.restoreCursor(cursor);
rginda87b86462011-12-14 13:48:03 -0800954};
955
956/**
957 * Scroll the terminal to the top of the scrollback buffer.
958 */
959hterm.Terminal.prototype.scrollHome = function() {
960 this.scrollPort_.scrollRowToTop(0);
961};
962
963/**
964 * Scroll the terminal to the end.
965 */
966hterm.Terminal.prototype.scrollEnd = function() {
967 this.scrollPort_.scrollRowToBottom(this.getRowCount());
968};
969
970/**
971 * Scroll the terminal one page up (minus one line) relative to the current
972 * position.
973 */
974hterm.Terminal.prototype.scrollPageUp = function() {
975 var i = this.scrollPort_.getTopRowIndex();
976 this.scrollPort_.scrollRowToTop(i - this.screenSize.height + 1);
977};
978
979/**
980 * Scroll the terminal one page down (minus one line) relative to the current
981 * position.
982 */
983hterm.Terminal.prototype.scrollPageDown = function() {
984 var i = this.scrollPort_.getTopRowIndex();
985 this.scrollPort_.scrollRowToTop(i + this.screenSize.height - 1);
rginda8ba33642011-12-14 12:31:31 -0800986};
987
rgindac9bc5502012-01-18 11:48:44 -0800988/**
Robert Ginda40932892012-12-10 17:26:40 -0800989 * Clear primary screen, secondary screen, and the scrollback buffer.
990 */
991hterm.Terminal.prototype.wipeContents = function() {
992 this.scrollbackRows_.length = 0;
993 this.scrollPort_.resetCache();
994
995 [this.primaryScreen_, this.alternateScreen_].forEach(function(screen) {
996 var bottom = screen.getHeight();
997 if (bottom > 0) {
998 this.renumberRows_(0, bottom);
999 this.clearHome(screen);
1000 }
1001 }.bind(this));
1002
1003 this.syncCursorPosition_();
Andrew de los Reyes68e07802013-04-04 15:38:55 -07001004 this.scrollPort_.invalidate();
Robert Ginda40932892012-12-10 17:26:40 -08001005};
1006
1007/**
rgindac9bc5502012-01-18 11:48:44 -08001008 * Full terminal reset.
1009 */
rginda87b86462011-12-14 13:48:03 -08001010hterm.Terminal.prototype.reset = function() {
rgindac9bc5502012-01-18 11:48:44 -08001011 this.clearAllTabStops();
1012 this.setDefaultTabStops();
rginda9ea433c2012-03-16 11:57:00 -07001013
1014 this.clearHome(this.primaryScreen_);
1015 this.primaryScreen_.textAttributes.reset();
1016
1017 this.clearHome(this.alternateScreen_);
1018 this.alternateScreen_.textAttributes.reset();
1019
rgindab8bc8932012-04-27 12:45:03 -07001020 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
1021
Robert Ginda92e18102013-03-14 13:56:37 -07001022 this.vt.reset();
1023
rgindac9bc5502012-01-18 11:48:44 -08001024 this.softReset();
rginda87b86462011-12-14 13:48:03 -08001025};
1026
rgindac9bc5502012-01-18 11:48:44 -08001027/**
1028 * Soft terminal reset.
rgindab8bc8932012-04-27 12:45:03 -07001029 *
1030 * Perform a soft reset to the default values listed in
1031 * http://www.vt100.net/docs/vt510-rm/DECSTR#T5-9
rgindac9bc5502012-01-18 11:48:44 -08001032 */
rginda0f5c0292012-01-13 11:00:13 -08001033hterm.Terminal.prototype.softReset = function() {
rgindab8bc8932012-04-27 12:45:03 -07001034 // Reset terminal options to their default values.
rgindac9bc5502012-01-18 11:48:44 -08001035 this.options_ = new hterm.Options();
rgindaf522ce02012-04-17 17:49:17 -07001036
rgindab8bc8932012-04-27 12:45:03 -07001037 // Xterm also resets the color palette on soft reset, even though it doesn't
1038 // seem to be documented anywhere.
rgindaf522ce02012-04-17 17:49:17 -07001039 this.primaryScreen_.textAttributes.resetColorPalette();
1040 this.alternateScreen_.textAttributes.resetColorPalette();
1041
rgindab8bc8932012-04-27 12:45:03 -07001042 // The xterm man page explicitly says this will happen on soft reset.
1043 this.setVTScrollRegion(null, null);
1044
1045 // Xterm also shows the cursor on soft reset, but does not alter the blink
1046 // state.
rgindaa19afe22012-01-25 15:40:22 -08001047 this.setCursorVisible(true);
rginda0f5c0292012-01-13 11:00:13 -08001048};
1049
rgindac9bc5502012-01-18 11:48:44 -08001050/**
1051 * Move the cursor forward to the next tab stop, or to the last column
1052 * if no more tab stops are set.
1053 */
1054hterm.Terminal.prototype.forwardTabStop = function() {
1055 var column = this.screen_.cursorPosition.column;
1056
1057 for (var i = 0; i < this.tabStops_.length; i++) {
1058 if (this.tabStops_[i] > column) {
1059 this.setCursorColumn(this.tabStops_[i]);
1060 return;
1061 }
1062 }
1063
David Benjamin66e954d2012-05-05 21:08:12 -04001064 // xterm does not clear the overflow flag on HT or CHT.
1065 var overflow = this.screen_.cursorPosition.overflow;
rgindac9bc5502012-01-18 11:48:44 -08001066 this.setCursorColumn(this.screenSize.width - 1);
David Benjamin66e954d2012-05-05 21:08:12 -04001067 this.screen_.cursorPosition.overflow = overflow;
rginda0f5c0292012-01-13 11:00:13 -08001068};
1069
rgindac9bc5502012-01-18 11:48:44 -08001070/**
1071 * Move the cursor backward to the previous tab stop, or to the first column
1072 * if no previous tab stops are set.
1073 */
1074hterm.Terminal.prototype.backwardTabStop = function() {
1075 var column = this.screen_.cursorPosition.column;
1076
1077 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
1078 if (this.tabStops_[i] < column) {
1079 this.setCursorColumn(this.tabStops_[i]);
1080 return;
1081 }
1082 }
1083
1084 this.setCursorColumn(1);
rginda0f5c0292012-01-13 11:00:13 -08001085};
1086
rgindac9bc5502012-01-18 11:48:44 -08001087/**
1088 * Set a tab stop at the given column.
1089 *
1090 * @param {int} column Zero based column.
1091 */
1092hterm.Terminal.prototype.setTabStop = function(column) {
1093 for (var i = this.tabStops_.length - 1; i >= 0; i--) {
1094 if (this.tabStops_[i] == column)
1095 return;
1096
1097 if (this.tabStops_[i] < column) {
1098 this.tabStops_.splice(i + 1, 0, column);
1099 return;
1100 }
1101 }
1102
1103 this.tabStops_.splice(0, 0, column);
rginda87b86462011-12-14 13:48:03 -08001104};
1105
rgindac9bc5502012-01-18 11:48:44 -08001106/**
1107 * Clear the tab stop at the current cursor position.
1108 *
1109 * No effect if there is no tab stop at the current cursor position.
1110 */
1111hterm.Terminal.prototype.clearTabStopAtCursor = function() {
1112 var column = this.screen_.cursorPosition.column;
1113
1114 var i = this.tabStops_.indexOf(column);
1115 if (i == -1)
1116 return;
1117
1118 this.tabStops_.splice(i, 1);
1119};
1120
1121/**
1122 * Clear all tab stops.
1123 */
1124hterm.Terminal.prototype.clearAllTabStops = function() {
1125 this.tabStops_.length = 0;
David Benjamin66e954d2012-05-05 21:08:12 -04001126 this.defaultTabStops = false;
rgindac9bc5502012-01-18 11:48:44 -08001127};
1128
1129/**
1130 * Set up the default tab stops, starting from a given column.
1131 *
1132 * This sets a tabstop every (column % this.tabWidth) column, starting
David Benjamin66e954d2012-05-05 21:08:12 -04001133 * from the specified column, or 0 if no column is provided. It also flags
1134 * future resizes to set them up.
rgindac9bc5502012-01-18 11:48:44 -08001135 *
1136 * This does not clear the existing tab stops first, use clearAllTabStops
1137 * for that.
1138 *
1139 * @param {int} opt_start Optional starting zero based starting column, useful
1140 * for filling out missing tab stops when the terminal is resized.
1141 */
1142hterm.Terminal.prototype.setDefaultTabStops = function(opt_start) {
1143 var start = opt_start || 0;
1144 var w = this.tabWidth;
David Benjamin66e954d2012-05-05 21:08:12 -04001145 // Round start up to a default tab stop.
1146 start = start - 1 - ((start - 1) % w) + w;
1147 for (var i = start; i < this.screenSize.width; i += w) {
1148 this.setTabStop(i);
rgindac9bc5502012-01-18 11:48:44 -08001149 }
David Benjamin66e954d2012-05-05 21:08:12 -04001150
1151 this.defaultTabStops = true;
rginda87b86462011-12-14 13:48:03 -08001152};
1153
rginda6d397402012-01-17 10:58:29 -08001154/**
rginda8ba33642011-12-14 12:31:31 -08001155 * Interpret a sequence of characters.
1156 *
1157 * Incomplete escape sequences are buffered until the next call.
1158 *
1159 * @param {string} str Sequence of characters to interpret or pass through.
1160 */
1161hterm.Terminal.prototype.interpret = function(str) {
rginda0f5c0292012-01-13 11:00:13 -08001162 this.vt.interpret(str);
rginda8ba33642011-12-14 12:31:31 -08001163 this.scheduleSyncCursorPosition_();
1164};
1165
1166/**
1167 * Take over the given DIV for use as the terminal display.
1168 *
1169 * @param {HTMLDivElement} div The div to use as the terminal display.
1170 */
1171hterm.Terminal.prototype.decorate = function(div) {
rginda87b86462011-12-14 13:48:03 -08001172 this.div_ = div;
1173
rginda8ba33642011-12-14 12:31:31 -08001174 this.scrollPort_.decorate(div);
rginda30f20f62012-04-05 16:36:19 -07001175 this.scrollPort_.setBackgroundImage(this.prefs_.get('background-image'));
Philip Douglass959b49d2012-05-30 13:29:29 -04001176 this.scrollPort_.setBackgroundSize(this.prefs_.get('background-size'));
1177 this.scrollPort_.setBackgroundPosition(
1178 this.prefs_.get('background-position'));
Robert Gindae76aa9f2014-03-14 12:29:12 -07001179 this.scrollPort_.setUserCss(this.prefs_.get('user-css'));
rginda30f20f62012-04-05 16:36:19 -07001180
rginda0918b652012-04-04 11:26:24 -07001181 this.div_.focus = this.focus.bind(this);
rgindaf7521392012-02-28 17:20:34 -08001182
rginda9f5222b2012-03-05 11:53:28 -08001183 this.setFontSize(this.prefs_.get('font-size'));
1184 this.syncFontFamily();
rgindaa19afe22012-01-25 15:40:22 -08001185
David Reveman8f552492012-03-28 12:18:41 -04001186 this.setScrollbarVisible(this.prefs_.get('scrollbar-visible'));
Rob Spies49039e52014-12-17 13:40:04 -08001187 this.setScrollWheelMoveMultipler(
1188 this.prefs_.get('scroll-wheel-move-multiplier'));
David Reveman8f552492012-03-28 12:18:41 -04001189
rginda8ba33642011-12-14 12:31:31 -08001190 this.document_ = this.scrollPort_.getDocument();
1191
rginda4bba5e12012-06-20 16:15:30 -07001192 this.document_.body.oncontextmenu = function() { return false };
1193
1194 var onMouse = this.onMouse_.bind(this);
Toni Barzic0bfa8922013-11-22 11:18:35 -08001195 var screenNode = this.scrollPort_.getScreenNode();
1196 screenNode.addEventListener('mousedown', onMouse);
1197 screenNode.addEventListener('mouseup', onMouse);
1198 screenNode.addEventListener('mousemove', onMouse);
rginda4bba5e12012-06-20 16:15:30 -07001199 this.scrollPort_.onScrollWheel = onMouse;
1200
Toni Barzic0bfa8922013-11-22 11:18:35 -08001201 screenNode.addEventListener(
rginda8e92a692012-05-20 19:37:20 -07001202 'focus', this.onFocusChange_.bind(this, true));
Rob Spies06533ba2014-04-24 11:20:37 -07001203 // Listen for mousedown events on the screenNode as in FF the focus
1204 // events don't bubble.
1205 screenNode.addEventListener('mousedown', function() {
1206 setTimeout(this.onFocusChange_.bind(this, true));
1207 }.bind(this));
1208
Toni Barzic0bfa8922013-11-22 11:18:35 -08001209 screenNode.addEventListener(
rginda8e92a692012-05-20 19:37:20 -07001210 'blur', this.onFocusChange_.bind(this, false));
1211
1212 var style = this.document_.createElement('style');
1213 style.textContent =
1214 ('.cursor-node[focus="false"] {' +
1215 ' box-sizing: border-box;' +
1216 ' background-color: transparent !important;' +
1217 ' border-width: 2px;' +
1218 ' border-style: solid;' +
Ricky Liang48f05cb2013-12-31 23:35:29 +08001219 '}' +
1220 '.wc-node {' +
1221 ' display: inline-block;' +
1222 ' text-align: center;' +
1223 ' width: ' + this.scrollPort_.characterSize.width * 2 + 'px;' +
rginda8e92a692012-05-20 19:37:20 -07001224 '}');
1225 this.document_.head.appendChild(style);
1226
Ricky Liang48f05cb2013-12-31 23:35:29 +08001227 var styleSheets = this.document_.styleSheets;
1228 var cssRules = styleSheets[styleSheets.length - 1].cssRules;
1229 this.wcCssRule_ = cssRules[cssRules.length - 1];
1230
rginda8ba33642011-12-14 12:31:31 -08001231 this.cursorNode_ = this.document_.createElement('div');
rginda8e92a692012-05-20 19:37:20 -07001232 this.cursorNode_.className = 'cursor-node';
rginda8ba33642011-12-14 12:31:31 -08001233 this.cursorNode_.style.cssText =
1234 ('position: absolute;' +
rginda87b86462011-12-14 13:48:03 -08001235 'top: -99px;' +
1236 'display: block;' +
rginda35c456b2012-02-09 17:29:05 -08001237 'width: ' + this.scrollPort_.characterSize.width + 'px;' +
1238 'height: ' + this.scrollPort_.characterSize.height + 'px;' +
Rob Spies06533ba2014-04-24 11:20:37 -07001239 '-webkit-transition: opacity, background-color 100ms linear;' +
1240 '-moz-transition: opacity, background-color 100ms linear;');
Robert Gindafb1be6a2013-12-11 11:56:22 -08001241
rginda8e92a692012-05-20 19:37:20 -07001242 this.setCursorColor(this.prefs_.get('cursor-color'));
Robert Gindafb1be6a2013-12-11 11:56:22 -08001243 this.setCursorBlink(!!this.prefs_.get('cursor-blink'));
1244 this.restyleCursor_();
rgindad5613292012-06-19 15:40:37 -07001245
rginda8ba33642011-12-14 12:31:31 -08001246 this.document_.body.appendChild(this.cursorNode_);
1247
rgindad5613292012-06-19 15:40:37 -07001248 // When 'enableMouseDragScroll' is off we reposition this element directly
1249 // under the mouse cursor after a click. This makes Chrome associate
1250 // subsequent mousemove events with the scroll-blocker. Since the
1251 // scroll-blocker is a peer (not a child) of the scrollport, the mousemove
1252 // events do not cause the scrollport to scroll.
1253 //
1254 // It's a hack, but it's the cleanest way I could find.
1255 this.scrollBlockerNode_ = this.document_.createElement('div');
1256 this.scrollBlockerNode_.style.cssText =
1257 ('position: absolute;' +
1258 'top: -99px;' +
1259 'display: block;' +
1260 'width: 10px;' +
1261 'height: 10px;');
1262 this.document_.body.appendChild(this.scrollBlockerNode_);
1263
1264 var onMouse = this.onMouse_.bind(this);
1265 this.scrollPort_.onScrollWheel = onMouse;
1266 ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick',
1267 ].forEach(function(event) {
1268 this.scrollBlockerNode_.addEventListener(event, onMouse);
1269 this.cursorNode_.addEventListener(event, onMouse);
1270 this.document_.addEventListener(event, onMouse);
1271 }.bind(this));
1272
1273 this.cursorNode_.addEventListener('mousedown', function() {
1274 setTimeout(this.focus.bind(this));
1275 }.bind(this));
1276
rginda8ba33642011-12-14 12:31:31 -08001277 this.setReverseVideo(false);
rginda87b86462011-12-14 13:48:03 -08001278
rginda87b86462011-12-14 13:48:03 -08001279 this.scrollPort_.focus();
rginda6d397402012-01-17 10:58:29 -08001280 this.scrollPort_.scheduleRedraw();
rginda87b86462011-12-14 13:48:03 -08001281};
1282
rginda0918b652012-04-04 11:26:24 -07001283/**
1284 * Return the HTML document that contains the terminal DOM nodes.
1285 */
rginda87b86462011-12-14 13:48:03 -08001286hterm.Terminal.prototype.getDocument = function() {
1287 return this.document_;
rginda8ba33642011-12-14 12:31:31 -08001288};
1289
1290/**
rginda0918b652012-04-04 11:26:24 -07001291 * Focus the terminal.
1292 */
1293hterm.Terminal.prototype.focus = function() {
1294 this.scrollPort_.focus();
1295};
1296
1297/**
rginda8ba33642011-12-14 12:31:31 -08001298 * Return the HTML Element for a given row index.
1299 *
1300 * This is a method from the RowProvider interface. The ScrollPort uses
1301 * it to fetch rows on demand as they are scrolled into view.
1302 *
1303 * TODO(rginda): Consider saving scrollback rows as (HTML source, text content)
1304 * pairs to conserve memory.
1305 *
1306 * @param {integer} index The zero-based row index, measured relative to the
1307 * start of the scrollback buffer. On-screen rows will always have the
1308 * largest indicies.
1309 * @return {HTMLElement} The 'x-row' element containing for the requested row.
1310 */
1311hterm.Terminal.prototype.getRowNode = function(index) {
1312 if (index < this.scrollbackRows_.length)
1313 return this.scrollbackRows_[index];
1314
1315 var screenIndex = index - this.scrollbackRows_.length;
1316 return this.screen_.rowsArray[screenIndex];
1317};
1318
1319/**
1320 * Return the text content for a given range of rows.
1321 *
1322 * This is a method from the RowProvider interface. The ScrollPort uses
1323 * it to fetch text content on demand when the user attempts to copy their
1324 * selection to the clipboard.
1325 *
1326 * @param {integer} start The zero-based row index to start from, measured
1327 * relative to the start of the scrollback buffer. On-screen rows will
1328 * always have the largest indicies.
1329 * @param {integer} end The zero-based row index to end on, measured
1330 * relative to the start of the scrollback buffer.
1331 * @return {string} A single string containing the text value of the range of
1332 * rows. Lines will be newline delimited, with no trailing newline.
1333 */
1334hterm.Terminal.prototype.getRowsText = function(start, end) {
1335 var ary = [];
1336 for (var i = start; i < end; i++) {
1337 var node = this.getRowNode(i);
1338 ary.push(node.textContent);
rgindaa09e7332012-08-17 12:49:51 -07001339 if (i < end - 1 && !node.getAttribute('line-overflow'))
1340 ary.push('\n');
rginda8ba33642011-12-14 12:31:31 -08001341 }
1342
rgindaa09e7332012-08-17 12:49:51 -07001343 return ary.join('');
rginda8ba33642011-12-14 12:31:31 -08001344};
1345
1346/**
1347 * Return the text content for a given row.
1348 *
1349 * This is a method from the RowProvider interface. The ScrollPort uses
1350 * it to fetch text content on demand when the user attempts to copy their
1351 * selection to the clipboard.
1352 *
1353 * @param {integer} index The zero-based row index to return, measured
1354 * relative to the start of the scrollback buffer. On-screen rows will
1355 * always have the largest indicies.
1356 * @return {string} A string containing the text value of the selected row.
1357 */
1358hterm.Terminal.prototype.getRowText = function(index) {
1359 var node = this.getRowNode(index);
rginda87b86462011-12-14 13:48:03 -08001360 return node.textContent;
rginda8ba33642011-12-14 12:31:31 -08001361};
1362
1363/**
1364 * Return the total number of rows in the addressable screen and in the
1365 * scrollback buffer of this terminal.
1366 *
1367 * This is a method from the RowProvider interface. The ScrollPort uses
1368 * it to compute the size of the scrollbar.
1369 *
1370 * @return {integer} The number of rows in this terminal.
1371 */
1372hterm.Terminal.prototype.getRowCount = function() {
1373 return this.scrollbackRows_.length + this.screen_.rowsArray.length;
1374};
1375
1376/**
1377 * Create DOM nodes for new rows and append them to the end of the terminal.
1378 *
1379 * This is the only correct way to add a new DOM node for a row. Notice that
1380 * the new row is appended to the bottom of the list of rows, and does not
1381 * require renumbering (of the rowIndex property) of previous rows.
1382 *
1383 * If you think you want a new blank row somewhere in the middle of the
1384 * terminal, look into moveRows_().
1385 *
1386 * This method does not pay attention to vtScrollTop/Bottom, since you should
1387 * be using moveRows() in cases where they would matter.
1388 *
1389 * The cursor will be positioned at column 0 of the first inserted line.
1390 */
1391hterm.Terminal.prototype.appendRows_ = function(count) {
1392 var cursorRow = this.screen_.rowsArray.length;
1393 var offset = this.scrollbackRows_.length + cursorRow;
1394 for (var i = 0; i < count; i++) {
1395 var row = this.document_.createElement('x-row');
1396 row.appendChild(this.document_.createTextNode(''));
1397 row.rowIndex = offset + i;
1398 this.screen_.pushRow(row);
1399 }
1400
1401 var extraRows = this.screen_.rowsArray.length - this.screenSize.height;
1402 if (extraRows > 0) {
1403 var ary = this.screen_.shiftRows(extraRows);
1404 Array.prototype.push.apply(this.scrollbackRows_, ary);
Robert Ginda36c5aa62012-10-15 11:17:47 -07001405 if (this.scrollPort_.isScrolledEnd)
1406 this.scheduleScrollDown_();
rginda8ba33642011-12-14 12:31:31 -08001407 }
1408
1409 if (cursorRow >= this.screen_.rowsArray.length)
1410 cursorRow = this.screen_.rowsArray.length - 1;
1411
rginda87b86462011-12-14 13:48:03 -08001412 this.setAbsoluteCursorPosition(cursorRow, 0);
rginda8ba33642011-12-14 12:31:31 -08001413};
1414
1415/**
1416 * Relocate rows from one part of the addressable screen to another.
1417 *
1418 * This is used to recycle rows during VT scrolls (those which are driven
1419 * by VT commands, rather than by the user manipulating the scrollbar.)
1420 *
1421 * In this case, the blank lines scrolled into the scroll region are made of
1422 * the nodes we scrolled off. These have their rowIndex properties carefully
1423 * renumbered so as not to confuse the ScrollPort.
rginda8ba33642011-12-14 12:31:31 -08001424 */
1425hterm.Terminal.prototype.moveRows_ = function(fromIndex, count, toIndex) {
1426 var ary = this.screen_.removeRows(fromIndex, count);
1427 this.screen_.insertRows(toIndex, ary);
1428
1429 var start, end;
1430 if (fromIndex < toIndex) {
1431 start = fromIndex;
rginda87b86462011-12-14 13:48:03 -08001432 end = toIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001433 } else {
1434 start = toIndex;
rginda87b86462011-12-14 13:48:03 -08001435 end = fromIndex + count;
rginda8ba33642011-12-14 12:31:31 -08001436 }
1437
1438 this.renumberRows_(start, end);
rginda2312fff2012-01-05 16:20:52 -08001439 this.scrollPort_.scheduleInvalidate();
rginda8ba33642011-12-14 12:31:31 -08001440};
1441
1442/**
1443 * Renumber the rowIndex property of the given range of rows.
1444 *
1445 * The start and end indicies are relative to the screen, not the scrollback.
1446 * Rows in the scrollback buffer cannot be renumbered. Since they are not
rginda2312fff2012-01-05 16:20:52 -08001447 * addressable (you can't delete them, scroll them, etc), you should have
rginda8ba33642011-12-14 12:31:31 -08001448 * no need to renumber scrollback rows.
1449 */
Robert Ginda40932892012-12-10 17:26:40 -08001450hterm.Terminal.prototype.renumberRows_ = function(start, end, opt_screen) {
1451 var screen = opt_screen || this.screen_;
1452
rginda8ba33642011-12-14 12:31:31 -08001453 var offset = this.scrollbackRows_.length;
1454 for (var i = start; i < end; i++) {
Robert Ginda40932892012-12-10 17:26:40 -08001455 screen.rowsArray[i].rowIndex = offset + i;
rginda8ba33642011-12-14 12:31:31 -08001456 }
1457};
1458
1459/**
1460 * Print a string to the terminal.
1461 *
1462 * This respects the current insert and wraparound modes. It will add new lines
1463 * to the end of the terminal, scrolling off the top into the scrollback buffer
1464 * if necessary.
1465 *
1466 * The string is *not* parsed for escape codes. Use the interpret() method if
1467 * that's what you're after.
1468 *
1469 * @param{string} str The string to print.
1470 */
1471hterm.Terminal.prototype.print = function(str) {
rgindaa9abdd82012-08-06 18:05:09 -07001472 var startOffset = 0;
rginda2312fff2012-01-05 16:20:52 -08001473
Ricky Liang48f05cb2013-12-31 23:35:29 +08001474 var strWidth = lib.wc.strWidth(str);
1475
1476 while (startOffset < strWidth) {
rgindaa09e7332012-08-17 12:49:51 -07001477 if (this.options_.wraparound && this.screen_.cursorPosition.overflow) {
1478 this.screen_.commitLineOverflow();
rginda35c456b2012-02-09 17:29:05 -08001479 this.newLine();
rgindaa09e7332012-08-17 12:49:51 -07001480 }
rgindaa19afe22012-01-25 15:40:22 -08001481
Ricky Liang48f05cb2013-12-31 23:35:29 +08001482 var count = strWidth - startOffset;
rgindaa9abdd82012-08-06 18:05:09 -07001483 var didOverflow = false;
1484 var substr;
rgindaa19afe22012-01-25 15:40:22 -08001485
rgindaa9abdd82012-08-06 18:05:09 -07001486 if (this.screen_.cursorPosition.column + count >= this.screenSize.width) {
1487 didOverflow = true;
1488 count = this.screenSize.width - this.screen_.cursorPosition.column;
1489 }
rgindaa19afe22012-01-25 15:40:22 -08001490
rgindaa9abdd82012-08-06 18:05:09 -07001491 if (didOverflow && !this.options_.wraparound) {
1492 // If the string overflowed the line but wraparound is off, then the
1493 // last printed character should be the last of the string.
1494 // TODO: This will add to our problems with multibyte UTF-16 characters.
Ricky Liang48f05cb2013-12-31 23:35:29 +08001495 substr = lib.wc.substr(str, startOffset, count - 1) +
1496 lib.wc.substr(str, strWidth - 1);
1497 count = strWidth;
rgindaa9abdd82012-08-06 18:05:09 -07001498 } else {
Ricky Liang48f05cb2013-12-31 23:35:29 +08001499 substr = lib.wc.substr(str, startOffset, count);
rgindaa9abdd82012-08-06 18:05:09 -07001500 }
rgindaa19afe22012-01-25 15:40:22 -08001501
Ricky Liang48f05cb2013-12-31 23:35:29 +08001502 var tokens = hterm.TextAttributes.splitWidecharString(substr);
1503 for (var i = 0; i < tokens.length; i++) {
1504 if (tokens[i].wcNode)
1505 this.screen_.textAttributes.wcNode = true;
1506
1507 if (this.options_.insertMode) {
1508 this.screen_.insertString(tokens[i].str);
1509 } else {
1510 this.screen_.overwriteString(tokens[i].str);
1511 }
1512 this.screen_.textAttributes.wcNode = false;
rgindaa9abdd82012-08-06 18:05:09 -07001513 }
1514
1515 this.screen_.maybeClipCurrentRow();
1516 startOffset += count;
rgindaa19afe22012-01-25 15:40:22 -08001517 }
rginda8ba33642011-12-14 12:31:31 -08001518
1519 this.scheduleSyncCursorPosition_();
rginda0f5c0292012-01-13 11:00:13 -08001520
rginda9f5222b2012-03-05 11:53:28 -08001521 if (this.scrollOnOutput_)
rginda0f5c0292012-01-13 11:00:13 -08001522 this.scrollPort_.scrollRowToBottom(this.getRowCount());
rginda8ba33642011-12-14 12:31:31 -08001523};
1524
1525/**
rginda87b86462011-12-14 13:48:03 -08001526 * Set the VT scroll region.
1527 *
rginda87b86462011-12-14 13:48:03 -08001528 * This also resets the cursor position to the absolute (0, 0) position, since
1529 * that's what xterm appears to do.
1530 *
Robert Ginda5b9fbe62013-10-30 14:05:53 -07001531 * Setting the scroll region to the full height of the terminal will clear
1532 * the scroll region. This is *NOT* what most terminals do. We're explicitly
1533 * going "off-spec" here because it makes `screen` and `tmux` overflow into the
1534 * local scrollback buffer, which means the scrollbars and shift-pgup/pgdn
1535 * continue to work as most users would expect.
1536 *
rginda87b86462011-12-14 13:48:03 -08001537 * @param {integer} scrollTop The zero-based top of the scroll region.
1538 * @param {integer} scrollBottom The zero-based bottom of the scroll region,
1539 * inclusive.
1540 */
1541hterm.Terminal.prototype.setVTScrollRegion = function(scrollTop, scrollBottom) {
Robert Ginda5b9fbe62013-10-30 14:05:53 -07001542 if (scrollTop == 0 && scrollBottom == this.screenSize.height - 1) {
Robert Ginda43684e22013-11-25 14:18:52 -08001543 this.vtScrollTop_ = null;
1544 this.vtScrollBottom_ = null;
Robert Ginda5b9fbe62013-10-30 14:05:53 -07001545 } else {
1546 this.vtScrollTop_ = scrollTop;
1547 this.vtScrollBottom_ = scrollBottom;
1548 }
rginda87b86462011-12-14 13:48:03 -08001549};
1550
1551/**
rginda8ba33642011-12-14 12:31:31 -08001552 * Return the top row index according to the VT.
1553 *
1554 * This will return 0 unless the terminal has been told to restrict scrolling
1555 * to some lower row. It is used for some VT cursor positioning and scrolling
1556 * commands.
1557 *
1558 * @return {integer} The topmost row in the terminal's scroll region.
1559 */
1560hterm.Terminal.prototype.getVTScrollTop = function() {
1561 if (this.vtScrollTop_ != null)
1562 return this.vtScrollTop_;
1563
1564 return 0;
rginda87b86462011-12-14 13:48:03 -08001565};
rginda8ba33642011-12-14 12:31:31 -08001566
1567/**
1568 * Return the bottom row index according to the VT.
1569 *
1570 * This will return the height of the terminal unless the it has been told to
1571 * restrict scrolling to some higher row. It is used for some VT cursor
1572 * positioning and scrolling commands.
1573 *
1574 * @return {integer} The bottommost row in the terminal's scroll region.
1575 */
1576hterm.Terminal.prototype.getVTScrollBottom = function() {
1577 if (this.vtScrollBottom_ != null)
1578 return this.vtScrollBottom_;
1579
rginda87b86462011-12-14 13:48:03 -08001580 return this.screenSize.height - 1;
rginda8ba33642011-12-14 12:31:31 -08001581}
1582
1583/**
1584 * Process a '\n' character.
1585 *
1586 * If the cursor is on the final row of the terminal this will append a new
1587 * blank row to the screen and scroll the topmost row into the scrollback
1588 * buffer.
1589 *
1590 * Otherwise, this moves the cursor to column zero of the next row.
1591 */
1592hterm.Terminal.prototype.newLine = function() {
Robert Ginda9937abc2013-07-25 16:09:23 -07001593 var cursorAtEndOfScreen = (this.screen_.cursorPosition.row ==
1594 this.screen_.rowsArray.length - 1);
1595
1596 if (this.vtScrollBottom_ != null) {
1597 // A VT Scroll region is active, we never append new rows.
1598 if (this.screen_.cursorPosition.row == this.vtScrollBottom_) {
1599 // We're at the end of the VT Scroll Region, perform a VT scroll.
1600 this.vtScrollUp(1);
1601 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
1602 } else if (cursorAtEndOfScreen) {
1603 // We're at the end of the screen, the only thing to do is put the
1604 // cursor to column 0.
1605 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0);
1606 } else {
1607 // Anywhere else, advance the cursor row, and reset the column.
1608 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
1609 }
1610 } else if (cursorAtEndOfScreen) {
Robert Ginda1b06b372013-07-19 15:22:51 -07001611 // We're at the end of the screen. Append a new row to the terminal,
1612 // shifting the top row into the scrollback.
1613 this.appendRows_(1);
rginda8ba33642011-12-14 12:31:31 -08001614 } else {
rginda87b86462011-12-14 13:48:03 -08001615 // Anywhere else in the screen just moves the cursor.
1616 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0);
rginda8ba33642011-12-14 12:31:31 -08001617 }
1618};
1619
1620/**
1621 * Like newLine(), except maintain the cursor column.
1622 */
1623hterm.Terminal.prototype.lineFeed = function() {
1624 var column = this.screen_.cursorPosition.column;
1625 this.newLine();
1626 this.setCursorColumn(column);
1627};
1628
1629/**
rginda87b86462011-12-14 13:48:03 -08001630 * If autoCarriageReturn is set then newLine(), else lineFeed().
1631 */
1632hterm.Terminal.prototype.formFeed = function() {
1633 if (this.options_.autoCarriageReturn) {
1634 this.newLine();
1635 } else {
1636 this.lineFeed();
1637 }
1638};
1639
1640/**
1641 * Move the cursor up one row, possibly inserting a blank line.
1642 *
1643 * The cursor column is not changed.
1644 */
1645hterm.Terminal.prototype.reverseLineFeed = function() {
1646 var scrollTop = this.getVTScrollTop();
1647 var currentRow = this.screen_.cursorPosition.row;
1648
1649 if (currentRow == scrollTop) {
1650 this.insertLines(1);
1651 } else {
1652 this.setAbsoluteCursorRow(currentRow - 1);
1653 }
1654};
1655
1656/**
rginda8ba33642011-12-14 12:31:31 -08001657 * Replace all characters to the left of the current cursor with the space
1658 * character.
1659 *
1660 * TODO(rginda): This should probably *remove* the characters (not just replace
1661 * with a space) if there are no characters at or beyond the current cursor
Robert Gindaf2547f12012-10-25 20:36:21 -07001662 * position.
rginda8ba33642011-12-14 12:31:31 -08001663 */
1664hterm.Terminal.prototype.eraseToLeft = function() {
rginda87b86462011-12-14 13:48:03 -08001665 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001666 this.setCursorColumn(0);
rgindacbbd7482012-06-13 15:06:16 -07001667 this.screen_.overwriteString(lib.f.getWhitespace(cursor.column + 1));
rginda87b86462011-12-14 13:48:03 -08001668 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001669};
1670
1671/**
David Benjamin684a9b72012-05-01 17:19:58 -04001672 * Erase a given number of characters to the right of the cursor.
rginda8ba33642011-12-14 12:31:31 -08001673 *
1674 * The cursor position is unchanged.
1675 *
Robert Gindaf2547f12012-10-25 20:36:21 -07001676 * If the current background color is not the default background color this
1677 * will insert spaces rather than delete. This is unfortunate because the
1678 * trailing space will affect text selection, but it's difficult to come up
1679 * with a way to style empty space that wouldn't trip up the hterm.Screen
1680 * code.
Robert Gindacd5637d2013-10-30 14:59:10 -07001681 *
1682 * eraseToRight is ignored in the presence of a cursor overflow. This deviates
1683 * from xterm, but agrees with gnome-terminal and konsole, xfce4-terminal. See
1684 * crbug.com/232390 for details.
rginda8ba33642011-12-14 12:31:31 -08001685 */
1686hterm.Terminal.prototype.eraseToRight = function(opt_count) {
Robert Gindacd5637d2013-10-30 14:59:10 -07001687 if (this.screen_.cursorPosition.overflow)
1688 return;
1689
Robert Ginda7fd57082012-09-25 14:41:47 -07001690 var maxCount = this.screenSize.width - this.screen_.cursorPosition.column;
1691 var count = opt_count ? Math.min(opt_count, maxCount) : maxCount;
Robert Gindaf2547f12012-10-25 20:36:21 -07001692
1693 if (this.screen_.textAttributes.background ===
1694 this.screen_.textAttributes.DEFAULT_COLOR) {
1695 var cursorRow = this.screen_.rowsArray[this.screen_.cursorPosition.row];
Ricky Liang48f05cb2013-12-31 23:35:29 +08001696 if (hterm.TextAttributes.nodeWidth(cursorRow) <=
Robert Gindaf2547f12012-10-25 20:36:21 -07001697 this.screen_.cursorPosition.column + count) {
1698 this.screen_.deleteChars(count);
1699 this.clearCursorOverflow();
1700 return;
1701 }
1702 }
1703
rginda87b86462011-12-14 13:48:03 -08001704 var cursor = this.saveCursor();
Robert Ginda7fd57082012-09-25 14:41:47 -07001705 this.screen_.overwriteString(lib.f.getWhitespace(count));
rginda87b86462011-12-14 13:48:03 -08001706 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001707 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001708};
1709
1710/**
1711 * Erase the current line.
1712 *
1713 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001714 */
1715hterm.Terminal.prototype.eraseLine = function() {
rginda87b86462011-12-14 13:48:03 -08001716 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001717 this.screen_.clearCursorRow();
rginda87b86462011-12-14 13:48:03 -08001718 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001719 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001720};
1721
1722/**
David Benjamina08d78f2012-05-05 00:28:49 -04001723 * Erase all characters from the start of the screen to the current cursor
1724 * position, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001725 *
1726 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001727 */
1728hterm.Terminal.prototype.eraseAbove = function() {
rginda87b86462011-12-14 13:48:03 -08001729 var cursor = this.saveCursor();
1730
1731 this.eraseToLeft();
rginda8ba33642011-12-14 12:31:31 -08001732
David Benjamina08d78f2012-05-05 00:28:49 -04001733 for (var i = 0; i < cursor.row; i++) {
rginda87b86462011-12-14 13:48:03 -08001734 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001735 this.screen_.clearCursorRow();
1736 }
1737
rginda87b86462011-12-14 13:48:03 -08001738 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001739 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001740};
1741
1742/**
1743 * Erase all characters from the current cursor position to the end of the
David Benjamina08d78f2012-05-05 00:28:49 -04001744 * screen, regardless of scroll region.
rginda8ba33642011-12-14 12:31:31 -08001745 *
1746 * The cursor position is unchanged.
rginda8ba33642011-12-14 12:31:31 -08001747 */
1748hterm.Terminal.prototype.eraseBelow = function() {
rginda87b86462011-12-14 13:48:03 -08001749 var cursor = this.saveCursor();
1750
1751 this.eraseToRight();
rginda8ba33642011-12-14 12:31:31 -08001752
David Benjamina08d78f2012-05-05 00:28:49 -04001753 var bottom = this.screenSize.height - 1;
rginda87b86462011-12-14 13:48:03 -08001754 for (var i = cursor.row + 1; i <= bottom; i++) {
1755 this.setAbsoluteCursorPosition(i, 0);
rginda8ba33642011-12-14 12:31:31 -08001756 this.screen_.clearCursorRow();
1757 }
1758
rginda87b86462011-12-14 13:48:03 -08001759 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001760 this.clearCursorOverflow();
rginda87b86462011-12-14 13:48:03 -08001761};
1762
1763/**
1764 * Fill the terminal with a given character.
1765 *
1766 * This methods does not respect the VT scroll region.
1767 *
1768 * @param {string} ch The character to use for the fill.
1769 */
1770hterm.Terminal.prototype.fill = function(ch) {
1771 var cursor = this.saveCursor();
1772
1773 this.setAbsoluteCursorPosition(0, 0);
1774 for (var row = 0; row < this.screenSize.height; row++) {
1775 for (var col = 0; col < this.screenSize.width; col++) {
1776 this.setAbsoluteCursorPosition(row, col);
1777 this.screen_.overwriteString(ch);
1778 }
1779 }
1780
1781 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001782};
1783
1784/**
rginda9ea433c2012-03-16 11:57:00 -07001785 * Erase the entire display and leave the cursor at (0, 0).
rginda8ba33642011-12-14 12:31:31 -08001786 *
rginda9ea433c2012-03-16 11:57:00 -07001787 * This does not respect the scroll region.
1788 *
1789 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1790 * to the current screen.
rginda8ba33642011-12-14 12:31:31 -08001791 */
rginda9ea433c2012-03-16 11:57:00 -07001792hterm.Terminal.prototype.clearHome = function(opt_screen) {
1793 var screen = opt_screen || this.screen_;
1794 var bottom = screen.getHeight();
rginda8ba33642011-12-14 12:31:31 -08001795
rginda11057d52012-04-25 12:29:56 -07001796 if (bottom == 0) {
1797 // Empty screen, nothing to do.
1798 return;
1799 }
1800
rgindae4d29232012-01-19 10:47:13 -08001801 for (var i = 0; i < bottom; i++) {
rginda9ea433c2012-03-16 11:57:00 -07001802 screen.setCursorPosition(i, 0);
1803 screen.clearCursorRow();
rginda8ba33642011-12-14 12:31:31 -08001804 }
1805
rginda9ea433c2012-03-16 11:57:00 -07001806 screen.setCursorPosition(0, 0);
1807};
1808
1809/**
1810 * Erase the entire display without changing the cursor position.
1811 *
1812 * The cursor position is unchanged. This does not respect the scroll
1813 * region.
1814 *
1815 * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults
1816 * to the current screen.
rginda9ea433c2012-03-16 11:57:00 -07001817 */
1818hterm.Terminal.prototype.clear = function(opt_screen) {
1819 var screen = opt_screen || this.screen_;
1820 var cursor = screen.cursorPosition.clone();
1821 this.clearHome(screen);
1822 screen.setCursorPosition(cursor.row, cursor.column);
rginda8ba33642011-12-14 12:31:31 -08001823};
1824
1825/**
1826 * VT command to insert lines at the current cursor row.
1827 *
1828 * This respects the current scroll region. Rows pushed off the bottom are
1829 * lost (they won't show up in the scrollback buffer).
1830 *
rginda8ba33642011-12-14 12:31:31 -08001831 * @param {integer} count The number of lines to insert.
1832 */
1833hterm.Terminal.prototype.insertLines = function(count) {
Robert Ginda579186b2012-09-26 11:40:04 -07001834 var cursorRow = this.screen_.cursorPosition.row;
rginda8ba33642011-12-14 12:31:31 -08001835
1836 var bottom = this.getVTScrollBottom();
Robert Ginda579186b2012-09-26 11:40:04 -07001837 count = Math.min(count, bottom - cursorRow);
rginda8ba33642011-12-14 12:31:31 -08001838
Robert Ginda579186b2012-09-26 11:40:04 -07001839 // The moveCount is the number of rows we need to relocate to make room for
1840 // the new row(s). The count is the distance to move them.
1841 var moveCount = bottom - cursorRow - count + 1;
1842 if (moveCount)
1843 this.moveRows_(cursorRow, moveCount, cursorRow + count);
rginda8ba33642011-12-14 12:31:31 -08001844
Robert Ginda579186b2012-09-26 11:40:04 -07001845 for (var i = count - 1; i >= 0; i--) {
1846 this.setAbsoluteCursorPosition(cursorRow + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001847 this.screen_.clearCursorRow();
1848 }
rginda8ba33642011-12-14 12:31:31 -08001849};
1850
1851/**
1852 * VT command to delete lines at the current cursor row.
1853 *
1854 * New rows are added to the bottom of scroll region to take their place. New
1855 * rows are strictly there to take up space and have no content or style.
1856 */
1857hterm.Terminal.prototype.deleteLines = function(count) {
rginda87b86462011-12-14 13:48:03 -08001858 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001859
rginda87b86462011-12-14 13:48:03 -08001860 var top = cursor.row;
rginda8ba33642011-12-14 12:31:31 -08001861 var bottom = this.getVTScrollBottom();
1862
rginda87b86462011-12-14 13:48:03 -08001863 var maxCount = bottom - top + 1;
rginda8ba33642011-12-14 12:31:31 -08001864 count = Math.min(count, maxCount);
1865
rginda87b86462011-12-14 13:48:03 -08001866 var moveStart = bottom - count + 1;
rginda8ba33642011-12-14 12:31:31 -08001867 if (count != maxCount)
1868 this.moveRows_(top, count, moveStart);
1869
1870 for (var i = 0; i < count; i++) {
rginda87b86462011-12-14 13:48:03 -08001871 this.setAbsoluteCursorPosition(moveStart + i, 0);
rginda8ba33642011-12-14 12:31:31 -08001872 this.screen_.clearCursorRow();
1873 }
1874
rginda87b86462011-12-14 13:48:03 -08001875 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001876 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001877};
1878
1879/**
1880 * Inserts the given number of spaces at the current cursor position.
1881 *
rginda87b86462011-12-14 13:48:03 -08001882 * The cursor position is not changed.
rginda8ba33642011-12-14 12:31:31 -08001883 */
1884hterm.Terminal.prototype.insertSpace = function(count) {
rginda87b86462011-12-14 13:48:03 -08001885 var cursor = this.saveCursor();
1886
rgindacbbd7482012-06-13 15:06:16 -07001887 var ws = lib.f.getWhitespace(count || 1);
rginda8ba33642011-12-14 12:31:31 -08001888 this.screen_.insertString(ws);
rgindaa19afe22012-01-25 15:40:22 -08001889 this.screen_.maybeClipCurrentRow();
rginda87b86462011-12-14 13:48:03 -08001890
1891 this.restoreCursor(cursor);
David Benjamin54e8bf62012-06-01 22:31:40 -04001892 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001893};
1894
1895/**
1896 * Forward-delete the specified number of characters starting at the cursor
1897 * position.
1898 *
1899 * @param {integer} count The number of characters to delete.
1900 */
1901hterm.Terminal.prototype.deleteChars = function(count) {
Robert Ginda7fd57082012-09-25 14:41:47 -07001902 var deleted = this.screen_.deleteChars(count);
1903 if (deleted && !this.screen_.textAttributes.isDefault()) {
1904 var cursor = this.saveCursor();
1905 this.setCursorColumn(this.screenSize.width - deleted);
1906 this.screen_.insertString(lib.f.getWhitespace(deleted));
1907 this.restoreCursor(cursor);
1908 }
1909
David Benjamin54e8bf62012-06-01 22:31:40 -04001910 this.clearCursorOverflow();
rginda8ba33642011-12-14 12:31:31 -08001911};
1912
1913/**
1914 * Shift rows in the scroll region upwards by a given number of lines.
1915 *
1916 * New rows are inserted at the bottom of the scroll region to fill the
1917 * vacated rows. The new rows not filled out with the current text attributes.
1918 *
1919 * This function does not affect the scrollback rows at all. Rows shifted
1920 * off the top are lost.
1921 *
rginda87b86462011-12-14 13:48:03 -08001922 * The cursor position is not altered.
1923 *
rginda8ba33642011-12-14 12:31:31 -08001924 * @param {integer} count The number of rows to scroll.
1925 */
1926hterm.Terminal.prototype.vtScrollUp = function(count) {
rginda87b86462011-12-14 13:48:03 -08001927 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001928
rginda87b86462011-12-14 13:48:03 -08001929 this.setAbsoluteCursorRow(this.getVTScrollTop());
rginda8ba33642011-12-14 12:31:31 -08001930 this.deleteLines(count);
1931
rginda87b86462011-12-14 13:48:03 -08001932 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001933};
1934
1935/**
1936 * Shift rows below the cursor down by a given number of lines.
1937 *
1938 * This function respects the current scroll region.
1939 *
1940 * New rows are inserted at the top of the scroll region to fill the
1941 * vacated rows. The new rows not filled out with the current text attributes.
1942 *
1943 * This function does not affect the scrollback rows at all. Rows shifted
1944 * off the bottom are lost.
1945 *
1946 * @param {integer} count The number of rows to scroll.
1947 */
1948hterm.Terminal.prototype.vtScrollDown = function(opt_count) {
rginda87b86462011-12-14 13:48:03 -08001949 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08001950
rginda87b86462011-12-14 13:48:03 -08001951 this.setAbsoluteCursorPosition(this.getVTScrollTop(), 0);
rginda8ba33642011-12-14 12:31:31 -08001952 this.insertLines(opt_count);
1953
rginda87b86462011-12-14 13:48:03 -08001954 this.restoreCursor(cursor);
rginda8ba33642011-12-14 12:31:31 -08001955};
1956
rginda87b86462011-12-14 13:48:03 -08001957
rginda8ba33642011-12-14 12:31:31 -08001958/**
1959 * Set the cursor position.
1960 *
1961 * The cursor row is relative to the scroll region if the terminal has
1962 * 'origin mode' enabled, or relative to the addressable screen otherwise.
1963 *
1964 * @param {integer} row The new zero-based cursor row.
1965 * @param {integer} row The new zero-based cursor column.
1966 */
1967hterm.Terminal.prototype.setCursorPosition = function(row, column) {
1968 if (this.options_.originMode) {
rginda87b86462011-12-14 13:48:03 -08001969 this.setRelativeCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001970 } else {
rginda87b86462011-12-14 13:48:03 -08001971 this.setAbsoluteCursorPosition(row, column);
rginda8ba33642011-12-14 12:31:31 -08001972 }
rginda87b86462011-12-14 13:48:03 -08001973};
rginda8ba33642011-12-14 12:31:31 -08001974
rginda87b86462011-12-14 13:48:03 -08001975hterm.Terminal.prototype.setRelativeCursorPosition = function(row, column) {
1976 var scrollTop = this.getVTScrollTop();
rgindacbbd7482012-06-13 15:06:16 -07001977 row = lib.f.clamp(row + scrollTop, scrollTop, this.getVTScrollBottom());
1978 column = lib.f.clamp(column, 0, this.screenSize.width - 1);
rginda87b86462011-12-14 13:48:03 -08001979 this.screen_.setCursorPosition(row, column);
1980};
1981
1982hterm.Terminal.prototype.setAbsoluteCursorPosition = function(row, column) {
rgindacbbd7482012-06-13 15:06:16 -07001983 row = lib.f.clamp(row, 0, this.screenSize.height - 1);
1984 column = lib.f.clamp(column, 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08001985 this.screen_.setCursorPosition(row, column);
1986};
1987
1988/**
1989 * Set the cursor column.
1990 *
1991 * @param {integer} column The new zero-based cursor column.
1992 */
1993hterm.Terminal.prototype.setCursorColumn = function(column) {
rginda87b86462011-12-14 13:48:03 -08001994 this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, column);
rginda8ba33642011-12-14 12:31:31 -08001995};
1996
1997/**
1998 * Return the cursor column.
1999 *
2000 * @return {integer} The zero-based cursor column.
2001 */
2002hterm.Terminal.prototype.getCursorColumn = function() {
2003 return this.screen_.cursorPosition.column;
2004};
2005
2006/**
2007 * Set the cursor row.
2008 *
2009 * The cursor row is relative to the scroll region if the terminal has
2010 * 'origin mode' enabled, or relative to the addressable screen otherwise.
2011 *
2012 * @param {integer} row The new cursor row.
2013 */
rginda87b86462011-12-14 13:48:03 -08002014hterm.Terminal.prototype.setAbsoluteCursorRow = function(row) {
2015 this.setAbsoluteCursorPosition(row, this.screen_.cursorPosition.column);
rginda8ba33642011-12-14 12:31:31 -08002016};
2017
2018/**
2019 * Return the cursor row.
2020 *
2021 * @return {integer} The zero-based cursor row.
2022 */
2023hterm.Terminal.prototype.getCursorRow = function(row) {
2024 return this.screen_.cursorPosition.row;
2025};
2026
2027/**
2028 * Request that the ScrollPort redraw itself soon.
2029 *
2030 * The redraw will happen asynchronously, soon after the call stack winds down.
2031 * Multiple calls will be coalesced into a single redraw.
2032 */
2033hterm.Terminal.prototype.scheduleRedraw_ = function() {
rginda87b86462011-12-14 13:48:03 -08002034 if (this.timeouts_.redraw)
2035 return;
rginda8ba33642011-12-14 12:31:31 -08002036
2037 var self = this;
rginda87b86462011-12-14 13:48:03 -08002038 this.timeouts_.redraw = setTimeout(function() {
2039 delete self.timeouts_.redraw;
rginda8ba33642011-12-14 12:31:31 -08002040 self.scrollPort_.redraw_();
2041 }, 0);
2042};
2043
2044/**
2045 * Request that the ScrollPort be scrolled to the bottom.
2046 *
2047 * The scroll will happen asynchronously, soon after the call stack winds down.
2048 * Multiple calls will be coalesced into a single scroll.
2049 *
2050 * This affects the scrollbar position of the ScrollPort, and has nothing to
2051 * do with the VT scroll commands.
2052 */
2053hterm.Terminal.prototype.scheduleScrollDown_ = function() {
2054 if (this.timeouts_.scrollDown)
rginda87b86462011-12-14 13:48:03 -08002055 return;
rginda8ba33642011-12-14 12:31:31 -08002056
2057 var self = this;
2058 this.timeouts_.scrollDown = setTimeout(function() {
2059 delete self.timeouts_.scrollDown;
2060 self.scrollPort_.scrollRowToBottom(self.getRowCount());
2061 }, 10);
2062};
2063
2064/**
2065 * Move the cursor up a specified number of rows.
2066 *
2067 * @param {integer} count The number of rows to move the cursor.
2068 */
2069hterm.Terminal.prototype.cursorUp = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08002070 return this.cursorDown(-(count || 1));
rginda8ba33642011-12-14 12:31:31 -08002071};
2072
2073/**
2074 * Move the cursor down a specified number of rows.
2075 *
2076 * @param {integer} count The number of rows to move the cursor.
2077 */
2078hterm.Terminal.prototype.cursorDown = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08002079 count = count || 1;
rginda8ba33642011-12-14 12:31:31 -08002080 var minHeight = (this.options_.originMode ? this.getVTScrollTop() : 0);
2081 var maxHeight = (this.options_.originMode ? this.getVTScrollBottom() :
2082 this.screenSize.height - 1);
2083
rgindacbbd7482012-06-13 15:06:16 -07002084 var row = lib.f.clamp(this.screen_.cursorPosition.row + count,
rginda8ba33642011-12-14 12:31:31 -08002085 minHeight, maxHeight);
rginda87b86462011-12-14 13:48:03 -08002086 this.setAbsoluteCursorRow(row);
rginda8ba33642011-12-14 12:31:31 -08002087};
2088
2089/**
2090 * Move the cursor left a specified number of columns.
2091 *
Robert Gindaaaba6132014-07-16 16:33:07 -07002092 * If reverse wraparound mode is enabled and the previous row wrapped into
2093 * the current row then we back up through the wraparound as well.
2094 *
rginda8ba33642011-12-14 12:31:31 -08002095 * @param {integer} count The number of columns to move the cursor.
2096 */
2097hterm.Terminal.prototype.cursorLeft = function(count) {
Robert Gindaaaba6132014-07-16 16:33:07 -07002098 count = count || 1;
2099
2100 if (count < 1)
2101 return;
2102
2103 var currentColumn = this.screen_.cursorPosition.column;
Robert Gindabfb32622014-07-17 13:20:27 -07002104 if (this.options_.reverseWraparound) {
2105 if (this.screen_.cursorPosition.overflow) {
2106 // If this cursor is in the right margin, consume one count to get it
2107 // back to the last column. This only applies when we're in reverse
2108 // wraparound mode.
2109 count--;
2110 this.clearCursorOverflow();
2111
2112 if (!count)
Robert Gindaaaba6132014-07-16 16:33:07 -07002113 return;
Robert Gindaaaba6132014-07-16 16:33:07 -07002114 }
2115
Robert Gindabfb32622014-07-17 13:20:27 -07002116 var newRow = this.screen_.cursorPosition.row;
2117 var newColumn = currentColumn - count;
2118 if (newColumn < 0) {
2119 newRow = newRow - Math.floor(count / this.screenSize.width) - 1;
2120 if (newRow < 0) {
2121 // xterm also wraps from row 0 to the last row.
2122 newRow = this.screenSize.height + newRow % this.screenSize.height;
2123 }
2124 newColumn = this.screenSize.width + newColumn % this.screenSize.width;
2125 }
Robert Gindaaaba6132014-07-16 16:33:07 -07002126
Robert Gindabfb32622014-07-17 13:20:27 -07002127 this.setCursorPosition(Math.max(newRow, 0), newColumn);
2128
2129 } else {
2130 var newColumn = Math.max(currentColumn - count, 0);
2131 this.setCursorColumn(newColumn);
2132 }
rginda8ba33642011-12-14 12:31:31 -08002133};
2134
2135/**
2136 * Move the cursor right a specified number of columns.
2137 *
2138 * @param {integer} count The number of columns to move the cursor.
2139 */
2140hterm.Terminal.prototype.cursorRight = function(count) {
rginda0f5c0292012-01-13 11:00:13 -08002141 count = count || 1;
Robert Gindaaaba6132014-07-16 16:33:07 -07002142
2143 if (count < 1)
2144 return;
2145
rgindacbbd7482012-06-13 15:06:16 -07002146 var column = lib.f.clamp(this.screen_.cursorPosition.column + count,
rginda87b86462011-12-14 13:48:03 -08002147 0, this.screenSize.width - 1);
rginda8ba33642011-12-14 12:31:31 -08002148 this.setCursorColumn(column);
2149};
2150
2151/**
2152 * Reverse the foreground and background colors of the terminal.
2153 *
2154 * This only affects text that was drawn with no attributes.
2155 *
2156 * TODO(rginda): Test xterm to see if reverse is respected for text that has
2157 * been drawn with attributes that happen to coincide with the default
2158 * 'no-attribute' colors. My guess is probably not.
2159 */
2160hterm.Terminal.prototype.setReverseVideo = function(state) {
rginda87b86462011-12-14 13:48:03 -08002161 this.options_.reverseVideo = state;
rginda8ba33642011-12-14 12:31:31 -08002162 if (state) {
rginda9f5222b2012-03-05 11:53:28 -08002163 this.scrollPort_.setForegroundColor(this.prefs_.get('background-color'));
2164 this.scrollPort_.setBackgroundColor(this.prefs_.get('foreground-color'));
rginda8ba33642011-12-14 12:31:31 -08002165 } else {
rginda9f5222b2012-03-05 11:53:28 -08002166 this.scrollPort_.setForegroundColor(this.prefs_.get('foreground-color'));
2167 this.scrollPort_.setBackgroundColor(this.prefs_.get('background-color'));
rginda8ba33642011-12-14 12:31:31 -08002168 }
2169};
2170
2171/**
rginda87b86462011-12-14 13:48:03 -08002172 * Ring the terminal bell.
Robert Ginda92e18102013-03-14 13:56:37 -07002173 *
2174 * This will not play the bell audio more than once per second.
rginda87b86462011-12-14 13:48:03 -08002175 */
2176hterm.Terminal.prototype.ringBell = function() {
rginda6d397402012-01-17 10:58:29 -08002177 this.cursorNode_.style.backgroundColor =
2178 this.scrollPort_.getForegroundColor();
rginda87b86462011-12-14 13:48:03 -08002179
2180 var self = this;
2181 setTimeout(function() {
rginda9f5222b2012-03-05 11:53:28 -08002182 self.cursorNode_.style.backgroundColor = self.prefs_.get('cursor-color');
rginda6d397402012-01-17 10:58:29 -08002183 }, 200);
Robert Ginda92e18102013-03-14 13:56:37 -07002184
Michael Kelly485ecd12014-06-09 11:41:56 -04002185 // bellSquelchTimeout_ affects both audio and notification bells.
2186 if (this.bellSquelchTimeout_)
2187 return;
2188
Robert Ginda92e18102013-03-14 13:56:37 -07002189 if (this.bellAudio_.getAttribute('src')) {
Robert Ginda92e18102013-03-14 13:56:37 -07002190 this.bellAudio_.play();
Robert Ginda92e18102013-03-14 13:56:37 -07002191 this.bellSequelchTimeout_ = setTimeout(function() {
2192 delete this.bellSquelchTimeout_;
Robert Gindaa6331372013-03-19 10:35:39 -07002193 }.bind(this), 500);
Robert Ginda92e18102013-03-14 13:56:37 -07002194 } else {
2195 delete this.bellSquelchTimeout_;
2196 }
Michael Kelly485ecd12014-06-09 11:41:56 -04002197
2198 if (this.desktopNotificationBell_ && !this.document_.hasFocus()) {
2199 var n = new Notification(
2200 lib.f.replaceVars(hterm.desktopNotificationTitle,
Robert Ginda348dc2b2014-06-24 14:42:23 -07002201 {'title': window.document.title || 'hterm'}));
Michael Kelly485ecd12014-06-09 11:41:56 -04002202 this.bellNotificationList_.push(n);
2203 // TODO: Should we try to raise the window here?
2204 n.onclick = function() { self.closeBellNotifications_(); };
2205 }
rginda87b86462011-12-14 13:48:03 -08002206};
2207
2208/**
rginda8ba33642011-12-14 12:31:31 -08002209 * Set the origin mode bit.
2210 *
2211 * If origin mode is on, certain VT cursor and scrolling commands measure their
2212 * row parameter relative to the VT scroll region. Otherwise, row 0 corresponds
2213 * to the top of the addressable screen.
2214 *
2215 * Defaults to off.
2216 *
2217 * @param {boolean} state True to set origin mode, false to unset.
2218 */
2219hterm.Terminal.prototype.setOriginMode = function(state) {
2220 this.options_.originMode = state;
rgindae4d29232012-01-19 10:47:13 -08002221 this.setCursorPosition(0, 0);
rginda8ba33642011-12-14 12:31:31 -08002222};
2223
2224/**
2225 * Set the insert mode bit.
2226 *
2227 * If insert mode is on, existing text beyond the cursor position will be
2228 * shifted right to make room for new text. Otherwise, new text overwrites
2229 * any existing text.
2230 *
2231 * Defaults to off.
2232 *
2233 * @param {boolean} state True to set insert mode, false to unset.
2234 */
2235hterm.Terminal.prototype.setInsertMode = function(state) {
2236 this.options_.insertMode = state;
2237};
2238
2239/**
rginda87b86462011-12-14 13:48:03 -08002240 * Set the auto carriage return bit.
2241 *
2242 * If auto carriage return is on then a formfeed character is interpreted
2243 * as a newline, otherwise it's the same as a linefeed. The difference boils
2244 * down to whether or not the cursor column is reset.
2245 */
2246hterm.Terminal.prototype.setAutoCarriageReturn = function(state) {
2247 this.options_.autoCarriageReturn = state;
2248};
2249
2250/**
rginda8ba33642011-12-14 12:31:31 -08002251 * Set the wraparound mode bit.
2252 *
2253 * If wraparound mode is on, certain VT commands will allow the cursor to wrap
2254 * to the start of the following row. Otherwise, the cursor is clamped to the
2255 * end of the screen and attempts to write past it are ignored.
2256 *
2257 * Defaults to on.
2258 *
2259 * @param {boolean} state True to set wraparound mode, false to unset.
2260 */
2261hterm.Terminal.prototype.setWraparound = function(state) {
2262 this.options_.wraparound = state;
2263};
2264
2265/**
2266 * Set the reverse-wraparound mode bit.
2267 *
2268 * If wraparound mode is off, certain VT commands will allow the cursor to wrap
2269 * to the end of the previous row. Otherwise, the cursor is clamped to column
2270 * 0.
2271 *
2272 * Defaults to off.
2273 *
2274 * @param {boolean} state True to set reverse-wraparound mode, false to unset.
2275 */
2276hterm.Terminal.prototype.setReverseWraparound = function(state) {
2277 this.options_.reverseWraparound = state;
2278};
2279
2280/**
2281 * Selects between the primary and alternate screens.
2282 *
2283 * If alternate mode is on, the alternate screen is active. Otherwise the
2284 * primary screen is active.
2285 *
2286 * Swapping screens has no effect on the scrollback buffer.
2287 *
2288 * Each screen maintains its own cursor position.
2289 *
2290 * Defaults to off.
2291 *
2292 * @param {boolean} state True to set alternate mode, false to unset.
2293 */
2294hterm.Terminal.prototype.setAlternateMode = function(state) {
rginda6d397402012-01-17 10:58:29 -08002295 var cursor = this.saveCursor();
rginda8ba33642011-12-14 12:31:31 -08002296 this.screen_ = state ? this.alternateScreen_ : this.primaryScreen_;
2297
rginda35c456b2012-02-09 17:29:05 -08002298 if (this.screen_.rowsArray.length &&
2299 this.screen_.rowsArray[0].rowIndex != this.scrollbackRows_.length) {
2300 // If the screen changed sizes while we were away, our rowIndexes may
2301 // be incorrect.
2302 var offset = this.scrollbackRows_.length;
2303 var ary = this.screen_.rowsArray;
rgindacbbd7482012-06-13 15:06:16 -07002304 for (var i = 0; i < ary.length; i++) {
rginda35c456b2012-02-09 17:29:05 -08002305 ary[i].rowIndex = offset + i;
2306 }
2307 }
rginda8ba33642011-12-14 12:31:31 -08002308
rginda35c456b2012-02-09 17:29:05 -08002309 this.realizeWidth_(this.screenSize.width);
2310 this.realizeHeight_(this.screenSize.height);
2311 this.scrollPort_.syncScrollHeight();
2312 this.scrollPort_.invalidate();
rginda8ba33642011-12-14 12:31:31 -08002313
rginda6d397402012-01-17 10:58:29 -08002314 this.restoreCursor(cursor);
rginda35c456b2012-02-09 17:29:05 -08002315 this.scrollPort_.resize();
rginda8ba33642011-12-14 12:31:31 -08002316};
2317
2318/**
2319 * Set the cursor-blink mode bit.
2320 *
2321 * If cursor-blink is on, the cursor will blink when it is visible. Otherwise
2322 * a visible cursor does not blink.
2323 *
2324 * You should make sure to turn blinking off if you're going to dispose of a
2325 * terminal, otherwise you'll leak a timeout.
2326 *
2327 * Defaults to on.
2328 *
2329 * @param {boolean} state True to set cursor-blink mode, false to unset.
2330 */
2331hterm.Terminal.prototype.setCursorBlink = function(state) {
2332 this.options_.cursorBlink = state;
2333
2334 if (!state && this.timeouts_.cursorBlink) {
2335 clearTimeout(this.timeouts_.cursorBlink);
2336 delete this.timeouts_.cursorBlink;
2337 }
2338
2339 if (this.options_.cursorVisible)
2340 this.setCursorVisible(true);
2341};
2342
2343/**
2344 * Set the cursor-visible mode bit.
2345 *
2346 * If cursor-visible is on, the cursor will be visible. Otherwise it will not.
2347 *
2348 * Defaults to on.
2349 *
2350 * @param {boolean} state True to set cursor-visible mode, false to unset.
2351 */
2352hterm.Terminal.prototype.setCursorVisible = function(state) {
2353 this.options_.cursorVisible = state;
2354
2355 if (!state) {
rginda87b86462011-12-14 13:48:03 -08002356 this.cursorNode_.style.opacity = '0';
rginda8ba33642011-12-14 12:31:31 -08002357 return;
2358 }
2359
rginda87b86462011-12-14 13:48:03 -08002360 this.syncCursorPosition_();
2361
2362 this.cursorNode_.style.opacity = '1';
rginda8ba33642011-12-14 12:31:31 -08002363
2364 if (this.options_.cursorBlink) {
2365 if (this.timeouts_.cursorBlink)
2366 return;
2367
Robert Gindaea2183e2014-07-17 09:51:51 -07002368 this.onCursorBlink_();
rginda8ba33642011-12-14 12:31:31 -08002369 } else {
2370 if (this.timeouts_.cursorBlink) {
2371 clearTimeout(this.timeouts_.cursorBlink);
2372 delete this.timeouts_.cursorBlink;
2373 }
2374 }
2375};
2376
2377/**
rginda87b86462011-12-14 13:48:03 -08002378 * Synchronizes the visible cursor and document selection with the current
2379 * cursor coordinates.
rginda8ba33642011-12-14 12:31:31 -08002380 */
2381hterm.Terminal.prototype.syncCursorPosition_ = function() {
2382 var topRowIndex = this.scrollPort_.getTopRowIndex();
2383 var bottomRowIndex = this.scrollPort_.getBottomRowIndex(topRowIndex);
2384 var cursorRowIndex = this.scrollbackRows_.length +
2385 this.screen_.cursorPosition.row;
2386
2387 if (cursorRowIndex > bottomRowIndex) {
2388 // Cursor is scrolled off screen, move it outside of the visible area.
rginda35c456b2012-02-09 17:29:05 -08002389 this.cursorNode_.style.top = -this.scrollPort_.characterSize.height + 'px';
rginda8ba33642011-12-14 12:31:31 -08002390 return;
2391 }
2392
Robert Gindab837c052014-08-11 11:17:51 -07002393 if (this.options_.cursorVisible &&
2394 this.cursorNode_.style.display == 'none') {
2395 // Re-display the terminal cursor if it was hidden by the mouse cursor.
2396 this.cursorNode_.style.display = '';
2397 }
2398
2399
rginda8ba33642011-12-14 12:31:31 -08002400 this.cursorNode_.style.top = this.scrollPort_.visibleRowTopMargin +
rginda35c456b2012-02-09 17:29:05 -08002401 this.scrollPort_.characterSize.height * (cursorRowIndex - topRowIndex) +
2402 'px';
2403 this.cursorNode_.style.left = this.scrollPort_.characterSize.width *
2404 this.screen_.cursorPosition.column + 'px';
rginda87b86462011-12-14 13:48:03 -08002405
2406 this.cursorNode_.setAttribute('title',
2407 '(' + this.screen_.cursorPosition.row +
2408 ', ' + this.screen_.cursorPosition.column +
2409 ')');
2410
2411 // Update the caret for a11y purposes.
2412 var selection = this.document_.getSelection();
2413 if (selection && selection.isCollapsed)
2414 this.screen_.syncSelectionCaret(selection);
rginda8ba33642011-12-14 12:31:31 -08002415};
2416
Robert Gindafb1be6a2013-12-11 11:56:22 -08002417/**
2418 * Adjusts the style of this.cursorNode_ according to the current cursor shape
2419 * and character cell dimensions.
2420 */
Robert Ginda830583c2013-08-07 13:20:46 -07002421hterm.Terminal.prototype.restyleCursor_ = function() {
2422 var shape = this.cursorShape_;
2423
2424 if (this.cursorNode_.getAttribute('focus') == 'false') {
2425 // Always show a block cursor when unfocused.
2426 shape = hterm.Terminal.cursorShape.BLOCK;
2427 }
2428
2429 var style = this.cursorNode_.style;
2430
Robert Gindafb1be6a2013-12-11 11:56:22 -08002431 style.width = this.scrollPort_.characterSize.width + 'px';
2432
Robert Ginda830583c2013-08-07 13:20:46 -07002433 switch (shape) {
2434 case hterm.Terminal.cursorShape.BEAM:
2435 style.height = this.scrollPort_.characterSize.height + 'px';
2436 style.backgroundColor = 'transparent';
2437 style.borderBottomStyle = null;
2438 style.borderLeftStyle = 'solid';
2439 break;
2440
2441 case hterm.Terminal.cursorShape.UNDERLINE:
2442 style.height = this.scrollPort_.characterSize.baseline + 'px';
2443 style.backgroundColor = 'transparent';
2444 style.borderBottomStyle = 'solid';
2445 // correct the size to put it exactly at the baseline
2446 style.borderLeftStyle = null;
2447 break;
2448
2449 default:
2450 style.height = this.scrollPort_.characterSize.height + 'px';
2451 style.backgroundColor = this.cursorColor_;
2452 style.borderBottomStyle = null;
2453 style.borderLeftStyle = null;
2454 break;
2455 }
2456};
2457
rginda8ba33642011-12-14 12:31:31 -08002458/**
2459 * Synchronizes the visible cursor with the current cursor coordinates.
2460 *
2461 * The sync will happen asynchronously, soon after the call stack winds down.
2462 * Multiple calls will be coalesced into a single sync.
2463 */
2464hterm.Terminal.prototype.scheduleSyncCursorPosition_ = function() {
2465 if (this.timeouts_.syncCursor)
rginda87b86462011-12-14 13:48:03 -08002466 return;
rginda8ba33642011-12-14 12:31:31 -08002467
2468 var self = this;
2469 this.timeouts_.syncCursor = setTimeout(function() {
2470 self.syncCursorPosition_();
2471 delete self.timeouts_.syncCursor;
rginda87b86462011-12-14 13:48:03 -08002472 }, 0);
2473};
2474
rgindacc2996c2012-02-24 14:59:31 -08002475/**
rgindaf522ce02012-04-17 17:49:17 -07002476 * Show or hide the zoom warning.
2477 *
2478 * The zoom warning is a message warning the user that their browser zoom must
2479 * be set to 100% in order for hterm to function properly.
2480 *
2481 * @param {boolean} state True to show the message, false to hide it.
2482 */
2483hterm.Terminal.prototype.showZoomWarning_ = function(state) {
2484 if (!this.zoomWarningNode_) {
2485 if (!state)
2486 return;
2487
2488 this.zoomWarningNode_ = this.document_.createElement('div');
2489 this.zoomWarningNode_.style.cssText = (
2490 'color: black;' +
2491 'background-color: #ff2222;' +
2492 'font-size: large;' +
2493 'border-radius: 8px;' +
2494 'opacity: 0.75;' +
2495 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2496 'top: 0.5em;' +
2497 'right: 1.2em;' +
2498 'position: absolute;' +
2499 '-webkit-text-size-adjust: none;' +
Rob Spies06533ba2014-04-24 11:20:37 -07002500 '-webkit-user-select: none;' +
2501 '-moz-text-size-adjust: none;' +
2502 '-moz-user-select: none;');
rgindaf522ce02012-04-17 17:49:17 -07002503 }
2504
Robert Gindab4839c22013-02-28 16:52:10 -08002505 this.zoomWarningNode_.textContent = lib.MessageManager.replaceReferences(
2506 hterm.zoomWarningMessage,
2507 [parseInt(this.scrollPort_.characterSize.zoomFactor * 100)]);
2508
rgindaf522ce02012-04-17 17:49:17 -07002509 this.zoomWarningNode_.style.fontFamily = this.prefs_.get('font-family');
2510
2511 if (state) {
2512 if (!this.zoomWarningNode_.parentNode)
2513 this.div_.parentNode.appendChild(this.zoomWarningNode_);
2514 } else if (this.zoomWarningNode_.parentNode) {
2515 this.zoomWarningNode_.parentNode.removeChild(this.zoomWarningNode_);
2516 }
2517};
2518
2519/**
rgindacc2996c2012-02-24 14:59:31 -08002520 * Show the terminal overlay for a given amount of time.
2521 *
2522 * The terminal overlay appears in inverse video in a large font, centered
2523 * over the terminal. You should probably keep the overlay message brief,
2524 * since it's in a large font and you probably aren't going to check the size
2525 * of the terminal first.
2526 *
2527 * @param {string} msg The text (not HTML) message to display in the overlay.
2528 * @param {number} opt_timeout The amount of time to wait before fading out
2529 * the overlay. Defaults to 1.5 seconds. Pass null to have the overlay
2530 * stay up forever (or until the next overlay).
2531 */
2532hterm.Terminal.prototype.showOverlay = function(msg, opt_timeout) {
rgindaf0090c92012-02-10 14:58:52 -08002533 if (!this.overlayNode_) {
2534 if (!this.div_)
2535 return;
2536
2537 this.overlayNode_ = this.document_.createElement('div');
2538 this.overlayNode_.style.cssText = (
rgindaf0090c92012-02-10 14:58:52 -08002539 'border-radius: 15px;' +
rgindaf0090c92012-02-10 14:58:52 -08002540 'font-size: xx-large;' +
2541 'opacity: 0.75;' +
2542 'padding: 0.2em 0.5em 0.2em 0.5em;' +
2543 'position: absolute;' +
2544 '-webkit-user-select: none;' +
Rob Spies06533ba2014-04-24 11:20:37 -07002545 '-webkit-transition: opacity 180ms ease-in;' +
2546 '-moz-user-select: none;' +
2547 '-moz-transition: opacity 180ms ease-in;');
Robert Ginda70926e42013-11-25 14:56:36 -08002548
2549 this.overlayNode_.addEventListener('mousedown', function(e) {
2550 e.preventDefault();
2551 e.stopPropagation();
2552 }, true);
rgindaf0090c92012-02-10 14:58:52 -08002553 }
2554
rginda9f5222b2012-03-05 11:53:28 -08002555 this.overlayNode_.style.color = this.prefs_.get('background-color');
2556 this.overlayNode_.style.backgroundColor = this.prefs_.get('foreground-color');
2557 this.overlayNode_.style.fontFamily = this.prefs_.get('font-family');
2558
rgindaf0090c92012-02-10 14:58:52 -08002559 this.overlayNode_.textContent = msg;
2560 this.overlayNode_.style.opacity = '0.75';
2561
2562 if (!this.overlayNode_.parentNode)
2563 this.div_.appendChild(this.overlayNode_);
2564
Robert Ginda97769282013-02-01 15:30:30 -08002565 var divSize = hterm.getClientSize(this.div_);
2566 var overlaySize = hterm.getClientSize(this.overlayNode_);
2567
Robert Ginda8a59f762014-07-23 11:29:55 -07002568 this.overlayNode_.style.top =
2569 (divSize.height - overlaySize.height) / 2 + 'px';
Robert Ginda97769282013-02-01 15:30:30 -08002570 this.overlayNode_.style.left = (divSize.width - overlaySize.width -
Robert Ginda8a59f762014-07-23 11:29:55 -07002571 this.scrollPort_.currentScrollbarWidthPx) / 2 + 'px';
rgindaf0090c92012-02-10 14:58:52 -08002572
2573 var self = this;
2574
2575 if (this.overlayTimeout_)
2576 clearTimeout(this.overlayTimeout_);
2577
rgindacc2996c2012-02-24 14:59:31 -08002578 if (opt_timeout === null)
2579 return;
2580
rgindaf0090c92012-02-10 14:58:52 -08002581 this.overlayTimeout_ = setTimeout(function() {
2582 self.overlayNode_.style.opacity = '0';
Robert Ginda70926e42013-11-25 14:56:36 -08002583 self.overlayTimeout_ = setTimeout(function() {
rginda259dcca2012-03-14 16:37:11 -07002584 if (self.overlayNode_.parentNode)
2585 self.overlayNode_.parentNode.removeChild(self.overlayNode_);
rgindaf0090c92012-02-10 14:58:52 -08002586 self.overlayTimeout_ = null;
2587 self.overlayNode_.style.opacity = '0.75';
2588 }, 200);
rgindacc2996c2012-02-24 14:59:31 -08002589 }, opt_timeout || 1500);
rgindaf0090c92012-02-10 14:58:52 -08002590};
2591
rginda4bba5e12012-06-20 16:15:30 -07002592/**
2593 * Paste from the system clipboard to the terminal.
2594 */
2595hterm.Terminal.prototype.paste = function() {
2596 hterm.pasteFromClipboard(this.document_);
2597};
2598
2599/**
2600 * Copy a string to the system clipboard.
2601 *
2602 * Note: If there is a selected range in the terminal, it'll be cleared.
2603 */
2604hterm.Terminal.prototype.copyStringToClipboard = function(str) {
Robert Ginda4e4d42c2014-03-04 14:07:23 -08002605 if (this.prefs_.get('enable-clipboard-notice'))
2606 setTimeout(this.showOverlay.bind(this, hterm.notifyCopyMessage, 500), 200);
2607
rgindaa09e7332012-08-17 12:49:51 -07002608 var copySource = this.document_.createElement('pre');
rginda4bba5e12012-06-20 16:15:30 -07002609 copySource.textContent = str;
2610 copySource.style.cssText = (
2611 '-webkit-user-select: text;' +
Rob Spies06533ba2014-04-24 11:20:37 -07002612 '-moz-user-select: text;' +
rginda4bba5e12012-06-20 16:15:30 -07002613 'position: absolute;' +
2614 'top: -99px');
2615
2616 this.document_.body.appendChild(copySource);
rgindafaa74742012-08-21 13:34:03 -07002617
rginda4bba5e12012-06-20 16:15:30 -07002618 var selection = this.document_.getSelection();
rgindafaa74742012-08-21 13:34:03 -07002619 var anchorNode = selection.anchorNode;
2620 var anchorOffset = selection.anchorOffset;
2621 var focusNode = selection.focusNode;
2622 var focusOffset = selection.focusOffset;
2623
rginda4bba5e12012-06-20 16:15:30 -07002624 selection.selectAllChildren(copySource);
2625
rgindaa09e7332012-08-17 12:49:51 -07002626 hterm.copySelectionToClipboard(this.document_);
rginda4bba5e12012-06-20 16:15:30 -07002627
Rob Spies56953412014-04-28 14:09:47 -07002628 // IE doesn't support selection.extend. This means that the selection
2629 // won't return on IE.
Robert Ginda6f4f0aa2014-07-28 10:21:39 -07002630 if (selection.extend) {
Rob Spies56953412014-04-28 14:09:47 -07002631 selection.collapse(anchorNode, anchorOffset);
2632 selection.extend(focusNode, focusOffset);
2633 }
rgindafaa74742012-08-21 13:34:03 -07002634
rginda4bba5e12012-06-20 16:15:30 -07002635 copySource.parentNode.removeChild(copySource);
2636};
2637
rgindaa09e7332012-08-17 12:49:51 -07002638hterm.Terminal.prototype.getSelectionText = function() {
2639 var selection = this.scrollPort_.selection;
2640 selection.sync();
2641
2642 if (selection.isCollapsed)
2643 return null;
2644
2645
2646 // Start offset measures from the beginning of the line.
2647 var startOffset = selection.startOffset;
2648 var node = selection.startNode;
Robert Ginda0d190502012-10-02 10:59:00 -07002649
Robert Gindafdbb3f22012-09-06 20:23:06 -07002650 if (node.nodeName != 'X-ROW') {
2651 // If the selection doesn't start on an x-row node, then it must be
2652 // somewhere inside the x-row. Add any characters from previous siblings
2653 // into the start offset.
Robert Ginda0d190502012-10-02 10:59:00 -07002654
2655 if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') {
2656 // If node is the text node in a styled span, move up to the span node.
2657 node = node.parentNode;
2658 }
2659
Robert Gindafdbb3f22012-09-06 20:23:06 -07002660 while (node.previousSibling) {
2661 node = node.previousSibling;
Ricky Liang48f05cb2013-12-31 23:35:29 +08002662 startOffset += hterm.TextAttributes.nodeWidth(node);
Robert Gindafdbb3f22012-09-06 20:23:06 -07002663 }
rgindaa09e7332012-08-17 12:49:51 -07002664 }
2665
2666 // End offset measures from the end of the line.
Ricky Liang48f05cb2013-12-31 23:35:29 +08002667 var endOffset = (hterm.TextAttributes.nodeWidth(selection.endNode) -
2668 selection.endOffset);
rgindaa09e7332012-08-17 12:49:51 -07002669 var node = selection.endNode;
Robert Ginda0d190502012-10-02 10:59:00 -07002670
Robert Gindafdbb3f22012-09-06 20:23:06 -07002671 if (node.nodeName != 'X-ROW') {
2672 // If the selection doesn't end on an x-row node, then it must be
2673 // somewhere inside the x-row. Add any characters from following siblings
2674 // into the end offset.
Robert Ginda0d190502012-10-02 10:59:00 -07002675
2676 if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') {
2677 // If node is the text node in a styled span, move up to the span node.
2678 node = node.parentNode;
2679 }
2680
Robert Gindafdbb3f22012-09-06 20:23:06 -07002681 while (node.nextSibling) {
2682 node = node.nextSibling;
Ricky Liang48f05cb2013-12-31 23:35:29 +08002683 endOffset += hterm.TextAttributes.nodeWidth(node);
Robert Gindafdbb3f22012-09-06 20:23:06 -07002684 }
rgindaa09e7332012-08-17 12:49:51 -07002685 }
2686
2687 var rv = this.getRowsText(selection.startRow.rowIndex,
2688 selection.endRow.rowIndex + 1);
Ricky Liang48f05cb2013-12-31 23:35:29 +08002689 return lib.wc.substring(rv, startOffset, lib.wc.strWidth(rv) - endOffset);
rgindaa09e7332012-08-17 12:49:51 -07002690};
2691
rginda4bba5e12012-06-20 16:15:30 -07002692/**
2693 * Copy the current selection to the system clipboard, then clear it after a
2694 * short delay.
2695 */
2696hterm.Terminal.prototype.copySelectionToClipboard = function() {
rgindaa09e7332012-08-17 12:49:51 -07002697 var text = this.getSelectionText();
2698 if (text != null)
2699 this.copyStringToClipboard(text);
rginda4bba5e12012-06-20 16:15:30 -07002700};
2701
rgindaf0090c92012-02-10 14:58:52 -08002702hterm.Terminal.prototype.overlaySize = function() {
2703 this.showOverlay(this.screenSize.width + 'x' + this.screenSize.height);
2704};
2705
rginda87b86462011-12-14 13:48:03 -08002706/**
2707 * Invoked by hterm.Terminal.Keyboard when a VT keystroke is detected.
2708 *
Robert Ginda8cb7d902013-06-20 14:37:18 -07002709 * @param {string} string The VT string representing the keystroke, in UTF-16.
rginda87b86462011-12-14 13:48:03 -08002710 */
2711hterm.Terminal.prototype.onVTKeystroke = function(string) {
rginda9f5222b2012-03-05 11:53:28 -08002712 if (this.scrollOnKeystroke_)
rginda87b86462011-12-14 13:48:03 -08002713 this.scrollPort_.scrollRowToBottom(this.getRowCount());
2714
Robert Ginda8cb7d902013-06-20 14:37:18 -07002715 this.io.onVTKeystroke(this.keyboard.encode(string));
rginda8ba33642011-12-14 12:31:31 -08002716};
2717
2718/**
rgindad5613292012-06-19 15:40:37 -07002719 * Add the terminalRow and terminalColumn properties to mouse events and
2720 * then forward on to onMouse().
2721 *
2722 * The terminalRow and terminalColumn properties contain the (row, column)
2723 * coordinates for the mouse event.
2724 */
2725hterm.Terminal.prototype.onMouse_ = function(e) {
rgindafaa74742012-08-21 13:34:03 -07002726 if (e.processedByTerminalHandler_) {
2727 // We register our event handlers on the document, as well as the cursor
2728 // and the scroll blocker. Mouse events that occur on the cursor or
2729 // scroll blocker will also appear on the document, but we don't want to
2730 // process them twice.
2731 //
2732 // We can't just prevent bubbling because that has other side effects, so
2733 // we decorate the event object with this property instead.
2734 return;
2735 }
2736
2737 e.processedByTerminalHandler_ = true;
2738
Robert Gindaeda48db2014-07-17 09:25:30 -07002739 // One based row/column stored on the mouse event.
2740 e.terminalRow = parseInt((e.clientY - this.scrollPort_.visibleRowTopMargin) /
2741 this.scrollPort_.characterSize.height) + 1;
2742 e.terminalColumn = parseInt(e.clientX /
2743 this.scrollPort_.characterSize.width) + 1;
2744
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002745 if (e.type == 'mousedown' && e.terminalColumn > this.screenSize.width) {
2746 // Mousedown in the scrollbar area.
rginda4bba5e12012-06-20 16:15:30 -07002747 return;
2748 }
2749
Robert Gindab837c052014-08-11 11:17:51 -07002750 if (this.options_.cursorVisible &&
2751 this.vt.mouseReport == this.vt.MOUSE_REPORT_DISABLED) {
2752 // If the cursor is visible and we're not sending mouse events to the
2753 // host app, then we want to hide the terminal cursor when the mouse
2754 // cursor is over top. This keeps the terminal cursor from interfering
2755 // with local text selection.
Robert Gindaeda48db2014-07-17 09:25:30 -07002756 if (e.terminalRow - 1 == this.screen_.cursorPosition.row &&
2757 e.terminalColumn - 1 == this.screen_.cursorPosition.column) {
2758 this.cursorNode_.style.display = 'none';
2759 } else if (this.cursorNode_.style.display == 'none') {
2760 this.cursorNode_.style.display = '';
2761 }
2762 }
rgindad5613292012-06-19 15:40:37 -07002763
Robert Ginda928cf632014-03-05 15:07:41 -08002764 if (e.type == 'mousedown') {
2765 if (e.altKey || this.vt.mouseReport == this.vt.MOUSE_REPORT_DISABLED) {
2766 // If VT mouse reporting is disabled, or has been defeated with
2767 // alt-mousedown, then the mouse will act on the local selection.
2768 this.reportMouseEvents_ = false;
2769 this.setSelectionEnabled(true);
2770 } else {
2771 // Otherwise we defer ownership of the mouse to the VT.
2772 this.reportMouseEvents_ = true;
Robert Ginda3ae37822014-05-15 13:05:35 -07002773 this.document_.getSelection().collapseToEnd();
Robert Ginda928cf632014-03-05 15:07:41 -08002774 this.setSelectionEnabled(false);
2775 e.preventDefault();
2776 }
2777 }
2778
2779 if (!this.reportMouseEvents_) {
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002780 if (e.type == 'dblclick') {
2781 this.screen_.expandSelection(this.document_.getSelection());
2782 hterm.copySelectionToClipboard(this.document_);
rgindad5613292012-06-19 15:40:37 -07002783 }
2784
Robert Ginda928cf632014-03-05 15:07:41 -08002785 if (e.type == 'mousedown' && e.which == this.mousePasteButton)
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002786 this.paste();
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002787
2788 if (e.type == 'mouseup' && e.which == 1 && this.copyOnSelect &&
2789 !this.document_.getSelection().isCollapsed) {
2790 hterm.copySelectionToClipboard(this.document_);
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002791 }
2792
2793 if ((e.type == 'mousemove' || e.type == 'mouseup') &&
2794 this.scrollBlockerNode_.engaged) {
2795 // Disengage the scroll-blocker after one of these events.
2796 this.scrollBlockerNode_.engaged = false;
2797 this.scrollBlockerNode_.style.top = '-99px';
2798 }
2799
Robert Ginda928cf632014-03-05 15:07:41 -08002800 } else /* if (this.reportMouseEvents) */ {
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002801 if (!this.scrollBlockerNode_.engaged) {
2802 if (e.type == 'mousedown') {
2803 // Move the scroll-blocker into place if we want to keep the scrollport
2804 // from scrolling.
2805 this.scrollBlockerNode_.engaged = true;
2806 this.scrollBlockerNode_.style.top = (e.clientY - 5) + 'px';
2807 this.scrollBlockerNode_.style.left = (e.clientX - 5) + 'px';
2808 } else if (e.type == 'mousemove') {
2809 // Oh. This means that drag-scroll was disabled AFTER the mouse down,
2810 // in which case it's too late to engage the scroll-blocker.
Robert Ginda3ae37822014-05-15 13:05:35 -07002811 this.document_.getSelection().collapseToEnd();
Robert Ginda4e24f8f2014-01-08 14:45:06 -08002812 e.preventDefault();
2813 }
2814 }
Robert Ginda928cf632014-03-05 15:07:41 -08002815
2816 this.onMouse(e);
rgindad5613292012-06-19 15:40:37 -07002817 }
2818
Robert Ginda928cf632014-03-05 15:07:41 -08002819 if (e.type == 'mouseup' && this.document_.getSelection().isCollapsed) {
2820 // Restore this on mouseup in case it was temporarily defeated with a
2821 // alt-mousedown. Only do this when the selection is empty so that
2822 // we don't immediately kill the users selection.
2823 this.reportMouseEvents_ = (this.vt.mouseReport !=
2824 this.vt.MOUSE_REPORT_DISABLED);
2825 }
rgindad5613292012-06-19 15:40:37 -07002826};
2827
2828/**
2829 * Clients should override this if they care to know about mouse events.
2830 *
2831 * The event parameter will be a normal DOM mouse click event with additional
2832 * 'terminalRow' and 'terminalColumn' properties.
2833 */
2834hterm.Terminal.prototype.onMouse = function(e) { };
2835
2836/**
rginda8e92a692012-05-20 19:37:20 -07002837 * React when focus changes.
2838 */
Rob Spies06533ba2014-04-24 11:20:37 -07002839hterm.Terminal.prototype.onFocusChange_ = function(focused) {
2840 this.cursorNode_.setAttribute('focus', focused);
Robert Ginda830583c2013-08-07 13:20:46 -07002841 this.restyleCursor_();
Michael Kelly485ecd12014-06-09 11:41:56 -04002842 if (focused === true)
2843 this.closeBellNotifications_();
rginda8e92a692012-05-20 19:37:20 -07002844};
2845
2846/**
rginda8ba33642011-12-14 12:31:31 -08002847 * React when the ScrollPort is scrolled.
2848 */
2849hterm.Terminal.prototype.onScroll_ = function() {
2850 this.scheduleSyncCursorPosition_();
2851};
2852
2853/**
rginda9846e2f2012-01-27 13:53:33 -08002854 * React when text is pasted into the scrollPort.
2855 */
2856hterm.Terminal.prototype.onPaste_ = function(e) {
Robert Gindaa063b202014-07-21 11:08:25 -07002857 var data = e.text.replace(/\n/mg, '\r');
Connor Hegartyf525ceb2014-09-03 13:36:03 -07002858 data = this.keyboard.encode(data);
Robert Gindaa063b202014-07-21 11:08:25 -07002859 if (this.options_.bracketedPaste)
2860 data = '\x1b[200~' + data + '\x1b[201~';
2861
2862 this.io.sendString(data);
rginda9846e2f2012-01-27 13:53:33 -08002863};
2864
2865/**
rgindaa09e7332012-08-17 12:49:51 -07002866 * React when the user tries to copy from the scrollPort.
2867 */
2868hterm.Terminal.prototype.onCopy_ = function(e) {
Rob Spies0bec09b2014-06-06 15:58:09 -07002869 if (!this.useDefaultWindowCopy) {
2870 e.preventDefault();
2871 setTimeout(this.copySelectionToClipboard.bind(this), 0);
2872 }
rgindaa09e7332012-08-17 12:49:51 -07002873};
2874
2875/**
rginda8ba33642011-12-14 12:31:31 -08002876 * React when the ScrollPort is resized.
rgindac9bc5502012-01-18 11:48:44 -08002877 *
2878 * Note: This function should not directly contain code that alters the internal
2879 * state of the terminal. That kind of code belongs in realizeWidth or
2880 * realizeHeight, so that it can be executed synchronously in the case of a
2881 * programmatic width change.
rginda8ba33642011-12-14 12:31:31 -08002882 */
2883hterm.Terminal.prototype.onResize_ = function() {
Robert Ginda19f61292014-03-04 14:07:57 -08002884 var columnCount = Math.floor(this.scrollPort_.getScreenWidth() /
rginda35c456b2012-02-09 17:29:05 -08002885 this.scrollPort_.characterSize.width);
Rob Spiesf4e90e82015-01-28 12:10:13 -08002886 var rowCount = lib.f.smartFloorDivide(this.scrollPort_.getScreenHeight(),
rginda35c456b2012-02-09 17:29:05 -08002887 this.scrollPort_.characterSize.height);
2888
Robert Ginda4e83f3a2012-09-04 15:25:25 -07002889 if (columnCount <= 0 || rowCount <= 0) {
rginda35c456b2012-02-09 17:29:05 -08002890 // We avoid these situations since they happen sometimes when the terminal
Robert Ginda4e83f3a2012-09-04 15:25:25 -07002891 // gets removed from the document or during the initial load, and we can't
2892 // deal with that.
rginda35c456b2012-02-09 17:29:05 -08002893 return;
2894 }
2895
rgindaa8ba17d2012-08-15 14:41:10 -07002896 var isNewSize = (columnCount != this.screenSize.width ||
2897 rowCount != this.screenSize.height);
2898
2899 // We do this even if the size didn't change, just to be sure everything is
2900 // in sync.
Dmitry Polukhinbb2ef712012-01-19 19:00:37 +04002901 this.realizeSize_(columnCount, rowCount);
rgindaf522ce02012-04-17 17:49:17 -07002902 this.showZoomWarning_(this.scrollPort_.characterSize.zoomFactor != 1);
rgindaa8ba17d2012-08-15 14:41:10 -07002903
2904 if (isNewSize)
2905 this.overlaySize();
2906
Robert Gindafb1be6a2013-12-11 11:56:22 -08002907 this.restyleCursor_();
rgindaa8ba17d2012-08-15 14:41:10 -07002908 this.scheduleSyncCursorPosition_();
rginda8ba33642011-12-14 12:31:31 -08002909};
2910
2911/**
2912 * Service the cursor blink timeout.
2913 */
2914hterm.Terminal.prototype.onCursorBlink_ = function() {
Robert Gindaea2183e2014-07-17 09:51:51 -07002915 if (!this.options_.cursorBlink) {
2916 delete this.timeouts_.cursorBlink;
2917 return;
2918 }
2919
Robert Ginda830583c2013-08-07 13:20:46 -07002920 if (this.cursorNode_.getAttribute('focus') == 'false' ||
2921 this.cursorNode_.style.opacity == '0') {
rginda87b86462011-12-14 13:48:03 -08002922 this.cursorNode_.style.opacity = '1';
Robert Gindaea2183e2014-07-17 09:51:51 -07002923 this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_,
2924 this.cursorBlinkCycle_[0]);
rginda8ba33642011-12-14 12:31:31 -08002925 } else {
rginda87b86462011-12-14 13:48:03 -08002926 this.cursorNode_.style.opacity = '0';
Robert Gindaea2183e2014-07-17 09:51:51 -07002927 this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_,
2928 this.cursorBlinkCycle_[1]);
rginda8ba33642011-12-14 12:31:31 -08002929 }
2930};
David Reveman8f552492012-03-28 12:18:41 -04002931
2932/**
2933 * Set the scrollbar-visible mode bit.
2934 *
2935 * If scrollbar-visible is on, the vertical scrollbar will be visible.
2936 * Otherwise it will not.
2937 *
2938 * Defaults to on.
2939 *
2940 * @param {boolean} state True to set scrollbar-visible mode, false to unset.
2941 */
2942hterm.Terminal.prototype.setScrollbarVisible = function(state) {
2943 this.scrollPort_.setScrollbarVisible(state);
2944};
Michael Kelly485ecd12014-06-09 11:41:56 -04002945
2946/**
Rob Spies49039e52014-12-17 13:40:04 -08002947 * Set the scroll wheel move multiplier. This will affect how fast the page
2948 * scrolls on mousewheel events.
2949 *
2950 * Defaults to 1.
2951 *
2952 * @param {number} multiplier.
2953 */
2954hterm.Terminal.prototype.setScrollWheelMoveMultipler = function(multiplier) {
2955 this.scrollPort_.setScrollWheelMoveMultipler(multiplier);
2956};
2957
2958/**
Michael Kelly485ecd12014-06-09 11:41:56 -04002959 * Close all web notifications created by terminal bells.
2960 */
2961hterm.Terminal.prototype.closeBellNotifications_ = function() {
2962 this.bellNotificationList_.forEach(function(n) {
2963 n.close();
2964 });
2965 this.bellNotificationList_.length = 0;
2966};