rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 5 | 'use strict'; |
| 6 | |
Masaya Suzuki | 273aa98 | 2014-05-31 07:25:55 +0900 | [diff] [blame] | 7 | lib.rtdep('lib.colors', 'lib.PreferenceManager', 'lib.resource', 'lib.wc', |
Rob Spies | f4e90e8 | 2015-01-28 12:10:13 -0800 | [diff] [blame] | 8 | 'lib.f', 'hterm.Keyboard', 'hterm.Options', 'hterm.PreferenceManager', |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 9 | 'hterm.Screen', 'hterm.ScrollPort', 'hterm.Size', |
| 10 | 'hterm.TextAttributes', 'hterm.VT'); |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 11 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 12 | /** |
| 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). |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 28 | * |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 29 | * @param {string} opt_profileId Optional preference profile name. If not |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 30 | * provided, defaults to 'default'. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 31 | */ |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 32 | hterm.Terminal = function(opt_profileId) { |
| 33 | this.profileId_ = null; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 34 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 35 | // 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 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 42 | // 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 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 48 | // The scroll port we'll be using to display the visible rows. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 49 | this.scrollPort_ = new hterm.ScrollPort(this); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 50 | this.scrollPort_.subscribe('resize', this.onResize_.bind(this)); |
| 51 | this.scrollPort_.subscribe('scroll', this.onScroll_.bind(this)); |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 52 | this.scrollPort_.subscribe('paste', this.onPaste_.bind(this)); |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 53 | this.scrollPort_.onCopy = this.onCopy_.bind(this); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 54 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 55 | // The div that contains this terminal. |
| 56 | this.div_ = null; |
| 57 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 58 | // 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; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 62 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 63 | // The rows that have scrolled off screen and are no longer addressable. |
| 64 | this.scrollbackRows_ = []; |
| 65 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 66 | // Saved tab stops. |
| 67 | this.tabStops_ = []; |
| 68 | |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 69 | // 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 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 73 | // 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 Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 81 | // 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 Ginda | ea2183e | 2014-07-17 09:51:51 -0700 | [diff] [blame] | 87 | // 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 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 94 | // These prefs are cached so we don't have to read from local storage with |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 95 | // each output and keystroke. They are initialized by the preference manager. |
Robert Ginda | 8cb7d90 | 2013-06-20 14:37:18 -0700 | [diff] [blame] | 96 | this.backgroundColor_ = null; |
| 97 | this.foregroundColor_ = null; |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 98 | this.scrollOnOutput_ = null; |
| 99 | this.scrollOnKeystroke_ = null; |
Mike Frysinger | 3c9fa07 | 2017-07-13 10:21:13 -0400 | [diff] [blame] | 100 | this.scrollWheelArrowKeys_ = null; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 101 | |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 102 | // True if we should override mouse event reporting to allow local selection. |
| 103 | this.defeatMouseReports_ = false; |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 104 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 105 | // Terminal bell sound. |
| 106 | this.bellAudio_ = this.document_.createElement('audio'); |
Mike Frysinger | d826f1a | 2017-07-06 16:20:06 -0400 | [diff] [blame] | 107 | this.bellAudio_.id = 'hterm:bell-audio'; |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 108 | this.bellAudio_.setAttribute('preload', 'auto'); |
| 109 | |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 110 | // All terminal bell notifications that have been generated (not necessarily |
| 111 | // shown). |
| 112 | this.bellNotificationList_ = []; |
| 113 | |
| 114 | // Whether we have permission to display notifications. |
| 115 | this.desktopNotificationBell_ = false; |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 116 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 117 | // Cursor position and attributes saved with DECSC. |
| 118 | this.savedOptions_ = {}; |
| 119 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 120 | // The current mode bits for the terminal. |
| 121 | this.options_ = new hterm.Options(); |
| 122 | |
| 123 | // Timeouts we might need to clear. |
| 124 | this.timeouts_ = {}; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 125 | |
| 126 | // The VT escape sequence interpreter. |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 127 | this.vt = new hterm.VT(this); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 128 | |
Mike Frysinger | a2cacaa | 2017-11-29 13:51:09 -0800 | [diff] [blame] | 129 | this.saveCursorAndState(true); |
| 130 | |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 131 | // The keyboard handler. |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 132 | this.keyboard = new hterm.Keyboard(this); |
| 133 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 134 | // General IO interface that can be given to third parties without exposing |
| 135 | // the entire terminal object. |
| 136 | this.io = new hterm.Terminal.IO(this); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 137 | |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 138 | // True if mouse-click-drag should scroll the terminal. |
| 139 | this.enableMouseDragScroll = true; |
| 140 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 141 | this.copyOnSelect = null; |
Mike Frysinger | 847577f | 2017-05-23 23:25:57 -0400 | [diff] [blame] | 142 | this.mouseRightClickPaste = null; |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 143 | this.mousePasteButton = null; |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 144 | |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 145 | // Whether to use the default window copy behavior. |
Rob Spies | 0bec09b | 2014-06-06 15:58:09 -0700 | [diff] [blame] | 146 | this.useDefaultWindowCopy = false; |
| 147 | |
| 148 | this.clearSelectionAfterCopy = true; |
| 149 | |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 150 | this.realizeSize_(80, 24); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 151 | this.setDefaultTabStops(); |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 152 | |
Gabriel Holodak | e8a09be | 2017-10-10 01:07:11 -0400 | [diff] [blame] | 153 | this.reportFocus = false; |
| 154 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 155 | this.setProfile(opt_profileId || 'default', |
Evan Jones | 5f9df81 | 2016-12-06 09:38:58 -0500 | [diff] [blame] | 156 | function() { this.onTerminalReady(); }.bind(this)); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | /** |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 160 | * Possible cursor shapes. |
| 161 | */ |
| 162 | hterm.Terminal.cursorShape = { |
| 163 | BLOCK: 'BLOCK', |
| 164 | BEAM: 'BEAM', |
| 165 | UNDERLINE: 'UNDERLINE' |
| 166 | }; |
| 167 | |
| 168 | /** |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 169 | * Clients should override this to be notified when the terminal is ready |
| 170 | * for use. |
| 171 | * |
| 172 | * The terminal initialization is asynchronous, and shouldn't be used before |
| 173 | * this method is called. |
| 174 | */ |
| 175 | hterm.Terminal.prototype.onTerminalReady = function() { }; |
| 176 | |
| 177 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 178 | * Default tab with of 8 to match xterm. |
| 179 | */ |
| 180 | hterm.Terminal.prototype.tabWidth = 8; |
| 181 | |
| 182 | /** |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 183 | * Select a preference profile. |
| 184 | * |
| 185 | * This will load the terminal preferences for the given profile name and |
| 186 | * associate subsequent preference changes with the new preference profile. |
| 187 | * |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 188 | * @param {string} profileId The name of the preference profile. Forward slash |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 189 | * characters will be removed from the name. |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 190 | * @param {function} opt_callback Optional callback to invoke when the profile |
| 191 | * transition is complete. |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 192 | */ |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 193 | hterm.Terminal.prototype.setProfile = function(profileId, opt_callback) { |
| 194 | this.profileId_ = profileId.replace(/\//g, ''); |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 195 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 196 | var terminal = this; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 197 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 198 | if (this.prefs_) |
| 199 | this.prefs_.deactivate(); |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 200 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 201 | this.prefs_ = new hterm.PreferenceManager(this.profileId_); |
| 202 | this.prefs_.addObservers(null, { |
Robert Ginda | 034ffa7 | 2015-02-26 14:02:37 -0800 | [diff] [blame] | 203 | 'alt-gr-mode': function(v) { |
| 204 | if (v == null) { |
| 205 | if (navigator.language.toLowerCase() == 'en-us') { |
| 206 | v = 'none'; |
| 207 | } else { |
| 208 | v = 'right-alt'; |
| 209 | } |
| 210 | } else if (typeof v == 'string') { |
| 211 | v = v.toLowerCase(); |
| 212 | } else { |
| 213 | v = 'none'; |
| 214 | } |
| 215 | |
| 216 | if (!/^(none|ctrl-alt|left-alt|right-alt)$/.test(v)) |
| 217 | v = 'none'; |
| 218 | |
| 219 | terminal.keyboard.altGrMode = v; |
| 220 | }, |
| 221 | |
Andrew de los Reyes | 574e10e | 2013-04-04 09:31:57 -0700 | [diff] [blame] | 222 | 'alt-backspace-is-meta-backspace': function(v) { |
| 223 | terminal.keyboard.altBackspaceIsMetaBackspace = v; |
| 224 | }, |
| 225 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 226 | 'alt-is-meta': function(v) { |
| 227 | terminal.keyboard.altIsMeta = v; |
| 228 | }, |
| 229 | |
| 230 | 'alt-sends-what': function(v) { |
| 231 | if (!/^(escape|8-bit|browser-key)$/.test(v)) |
| 232 | v = 'escape'; |
| 233 | |
| 234 | terminal.keyboard.altSendsWhat = v; |
| 235 | }, |
| 236 | |
| 237 | 'audible-bell-sound': function(v) { |
Robert Ginda | b4839c2 | 2013-02-28 16:52:10 -0800 | [diff] [blame] | 238 | var ary = v.match(/^lib-resource:(\S+)/); |
| 239 | if (ary) { |
| 240 | terminal.bellAudio_.setAttribute('src', |
| 241 | lib.resource.getDataUrl(ary[1])); |
| 242 | } else { |
| 243 | terminal.bellAudio_.setAttribute('src', v); |
| 244 | } |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 245 | }, |
| 246 | |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 247 | 'desktop-notification-bell': function(v) { |
| 248 | if (v && Notification) { |
Robert Ginda | 348dc2b | 2014-06-24 14:42:23 -0700 | [diff] [blame] | 249 | terminal.desktopNotificationBell_ = |
Michael Kelly | b806786 | 2014-06-26 12:59:47 -0400 | [diff] [blame] | 250 | Notification.permission === 'granted'; |
| 251 | if (!terminal.desktopNotificationBell_) { |
| 252 | // Note: We don't call Notification.requestPermission here because |
| 253 | // Chrome requires the call be the result of a user action (such as an |
| 254 | // onclick handler), and pref listeners are run asynchronously. |
| 255 | // |
| 256 | // A way of working around this would be to display a dialog in the |
| 257 | // terminal with a "click-to-request-permission" button. |
| 258 | console.warn('desktop-notification-bell is true but we do not have ' + |
| 259 | 'permission to display notifications.'); |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 260 | } |
| 261 | } else { |
| 262 | terminal.desktopNotificationBell_ = false; |
| 263 | } |
| 264 | }, |
| 265 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 266 | 'background-color': function(v) { |
| 267 | terminal.setBackgroundColor(v); |
| 268 | }, |
| 269 | |
| 270 | 'background-image': function(v) { |
| 271 | terminal.scrollPort_.setBackgroundImage(v); |
| 272 | }, |
| 273 | |
| 274 | 'background-size': function(v) { |
| 275 | terminal.scrollPort_.setBackgroundSize(v); |
| 276 | }, |
| 277 | |
| 278 | 'background-position': function(v) { |
| 279 | terminal.scrollPort_.setBackgroundPosition(v); |
| 280 | }, |
| 281 | |
| 282 | 'backspace-sends-backspace': function(v) { |
| 283 | terminal.keyboard.backspaceSendsBackspace = v; |
| 284 | }, |
| 285 | |
Brad Town | 18654b6 | 2015-03-12 00:27:45 -0700 | [diff] [blame] | 286 | 'character-map-overrides': function(v) { |
| 287 | if (!(v == null || v instanceof Object)) { |
| 288 | console.warn('Preference character-map-modifications is not an ' + |
| 289 | 'object: ' + v); |
| 290 | return; |
| 291 | } |
| 292 | |
Mike Frysinger | 095d406 | 2017-06-14 00:29:48 -0700 | [diff] [blame] | 293 | terminal.vt.characterMaps.reset(); |
| 294 | terminal.vt.characterMaps.setOverrides(v); |
Brad Town | 18654b6 | 2015-03-12 00:27:45 -0700 | [diff] [blame] | 295 | }, |
| 296 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 297 | 'cursor-blink': function(v) { |
| 298 | terminal.setCursorBlink(!!v); |
| 299 | }, |
| 300 | |
Robert Ginda | ea2183e | 2014-07-17 09:51:51 -0700 | [diff] [blame] | 301 | 'cursor-blink-cycle': function(v) { |
| 302 | if (v instanceof Array && |
| 303 | typeof v[0] == 'number' && |
| 304 | typeof v[1] == 'number') { |
| 305 | terminal.cursorBlinkCycle_ = v; |
| 306 | } else if (typeof v == 'number') { |
| 307 | terminal.cursorBlinkCycle_ = [v, v]; |
| 308 | } else { |
| 309 | // Fast blink indicates an error. |
| 310 | terminal.cursorBlinkCycle_ = [100, 100]; |
| 311 | } |
| 312 | }, |
| 313 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 314 | 'cursor-color': function(v) { |
| 315 | terminal.setCursorColor(v); |
| 316 | }, |
| 317 | |
| 318 | 'color-palette-overrides': function(v) { |
| 319 | if (!(v == null || v instanceof Object || v instanceof Array)) { |
| 320 | console.warn('Preference color-palette-overrides is not an array or ' + |
| 321 | 'object: ' + v); |
| 322 | return; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 323 | } |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 324 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 325 | lib.colors.colorPalette = lib.colors.stockColorPalette.concat(); |
rginda | 39bdf6f | 2012-04-10 16:50:55 -0700 | [diff] [blame] | 326 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 327 | if (v) { |
| 328 | for (var key in v) { |
| 329 | var i = parseInt(key); |
| 330 | if (isNaN(i) || i < 0 || i > 255) { |
| 331 | console.log('Invalid value in palette: ' + key + ': ' + v[key]); |
| 332 | continue; |
| 333 | } |
| 334 | |
| 335 | if (v[i]) { |
| 336 | var rgb = lib.colors.normalizeCSS(v[i]); |
| 337 | if (rgb) |
| 338 | lib.colors.colorPalette[i] = rgb; |
| 339 | } |
| 340 | } |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 341 | } |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 342 | |
Evan Jones | 5f9df81 | 2016-12-06 09:38:58 -0500 | [diff] [blame] | 343 | terminal.primaryScreen_.textAttributes.resetColorPalette(); |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 344 | terminal.alternateScreen_.textAttributes.resetColorPalette(); |
| 345 | }, |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 346 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 347 | 'copy-on-select': function(v) { |
| 348 | terminal.copyOnSelect = !!v; |
| 349 | }, |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 350 | |
Rob Spies | 0bec09b | 2014-06-06 15:58:09 -0700 | [diff] [blame] | 351 | 'use-default-window-copy': function(v) { |
| 352 | terminal.useDefaultWindowCopy = !!v; |
| 353 | }, |
| 354 | |
| 355 | 'clear-selection-after-copy': function(v) { |
| 356 | terminal.clearSelectionAfterCopy = !!v; |
| 357 | }, |
| 358 | |
Robert Ginda | 7e5e952 | 2014-03-14 12:23:58 -0700 | [diff] [blame] | 359 | 'ctrl-plus-minus-zero-zoom': function(v) { |
| 360 | terminal.keyboard.ctrlPlusMinusZeroZoom = v; |
| 361 | }, |
| 362 | |
Robert Ginda | fb5a3f9 | 2014-05-13 14:12:00 -0700 | [diff] [blame] | 363 | 'ctrl-c-copy': function(v) { |
| 364 | terminal.keyboard.ctrlCCopy = v; |
| 365 | }, |
| 366 | |
Leonardo Mesquita | 61e7c31 | 2014-01-04 12:53:12 +0100 | [diff] [blame] | 367 | 'ctrl-v-paste': function(v) { |
| 368 | terminal.keyboard.ctrlVPaste = v; |
Rob Spies | e52e184 | 2014-07-10 15:32:51 -0700 | [diff] [blame] | 369 | terminal.scrollPort_.setCtrlVPaste(v); |
Leonardo Mesquita | 61e7c31 | 2014-01-04 12:53:12 +0100 | [diff] [blame] | 370 | }, |
| 371 | |
Masaya Suzuki | 273aa98 | 2014-05-31 07:25:55 +0900 | [diff] [blame] | 372 | 'east-asian-ambiguous-as-two-column': function(v) { |
| 373 | lib.wc.regardCjkAmbiguous = v; |
| 374 | }, |
| 375 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 376 | 'enable-8-bit-control': function(v) { |
| 377 | terminal.vt.enable8BitControl = !!v; |
| 378 | }, |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 379 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 380 | 'enable-bold': function(v) { |
| 381 | terminal.syncBoldSafeState(); |
| 382 | }, |
Philip Douglass | 959b49d | 2012-05-30 13:29:29 -0400 | [diff] [blame] | 383 | |
Robert Ginda | 3e278d7 | 2014-03-25 13:18:51 -0700 | [diff] [blame] | 384 | 'enable-bold-as-bright': function(v) { |
| 385 | terminal.primaryScreen_.textAttributes.enableBoldAsBright = !!v; |
| 386 | terminal.alternateScreen_.textAttributes.enableBoldAsBright = !!v; |
| 387 | }, |
| 388 | |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 389 | 'enable-blink': function(v) { |
| 390 | terminal.syncBlinkState(); |
| 391 | }, |
| 392 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 393 | 'enable-clipboard-write': function(v) { |
| 394 | terminal.vt.enableClipboardWrite = !!v; |
| 395 | }, |
Philip Douglass | 959b49d | 2012-05-30 13:29:29 -0400 | [diff] [blame] | 396 | |
Robert Ginda | 3755e75 | 2013-05-31 13:34:09 -0700 | [diff] [blame] | 397 | 'enable-dec12': function(v) { |
| 398 | terminal.vt.enableDec12 = !!v; |
| 399 | }, |
| 400 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 401 | 'font-family': function(v) { |
| 402 | terminal.syncFontFamily(); |
| 403 | }, |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 404 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 405 | 'font-size': function(v) { |
| 406 | terminal.setFontSize(v); |
| 407 | }, |
rginda | 9875d90 | 2012-08-20 16:21:57 -0700 | [diff] [blame] | 408 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 409 | 'font-smoothing': function(v) { |
| 410 | terminal.syncFontFamily(); |
| 411 | }, |
rginda | de84e38 | 2012-04-20 15:39:31 -0700 | [diff] [blame] | 412 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 413 | 'foreground-color': function(v) { |
| 414 | terminal.setForegroundColor(v); |
| 415 | }, |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 416 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 417 | 'home-keys-scroll': function(v) { |
| 418 | terminal.keyboard.homeKeysScroll = v; |
| 419 | }, |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 420 | |
Robert Ginda | a816569 | 2015-06-15 14:46:31 -0700 | [diff] [blame] | 421 | 'keybindings': function(v) { |
| 422 | terminal.keyboard.bindings.clear(); |
| 423 | |
| 424 | if (!v) |
| 425 | return; |
| 426 | |
| 427 | if (!(v instanceof Object)) { |
| 428 | console.error('Error in keybindings preference: Expected object'); |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | try { |
| 433 | terminal.keyboard.bindings.addBindings(v); |
| 434 | } catch (ex) { |
| 435 | console.error('Error in keybindings preference: ' + ex); |
| 436 | } |
| 437 | }, |
| 438 | |
Andrew de los Reyes | 6af23ae | 2013-04-04 14:17:50 -0700 | [diff] [blame] | 439 | 'media-keys-are-fkeys': function(v) { |
| 440 | terminal.keyboard.mediaKeysAreFKeys = v; |
| 441 | }, |
| 442 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 443 | 'meta-sends-escape': function(v) { |
| 444 | terminal.keyboard.metaSendsEscape = v; |
| 445 | }, |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 446 | |
Mike Frysinger | 847577f | 2017-05-23 23:25:57 -0400 | [diff] [blame] | 447 | 'mouse-right-click-paste': function(v) { |
| 448 | terminal.mouseRightClickPaste = v; |
| 449 | }, |
| 450 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 451 | 'mouse-paste-button': function(v) { |
| 452 | terminal.syncMousePasteButton(); |
| 453 | }, |
rginda | a8ba17d | 2012-08-15 14:41:10 -0700 | [diff] [blame] | 454 | |
Robert Ginda | e76aa9f | 2014-03-14 12:29:12 -0700 | [diff] [blame] | 455 | 'page-keys-scroll': function(v) { |
| 456 | terminal.keyboard.pageKeysScroll = v; |
| 457 | }, |
| 458 | |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 459 | 'pass-alt-number': function(v) { |
| 460 | if (v == null) { |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 461 | // Let Alt-1..9 pass to the browser (to control tab switching) on |
| 462 | // non-OS X systems, or if hterm is not opened in an app window. |
Mike Frysinger | ee81a00 | 2017-12-12 16:14:53 -0500 | [diff] [blame^] | 463 | v = (hterm.os != 'mac' && hterm.windowType != 'popup'); |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | terminal.passAltNumber = v; |
| 467 | }, |
| 468 | |
| 469 | 'pass-ctrl-number': function(v) { |
| 470 | if (v == null) { |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 471 | // Let Ctrl-1..9 pass to the browser (to control tab switching) on |
| 472 | // non-OS X systems, or if hterm is not opened in an app window. |
Mike Frysinger | ee81a00 | 2017-12-12 16:14:53 -0500 | [diff] [blame^] | 473 | v = (hterm.os != 'mac' && hterm.windowType != 'popup'); |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | terminal.passCtrlNumber = v; |
| 477 | }, |
| 478 | |
| 479 | 'pass-meta-number': function(v) { |
| 480 | if (v == null) { |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 481 | // Let Meta-1..9 pass to the browser (to control tab switching) on |
| 482 | // OS X systems, or if hterm is not opened in an app window. |
Mike Frysinger | ee81a00 | 2017-12-12 16:14:53 -0500 | [diff] [blame^] | 483 | v = (hterm.os == 'mac' && hterm.windowType != 'popup'); |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | terminal.passMetaNumber = v; |
| 487 | }, |
| 488 | |
Marius Schilder | 77857b3 | 2014-05-14 16:21:26 -0700 | [diff] [blame] | 489 | 'pass-meta-v': function(v) { |
Marius Schilder | 1a56781 | 2014-05-15 20:30:02 -0700 | [diff] [blame] | 490 | terminal.keyboard.passMetaV = v; |
Marius Schilder | 77857b3 | 2014-05-14 16:21:26 -0700 | [diff] [blame] | 491 | }, |
| 492 | |
Robert Ginda | 8cb7d90 | 2013-06-20 14:37:18 -0700 | [diff] [blame] | 493 | 'receive-encoding': function(v) { |
| 494 | if (!(/^(utf-8|raw)$/).test(v)) { |
| 495 | console.warn('Invalid value for "receive-encoding": ' + v); |
| 496 | v = 'utf-8'; |
| 497 | } |
| 498 | |
| 499 | terminal.vt.characterEncoding = v; |
| 500 | }, |
| 501 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 502 | 'scroll-on-keystroke': function(v) { |
| 503 | terminal.scrollOnKeystroke_ = v; |
| 504 | }, |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 505 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 506 | 'scroll-on-output': function(v) { |
| 507 | terminal.scrollOnOutput_ = v; |
| 508 | }, |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 509 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 510 | 'scrollbar-visible': function(v) { |
| 511 | terminal.setScrollbarVisible(v); |
| 512 | }, |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 513 | |
Mike Frysinger | 3c9fa07 | 2017-07-13 10:21:13 -0400 | [diff] [blame] | 514 | 'scroll-wheel-may-send-arrow-keys': function(v) { |
| 515 | terminal.scrollWheelArrowKeys_ = v; |
| 516 | }, |
| 517 | |
Rob Spies | 49039e5 | 2014-12-17 13:40:04 -0800 | [diff] [blame] | 518 | 'scroll-wheel-move-multiplier': function(v) { |
| 519 | terminal.setScrollWheelMoveMultipler(v); |
| 520 | }, |
| 521 | |
Robert Ginda | 8cb7d90 | 2013-06-20 14:37:18 -0700 | [diff] [blame] | 522 | 'send-encoding': function(v) { |
| 523 | if (!(/^(utf-8|raw)$/).test(v)) { |
| 524 | console.warn('Invalid value for "send-encoding": ' + v); |
| 525 | v = 'utf-8'; |
| 526 | } |
| 527 | |
| 528 | terminal.keyboard.characterEncoding = v; |
| 529 | }, |
| 530 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 531 | 'shift-insert-paste': function(v) { |
| 532 | terminal.keyboard.shiftInsertPaste = v; |
| 533 | }, |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 534 | |
Mike Frysinger | a776892 | 2017-07-28 15:00:12 -0400 | [diff] [blame] | 535 | 'terminal-encoding': function(v) { |
Mike Frysinger | a1371e1 | 2017-08-17 01:37:17 -0400 | [diff] [blame] | 536 | terminal.vt.setEncoding(v); |
Mike Frysinger | a776892 | 2017-07-28 15:00:12 -0400 | [diff] [blame] | 537 | }, |
| 538 | |
Robert Ginda | e76aa9f | 2014-03-14 12:29:12 -0700 | [diff] [blame] | 539 | 'user-css': function(v) { |
Mike Frysinger | 08bad43 | 2017-04-24 00:50:54 -0400 | [diff] [blame] | 540 | terminal.scrollPort_.setUserCssUrl(v); |
| 541 | }, |
| 542 | |
| 543 | 'user-css-text': function(v) { |
| 544 | terminal.scrollPort_.setUserCssText(v); |
| 545 | }, |
Mike Frysinger | 664e999 | 2017-05-19 01:24:24 -0400 | [diff] [blame] | 546 | |
| 547 | 'word-break-match-left': function(v) { |
| 548 | terminal.primaryScreen_.wordBreakMatchLeft = v; |
| 549 | terminal.alternateScreen_.wordBreakMatchLeft = v; |
| 550 | }, |
| 551 | |
| 552 | 'word-break-match-right': function(v) { |
| 553 | terminal.primaryScreen_.wordBreakMatchRight = v; |
| 554 | terminal.alternateScreen_.wordBreakMatchRight = v; |
| 555 | }, |
| 556 | |
| 557 | 'word-break-match-middle': function(v) { |
| 558 | terminal.primaryScreen_.wordBreakMatchMiddle = v; |
| 559 | terminal.alternateScreen_.wordBreakMatchMiddle = v; |
| 560 | }, |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 561 | }); |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 562 | |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 563 | this.prefs_.readStorage(function() { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 564 | this.prefs_.notifyAll(); |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 565 | |
| 566 | if (opt_callback) |
| 567 | opt_callback(); |
| 568 | }.bind(this)); |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 569 | }; |
| 570 | |
Rob Spies | 5695341 | 2014-04-28 14:09:47 -0700 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * Returns the preferences manager used for configuring this terminal. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 574 | * |
| 575 | * @return {hterm.PreferenceManager} |
Rob Spies | 5695341 | 2014-04-28 14:09:47 -0700 | [diff] [blame] | 576 | */ |
| 577 | hterm.Terminal.prototype.getPrefs = function() { |
| 578 | return this.prefs_; |
| 579 | }; |
| 580 | |
Robert Ginda | a063b20 | 2014-07-21 11:08:25 -0700 | [diff] [blame] | 581 | /** |
| 582 | * Enable or disable bracketed paste mode. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 583 | * |
| 584 | * @param {boolean} state The value to set. |
Robert Ginda | a063b20 | 2014-07-21 11:08:25 -0700 | [diff] [blame] | 585 | */ |
| 586 | hterm.Terminal.prototype.setBracketedPaste = function(state) { |
| 587 | this.options_.bracketedPaste = state; |
| 588 | }; |
Rob Spies | 5695341 | 2014-04-28 14:09:47 -0700 | [diff] [blame] | 589 | |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 590 | /** |
| 591 | * Set the color for the cursor. |
| 592 | * |
| 593 | * If you want this setting to persist, set it through prefs_, rather than |
| 594 | * with this method. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 595 | * |
| 596 | * @param {string} color The color to set. |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 597 | */ |
| 598 | hterm.Terminal.prototype.setCursorColor = function(color) { |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 599 | this.cursorColor_ = color; |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 600 | this.cursorNode_.style.backgroundColor = color; |
| 601 | this.cursorNode_.style.borderColor = color; |
| 602 | }; |
| 603 | |
| 604 | /** |
| 605 | * Return the current cursor color as a string. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 606 | * @return {string} |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 607 | */ |
| 608 | hterm.Terminal.prototype.getCursorColor = function() { |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 609 | return this.cursorColor_; |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 610 | }; |
| 611 | |
| 612 | /** |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 613 | * Enable or disable mouse based text selection in the terminal. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 614 | * |
| 615 | * @param {boolean} state The value to set. |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 616 | */ |
| 617 | hterm.Terminal.prototype.setSelectionEnabled = function(state) { |
| 618 | this.enableMouseDragScroll = state; |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 619 | }; |
| 620 | |
| 621 | /** |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 622 | * Set the background color. |
| 623 | * |
| 624 | * If you want this setting to persist, set it through prefs_, rather than |
| 625 | * with this method. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 626 | * |
| 627 | * @param {string} color The color to set. |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 628 | */ |
| 629 | hterm.Terminal.prototype.setBackgroundColor = function(color) { |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 630 | this.backgroundColor_ = lib.colors.normalizeCSS(color); |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 631 | this.primaryScreen_.textAttributes.setDefaults( |
| 632 | this.foregroundColor_, this.backgroundColor_); |
| 633 | this.alternateScreen_.textAttributes.setDefaults( |
| 634 | this.foregroundColor_, this.backgroundColor_); |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 635 | this.scrollPort_.setBackgroundColor(color); |
| 636 | }; |
| 637 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 638 | /** |
| 639 | * Return the current terminal background color. |
| 640 | * |
| 641 | * Intended for use by other classes, so we don't have to expose the entire |
| 642 | * prefs_ object. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 643 | * |
| 644 | * @return {string} |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 645 | */ |
| 646 | hterm.Terminal.prototype.getBackgroundColor = function() { |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 647 | return this.backgroundColor_; |
| 648 | }; |
| 649 | |
| 650 | /** |
| 651 | * Set the foreground color. |
| 652 | * |
| 653 | * If you want this setting to persist, set it through prefs_, rather than |
| 654 | * with this method. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 655 | * |
| 656 | * @param {string} color The color to set. |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 657 | */ |
| 658 | hterm.Terminal.prototype.setForegroundColor = function(color) { |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 659 | this.foregroundColor_ = lib.colors.normalizeCSS(color); |
Robert Ginda | 57f03b4 | 2012-09-13 11:02:48 -0700 | [diff] [blame] | 660 | this.primaryScreen_.textAttributes.setDefaults( |
| 661 | this.foregroundColor_, this.backgroundColor_); |
| 662 | this.alternateScreen_.textAttributes.setDefaults( |
| 663 | this.foregroundColor_, this.backgroundColor_); |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 664 | this.scrollPort_.setForegroundColor(color); |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | /** |
| 668 | * Return the current terminal foreground color. |
| 669 | * |
| 670 | * Intended for use by other classes, so we don't have to expose the entire |
| 671 | * prefs_ object. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 672 | * |
| 673 | * @return {string} |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 674 | */ |
| 675 | hterm.Terminal.prototype.getForegroundColor = function() { |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 676 | return this.foregroundColor_; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 677 | }; |
| 678 | |
| 679 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 680 | * Create a new instance of a terminal command and run it with a given |
| 681 | * argument string. |
| 682 | * |
| 683 | * @param {function} commandClass The constructor for a terminal command. |
| 684 | * @param {string} argString The argument string to pass to the command. |
| 685 | */ |
| 686 | hterm.Terminal.prototype.runCommandClass = function(commandClass, argString) { |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 687 | var environment = this.prefs_.get('environment'); |
| 688 | if (typeof environment != 'object' || environment == null) |
| 689 | environment = {}; |
| 690 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 691 | var self = this; |
| 692 | this.command = new commandClass( |
| 693 | { argString: argString || '', |
| 694 | io: this.io.push(), |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 695 | environment: environment, |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 696 | onExit: function(code) { |
| 697 | self.io.pop(); |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 698 | self.uninstallKeyboard(); |
rginda | 9875d90 | 2012-08-20 16:21:57 -0700 | [diff] [blame] | 699 | if (self.prefs_.get('close-on-exit')) |
| 700 | window.close(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 701 | } |
| 702 | }); |
| 703 | |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 704 | this.installKeyboard(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 705 | this.command.run(); |
| 706 | }; |
| 707 | |
| 708 | /** |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 709 | * Returns true if the current screen is the primary screen, false otherwise. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 710 | * |
| 711 | * @return {boolean} |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 712 | */ |
| 713 | hterm.Terminal.prototype.isPrimaryScreen = function() { |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 714 | return this.screen_ == this.primaryScreen_; |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 715 | }; |
| 716 | |
| 717 | /** |
| 718 | * Install the keyboard handler for this terminal. |
| 719 | * |
| 720 | * This will prevent the browser from seeing any keystrokes sent to the |
| 721 | * terminal. |
| 722 | */ |
| 723 | hterm.Terminal.prototype.installKeyboard = function() { |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 724 | this.keyboard.installKeyboard(this.scrollPort_.getDocument().body); |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /** |
| 728 | * Uninstall the keyboard handler for this terminal. |
| 729 | */ |
| 730 | hterm.Terminal.prototype.uninstallKeyboard = function() { |
| 731 | this.keyboard.installKeyboard(null); |
| 732 | } |
| 733 | |
| 734 | /** |
Mike Frysinger | cce97c4 | 2017-08-05 01:11:22 -0400 | [diff] [blame] | 735 | * Set a CSS variable. |
| 736 | * |
| 737 | * Normally this is used to set variables in the hterm namespace. |
| 738 | * |
| 739 | * @param {string} name The variable to set. |
| 740 | * @param {string} value The value to assign to the variable. |
| 741 | * @param {string?} opt_prefix The variable namespace/prefix to use. |
| 742 | */ |
| 743 | hterm.Terminal.prototype.setCssVar = function(name, value, |
| 744 | opt_prefix='--hterm-') { |
| 745 | this.document_.documentElement.style.setProperty( |
| 746 | `${opt_prefix}${name}`, value); |
| 747 | }; |
| 748 | |
| 749 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 750 | * Set the font size for this terminal. |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 751 | * |
| 752 | * Call setFontSize(0) to reset to the default font size. |
| 753 | * |
| 754 | * This function does not modify the font-size preference. |
| 755 | * |
| 756 | * @param {number} px The desired font size, in pixels. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 757 | */ |
| 758 | hterm.Terminal.prototype.setFontSize = function(px) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 759 | if (px === 0) |
| 760 | px = this.prefs_.get('font-size'); |
| 761 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 762 | this.scrollPort_.setFontSize(px); |
Mike Frysinger | cce97c4 | 2017-08-05 01:11:22 -0400 | [diff] [blame] | 763 | this.setCssVar('charsize-width', this.scrollPort_.characterSize.width + 'px'); |
| 764 | this.setCssVar('charsize-height', |
| 765 | this.scrollPort_.characterSize.height + 'px'); |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 766 | }; |
| 767 | |
| 768 | /** |
| 769 | * Get the current font size. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 770 | * |
| 771 | * @return {number} |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 772 | */ |
| 773 | hterm.Terminal.prototype.getFontSize = function() { |
| 774 | return this.scrollPort_.getFontSize(); |
| 775 | }; |
| 776 | |
| 777 | /** |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 778 | * Get the current font family. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 779 | * |
| 780 | * @return {string} |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 781 | */ |
| 782 | hterm.Terminal.prototype.getFontFamily = function() { |
| 783 | return this.scrollPort_.getFontFamily(); |
| 784 | }; |
| 785 | |
| 786 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 787 | * Set the CSS "font-family" for this terminal. |
| 788 | */ |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 789 | hterm.Terminal.prototype.syncFontFamily = function() { |
| 790 | this.scrollPort_.setFontFamily(this.prefs_.get('font-family'), |
| 791 | this.prefs_.get('font-smoothing')); |
| 792 | this.syncBoldSafeState(); |
| 793 | }; |
| 794 | |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 795 | /** |
| 796 | * Set this.mousePasteButton based on the mouse-paste-button pref, |
| 797 | * autodetecting if necessary. |
| 798 | */ |
| 799 | hterm.Terminal.prototype.syncMousePasteButton = function() { |
| 800 | var button = this.prefs_.get('mouse-paste-button'); |
| 801 | if (typeof button == 'number') { |
| 802 | this.mousePasteButton = button; |
| 803 | return; |
| 804 | } |
| 805 | |
Mike Frysinger | ee81a00 | 2017-12-12 16:14:53 -0500 | [diff] [blame^] | 806 | if (hterm.os != 'linux') { |
Mike Frysinger | 2edd361 | 2017-05-24 00:54:39 -0400 | [diff] [blame] | 807 | this.mousePasteButton = 1; // Middle mouse button. |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 808 | } else { |
Mike Frysinger | 2edd361 | 2017-05-24 00:54:39 -0400 | [diff] [blame] | 809 | this.mousePasteButton = 2; // Right mouse button. |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 810 | } |
| 811 | }; |
| 812 | |
| 813 | /** |
| 814 | * Enable or disable bold based on the enable-bold pref, autodetecting if |
| 815 | * necessary. |
| 816 | */ |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 817 | hterm.Terminal.prototype.syncBoldSafeState = function() { |
| 818 | var enableBold = this.prefs_.get('enable-bold'); |
| 819 | if (enableBold !== null) { |
Robert Ginda | ed01626 | 2012-10-26 16:27:09 -0700 | [diff] [blame] | 820 | this.primaryScreen_.textAttributes.enableBold = enableBold; |
| 821 | this.alternateScreen_.textAttributes.enableBold = enableBold; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 822 | return; |
| 823 | } |
| 824 | |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 825 | var normalSize = this.scrollPort_.measureCharacterSize(); |
| 826 | var boldSize = this.scrollPort_.measureCharacterSize('bold'); |
| 827 | |
| 828 | var isBoldSafe = normalSize.equals(boldSize); |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 829 | if (!isBoldSafe) { |
| 830 | console.warn('Bold characters disabled: Size of bold weight differs ' + |
rginda | c9759de | 2012-03-19 13:21:41 -0700 | [diff] [blame] | 831 | 'from normal. Font family is: ' + |
| 832 | this.scrollPort_.getFontFamily()); |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 833 | } |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 834 | |
Robert Ginda | ed01626 | 2012-10-26 16:27:09 -0700 | [diff] [blame] | 835 | this.primaryScreen_.textAttributes.enableBold = isBoldSafe; |
| 836 | this.alternateScreen_.textAttributes.enableBold = isBoldSafe; |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 837 | }; |
| 838 | |
| 839 | /** |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 840 | * Enable or disable blink based on the enable-blink pref. |
| 841 | */ |
| 842 | hterm.Terminal.prototype.syncBlinkState = function() { |
Mike Frysinger | cce97c4 | 2017-08-05 01:11:22 -0400 | [diff] [blame] | 843 | this.setCssVar('node-duration', |
| 844 | this.prefs_.get('enable-blink') ? '0.7s' : '0'); |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 845 | }; |
| 846 | |
| 847 | /** |
Mike Frysinger | 6ab275c | 2017-05-28 12:48:44 -0400 | [diff] [blame] | 848 | * Set the mouse cursor style based on the current terminal mode. |
| 849 | */ |
| 850 | hterm.Terminal.prototype.syncMouseStyle = function() { |
Mike Frysinger | cce97c4 | 2017-08-05 01:11:22 -0400 | [diff] [blame] | 851 | this.setCssVar('mouse-cursor-style', |
| 852 | this.vt.mouseReport == this.vt.MOUSE_REPORT_DISABLED ? |
| 853 | 'var(--hterm-mouse-cursor-text)' : |
| 854 | 'var(--hterm-mouse-cursor-pointer)'); |
Mike Frysinger | 6ab275c | 2017-05-28 12:48:44 -0400 | [diff] [blame] | 855 | }; |
| 856 | |
| 857 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 858 | * Return a copy of the current cursor position. |
| 859 | * |
| 860 | * @return {hterm.RowCol} The RowCol object representing the current position. |
| 861 | */ |
| 862 | hterm.Terminal.prototype.saveCursor = function() { |
| 863 | return this.screen_.cursorPosition.clone(); |
| 864 | }; |
| 865 | |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 866 | /** |
| 867 | * Return the current text attributes. |
| 868 | * |
| 869 | * @return {string} |
| 870 | */ |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 871 | hterm.Terminal.prototype.getTextAttributes = function() { |
| 872 | return this.screen_.textAttributes; |
| 873 | }; |
| 874 | |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 875 | /** |
| 876 | * Set the text attributes. |
| 877 | * |
| 878 | * @param {string} textAttributes The attributes to set. |
| 879 | */ |
rginda | 1a09aa0 | 2012-06-18 21:11:25 -0700 | [diff] [blame] | 880 | hterm.Terminal.prototype.setTextAttributes = function(textAttributes) { |
| 881 | this.screen_.textAttributes = textAttributes; |
| 882 | }; |
| 883 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 884 | /** |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 885 | * Return the current browser zoom factor applied to the terminal. |
| 886 | * |
| 887 | * @return {number} The current browser zoom factor. |
| 888 | */ |
| 889 | hterm.Terminal.prototype.getZoomFactor = function() { |
| 890 | return this.scrollPort_.characterSize.zoomFactor; |
| 891 | }; |
| 892 | |
| 893 | /** |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 894 | * Change the title of this terminal's window. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 895 | * |
| 896 | * @param {string} title The title to set. |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 897 | */ |
| 898 | hterm.Terminal.prototype.setWindowTitle = function(title) { |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 899 | window.document.title = title; |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 900 | }; |
| 901 | |
| 902 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 903 | * Restore a previously saved cursor position. |
| 904 | * |
| 905 | * @param {hterm.RowCol} cursor The position to restore. |
| 906 | */ |
| 907 | hterm.Terminal.prototype.restoreCursor = function(cursor) { |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 908 | var row = lib.f.clamp(cursor.row, 0, this.screenSize.height - 1); |
| 909 | var column = lib.f.clamp(cursor.column, 0, this.screenSize.width - 1); |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 910 | this.screen_.setCursorPosition(row, column); |
| 911 | if (cursor.column > column || |
| 912 | cursor.column == column && cursor.overflow) { |
| 913 | this.screen_.cursorPosition.overflow = true; |
| 914 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 915 | }; |
| 916 | |
| 917 | /** |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 918 | * Clear the cursor's overflow flag. |
| 919 | */ |
| 920 | hterm.Terminal.prototype.clearCursorOverflow = function() { |
| 921 | this.screen_.cursorPosition.overflow = false; |
| 922 | }; |
| 923 | |
| 924 | /** |
Mike Frysinger | a2cacaa | 2017-11-29 13:51:09 -0800 | [diff] [blame] | 925 | * Save the current cursor state to the corresponding screens. |
| 926 | * |
| 927 | * See the hterm.Screen.CursorState class for more details. |
| 928 | * |
| 929 | * @param {boolean=} both If true, update both screens, else only update the |
| 930 | * current screen. |
| 931 | */ |
| 932 | hterm.Terminal.prototype.saveCursorAndState = function(both) { |
| 933 | if (both) { |
| 934 | this.primaryScreen_.saveCursorAndState(this.vt); |
| 935 | this.alternateScreen_.saveCursorAndState(this.vt); |
| 936 | } else |
| 937 | this.screen_.saveCursorAndState(this.vt); |
| 938 | }; |
| 939 | |
| 940 | /** |
| 941 | * Restore the saved cursor state in the corresponding screens. |
| 942 | * |
| 943 | * See the hterm.Screen.CursorState class for more details. |
| 944 | * |
| 945 | * @param {boolean=} both If true, update both screens, else only update the |
| 946 | * current screen. |
| 947 | */ |
| 948 | hterm.Terminal.prototype.restoreCursorAndState = function(both) { |
| 949 | if (both) { |
| 950 | this.primaryScreen_.restoreCursorAndState(this.vt); |
| 951 | this.alternateScreen_.restoreCursorAndState(this.vt); |
| 952 | } else |
| 953 | this.screen_.restoreCursorAndState(this.vt); |
| 954 | }; |
| 955 | |
| 956 | /** |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 957 | * Sets the cursor shape |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 958 | * |
| 959 | * @param {string} shape The shape to set. |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 960 | */ |
| 961 | hterm.Terminal.prototype.setCursorShape = function(shape) { |
| 962 | this.cursorShape_ = shape; |
Robert Ginda | fb1be6a | 2013-12-11 11:56:22 -0800 | [diff] [blame] | 963 | this.restyleCursor_(); |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Get the cursor shape |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 968 | * |
| 969 | * @return {string} |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 970 | */ |
| 971 | hterm.Terminal.prototype.getCursorShape = function() { |
| 972 | return this.cursorShape_; |
| 973 | } |
| 974 | |
| 975 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 976 | * Set the width of the terminal, resizing the UI to match. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 977 | * |
| 978 | * @param {number} columnCount |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 979 | */ |
| 980 | hterm.Terminal.prototype.setWidth = function(columnCount) { |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 981 | if (columnCount == null) { |
| 982 | this.div_.style.width = '100%'; |
| 983 | return; |
| 984 | } |
| 985 | |
Robert Ginda | 26806d1 | 2014-07-24 13:44:07 -0700 | [diff] [blame] | 986 | this.div_.style.width = Math.ceil( |
| 987 | this.scrollPort_.characterSize.width * |
| 988 | columnCount + this.scrollPort_.currentScrollbarWidthPx) + 'px'; |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 989 | this.realizeSize_(columnCount, this.screenSize.height); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 990 | this.scheduleSyncCursorPosition_(); |
| 991 | }; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 992 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 993 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 994 | * Set the height of the terminal, resizing the UI to match. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 995 | * |
| 996 | * @param {number} rowCount The height in rows. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 997 | */ |
| 998 | hterm.Terminal.prototype.setHeight = function(rowCount) { |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 999 | if (rowCount == null) { |
| 1000 | this.div_.style.height = '100%'; |
| 1001 | return; |
| 1002 | } |
| 1003 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1004 | this.div_.style.height = |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 1005 | this.scrollPort_.characterSize.height * rowCount + 'px'; |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1006 | this.realizeSize_(this.screenSize.width, rowCount); |
| 1007 | this.scheduleSyncCursorPosition_(); |
| 1008 | }; |
| 1009 | |
| 1010 | /** |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 1011 | * Deal with terminal size changes. |
| 1012 | * |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1013 | * @param {number} columnCount The number of columns. |
| 1014 | * @param {number} rowCount The number of rows. |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 1015 | */ |
| 1016 | hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) { |
| 1017 | if (columnCount != this.screenSize.width) |
| 1018 | this.realizeWidth_(columnCount); |
| 1019 | |
| 1020 | if (rowCount != this.screenSize.height) |
| 1021 | this.realizeHeight_(rowCount); |
| 1022 | |
| 1023 | // Send new terminal size to plugin. |
Robert Ginda | e81427f | 2013-05-24 10:34:46 -0700 | [diff] [blame] | 1024 | this.io.onTerminalResize_(columnCount, rowCount); |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 1025 | }; |
| 1026 | |
| 1027 | /** |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1028 | * Deal with terminal width changes. |
| 1029 | * |
| 1030 | * This function does what needs to be done when the terminal width changes |
| 1031 | * out from under us. It happens here rather than in onResize_() because this |
| 1032 | * code may need to run synchronously to handle programmatic changes of |
| 1033 | * terminal width. |
| 1034 | * |
| 1035 | * Relying on the browser to send us an async resize event means we may not be |
| 1036 | * in the correct state yet when the next escape sequence hits. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1037 | * |
| 1038 | * @param {number} columnCount The number of columns. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1039 | */ |
| 1040 | hterm.Terminal.prototype.realizeWidth_ = function(columnCount) { |
Robert Ginda | 4e83f3a | 2012-09-04 15:25:25 -0700 | [diff] [blame] | 1041 | if (columnCount <= 0) |
| 1042 | throw new Error('Attempt to realize bad width: ' + columnCount); |
| 1043 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1044 | var deltaColumns = columnCount - this.screen_.getWidth(); |
| 1045 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1046 | this.screenSize.width = columnCount; |
| 1047 | this.screen_.setColumnCount(columnCount); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1048 | |
| 1049 | if (deltaColumns > 0) { |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1050 | if (this.defaultTabStops) |
| 1051 | this.setDefaultTabStops(this.screenSize.width - deltaColumns); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1052 | } else { |
| 1053 | for (var i = this.tabStops_.length - 1; i >= 0; i--) { |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1054 | if (this.tabStops_[i] < columnCount) |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1055 | break; |
| 1056 | |
| 1057 | this.tabStops_.pop(); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | this.screen_.setColumnCount(this.screenSize.width); |
| 1062 | }; |
| 1063 | |
| 1064 | /** |
| 1065 | * Deal with terminal height changes. |
| 1066 | * |
| 1067 | * This function does what needs to be done when the terminal height changes |
| 1068 | * out from under us. It happens here rather than in onResize_() because this |
| 1069 | * code may need to run synchronously to handle programmatic changes of |
| 1070 | * terminal height. |
| 1071 | * |
| 1072 | * Relying on the browser to send us an async resize event means we may not be |
| 1073 | * in the correct state yet when the next escape sequence hits. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1074 | * |
| 1075 | * @param {number} rowCount The number of rows. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1076 | */ |
| 1077 | hterm.Terminal.prototype.realizeHeight_ = function(rowCount) { |
Robert Ginda | 4e83f3a | 2012-09-04 15:25:25 -0700 | [diff] [blame] | 1078 | if (rowCount <= 0) |
| 1079 | throw new Error('Attempt to realize bad height: ' + rowCount); |
| 1080 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1081 | var deltaRows = rowCount - this.screen_.getHeight(); |
| 1082 | |
| 1083 | this.screenSize.height = rowCount; |
| 1084 | |
| 1085 | var cursor = this.saveCursor(); |
| 1086 | |
| 1087 | if (deltaRows < 0) { |
| 1088 | // Screen got smaller. |
| 1089 | deltaRows *= -1; |
| 1090 | while (deltaRows) { |
| 1091 | var lastRow = this.getRowCount() - 1; |
| 1092 | if (lastRow - this.scrollbackRows_.length == cursor.row) |
| 1093 | break; |
| 1094 | |
| 1095 | if (this.getRowText(lastRow)) |
| 1096 | break; |
| 1097 | |
| 1098 | this.screen_.popRow(); |
| 1099 | deltaRows--; |
| 1100 | } |
| 1101 | |
| 1102 | var ary = this.screen_.shiftRows(deltaRows); |
| 1103 | this.scrollbackRows_.push.apply(this.scrollbackRows_, ary); |
| 1104 | |
| 1105 | // We just removed rows from the top of the screen, we need to update |
| 1106 | // the cursor to match. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1107 | cursor.row = Math.max(cursor.row - deltaRows, 0); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1108 | } else if (deltaRows > 0) { |
| 1109 | // Screen got larger. |
| 1110 | |
| 1111 | if (deltaRows <= this.scrollbackRows_.length) { |
| 1112 | var scrollbackCount = Math.min(deltaRows, this.scrollbackRows_.length); |
| 1113 | var rows = this.scrollbackRows_.splice( |
| 1114 | this.scrollbackRows_.length - scrollbackCount, scrollbackCount); |
| 1115 | this.screen_.unshiftRows(rows); |
| 1116 | deltaRows -= scrollbackCount; |
| 1117 | cursor.row += scrollbackCount; |
| 1118 | } |
| 1119 | |
| 1120 | if (deltaRows) |
| 1121 | this.appendRows_(deltaRows); |
| 1122 | } |
| 1123 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1124 | this.setVTScrollRegion(null, null); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1125 | this.restoreCursor(cursor); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1126 | }; |
| 1127 | |
| 1128 | /** |
| 1129 | * Scroll the terminal to the top of the scrollback buffer. |
| 1130 | */ |
| 1131 | hterm.Terminal.prototype.scrollHome = function() { |
| 1132 | this.scrollPort_.scrollRowToTop(0); |
| 1133 | }; |
| 1134 | |
| 1135 | /** |
| 1136 | * Scroll the terminal to the end. |
| 1137 | */ |
| 1138 | hterm.Terminal.prototype.scrollEnd = function() { |
| 1139 | this.scrollPort_.scrollRowToBottom(this.getRowCount()); |
| 1140 | }; |
| 1141 | |
| 1142 | /** |
| 1143 | * Scroll the terminal one page up (minus one line) relative to the current |
| 1144 | * position. |
| 1145 | */ |
| 1146 | hterm.Terminal.prototype.scrollPageUp = function() { |
| 1147 | var i = this.scrollPort_.getTopRowIndex(); |
| 1148 | this.scrollPort_.scrollRowToTop(i - this.screenSize.height + 1); |
| 1149 | }; |
| 1150 | |
| 1151 | /** |
| 1152 | * Scroll the terminal one page down (minus one line) relative to the current |
| 1153 | * position. |
| 1154 | */ |
| 1155 | hterm.Terminal.prototype.scrollPageDown = function() { |
| 1156 | var i = this.scrollPort_.getTopRowIndex(); |
| 1157 | this.scrollPort_.scrollRowToTop(i + this.screenSize.height - 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1158 | }; |
| 1159 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1160 | /** |
Mike Frysinger | cd56a63 | 2017-05-10 14:45:28 -0400 | [diff] [blame] | 1161 | * Scroll the terminal one line up relative to the current position. |
| 1162 | */ |
| 1163 | hterm.Terminal.prototype.scrollLineUp = function() { |
| 1164 | var i = this.scrollPort_.getTopRowIndex(); |
| 1165 | this.scrollPort_.scrollRowToTop(i - 1); |
| 1166 | }; |
| 1167 | |
| 1168 | /** |
| 1169 | * Scroll the terminal one line down relative to the current position. |
| 1170 | */ |
| 1171 | hterm.Terminal.prototype.scrollLineDown = function() { |
| 1172 | var i = this.scrollPort_.getTopRowIndex(); |
| 1173 | this.scrollPort_.scrollRowToTop(i + 1); |
| 1174 | }; |
| 1175 | |
| 1176 | /** |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 1177 | * Clear primary screen, secondary screen, and the scrollback buffer. |
| 1178 | */ |
| 1179 | hterm.Terminal.prototype.wipeContents = function() { |
| 1180 | this.scrollbackRows_.length = 0; |
| 1181 | this.scrollPort_.resetCache(); |
| 1182 | |
| 1183 | [this.primaryScreen_, this.alternateScreen_].forEach(function(screen) { |
| 1184 | var bottom = screen.getHeight(); |
| 1185 | if (bottom > 0) { |
| 1186 | this.renumberRows_(0, bottom); |
| 1187 | this.clearHome(screen); |
| 1188 | } |
| 1189 | }.bind(this)); |
| 1190 | |
| 1191 | this.syncCursorPosition_(); |
Andrew de los Reyes | 68e0780 | 2013-04-04 15:38:55 -0700 | [diff] [blame] | 1192 | this.scrollPort_.invalidate(); |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 1193 | }; |
| 1194 | |
| 1195 | /** |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1196 | * Full terminal reset. |
Mike Frysinger | 84301d0 | 2017-11-29 13:28:46 -0800 | [diff] [blame] | 1197 | * |
| 1198 | * Perform a full reset to the default values listed in |
| 1199 | * https://vt100.net/docs/vt510-rm/RIS.html |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1200 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1201 | hterm.Terminal.prototype.reset = function() { |
Mike Frysinger | 7e42f63 | 2017-11-29 13:42:09 -0800 | [diff] [blame] | 1202 | this.vt.reset(); |
| 1203 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1204 | this.clearAllTabStops(); |
| 1205 | this.setDefaultTabStops(); |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1206 | |
Mike Frysinger | a2cacaa | 2017-11-29 13:51:09 -0800 | [diff] [blame] | 1207 | const resetScreen = (screen) => { |
| 1208 | // We want to make sure to reset the attributes before we clear the screen. |
| 1209 | // The attributes might be used to initialize default/empty rows. |
| 1210 | screen.textAttributes.reset(); |
| 1211 | screen.textAttributes.resetColorPalette(); |
| 1212 | this.clearHome(screen); |
| 1213 | screen.saveCursorAndState(this.vt); |
| 1214 | }; |
| 1215 | resetScreen(this.primaryScreen_); |
| 1216 | resetScreen(this.alternateScreen_); |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1217 | |
Mike Frysinger | 84301d0 | 2017-11-29 13:28:46 -0800 | [diff] [blame] | 1218 | // Reset terminal options to their default values. |
| 1219 | this.options_ = new hterm.Options(); |
rginda | b8bc893 | 2012-04-27 12:45:03 -0700 | [diff] [blame] | 1220 | this.setCursorBlink(!!this.prefs_.get('cursor-blink')); |
| 1221 | |
Mike Frysinger | 84301d0 | 2017-11-29 13:28:46 -0800 | [diff] [blame] | 1222 | this.setVTScrollRegion(null, null); |
| 1223 | |
| 1224 | this.setCursorVisible(true); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1225 | }; |
| 1226 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1227 | /** |
| 1228 | * Soft terminal reset. |
rginda | b8bc893 | 2012-04-27 12:45:03 -0700 | [diff] [blame] | 1229 | * |
| 1230 | * Perform a soft reset to the default values listed in |
| 1231 | * http://www.vt100.net/docs/vt510-rm/DECSTR#T5-9 |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1232 | */ |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1233 | hterm.Terminal.prototype.softReset = function() { |
Mike Frysinger | 7e42f63 | 2017-11-29 13:42:09 -0800 | [diff] [blame] | 1234 | this.vt.reset(); |
| 1235 | |
rginda | b8bc893 | 2012-04-27 12:45:03 -0700 | [diff] [blame] | 1236 | // Reset terminal options to their default values. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1237 | this.options_ = new hterm.Options(); |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 1238 | |
Brad Town | b62dfdc | 2015-03-16 19:07:15 -0700 | [diff] [blame] | 1239 | // We show the cursor on soft reset but do not alter the blink state. |
| 1240 | this.options_.cursorBlink = !!this.timeouts_.cursorBlink; |
| 1241 | |
Mike Frysinger | a2cacaa | 2017-11-29 13:51:09 -0800 | [diff] [blame] | 1242 | const resetScreen = (screen) => { |
| 1243 | // Xterm also resets the color palette on soft reset, even though it doesn't |
| 1244 | // seem to be documented anywhere. |
| 1245 | screen.textAttributes.reset(); |
| 1246 | screen.textAttributes.resetColorPalette(); |
| 1247 | screen.saveCursorAndState(this.vt); |
| 1248 | }; |
| 1249 | resetScreen(this.primaryScreen_); |
| 1250 | resetScreen(this.alternateScreen_); |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 1251 | |
rginda | b8bc893 | 2012-04-27 12:45:03 -0700 | [diff] [blame] | 1252 | // The xterm man page explicitly says this will happen on soft reset. |
| 1253 | this.setVTScrollRegion(null, null); |
| 1254 | |
| 1255 | // Xterm also shows the cursor on soft reset, but does not alter the blink |
| 1256 | // state. |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1257 | this.setCursorVisible(true); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1258 | }; |
| 1259 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1260 | /** |
| 1261 | * Move the cursor forward to the next tab stop, or to the last column |
| 1262 | * if no more tab stops are set. |
| 1263 | */ |
| 1264 | hterm.Terminal.prototype.forwardTabStop = function() { |
| 1265 | var column = this.screen_.cursorPosition.column; |
| 1266 | |
| 1267 | for (var i = 0; i < this.tabStops_.length; i++) { |
| 1268 | if (this.tabStops_[i] > column) { |
| 1269 | this.setCursorColumn(this.tabStops_[i]); |
| 1270 | return; |
| 1271 | } |
| 1272 | } |
| 1273 | |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1274 | // xterm does not clear the overflow flag on HT or CHT. |
| 1275 | var overflow = this.screen_.cursorPosition.overflow; |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1276 | this.setCursorColumn(this.screenSize.width - 1); |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1277 | this.screen_.cursorPosition.overflow = overflow; |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1278 | }; |
| 1279 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1280 | /** |
| 1281 | * Move the cursor backward to the previous tab stop, or to the first column |
| 1282 | * if no previous tab stops are set. |
| 1283 | */ |
| 1284 | hterm.Terminal.prototype.backwardTabStop = function() { |
| 1285 | var column = this.screen_.cursorPosition.column; |
| 1286 | |
| 1287 | for (var i = this.tabStops_.length - 1; i >= 0; i--) { |
| 1288 | if (this.tabStops_[i] < column) { |
| 1289 | this.setCursorColumn(this.tabStops_[i]); |
| 1290 | return; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | this.setCursorColumn(1); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1295 | }; |
| 1296 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1297 | /** |
| 1298 | * Set a tab stop at the given column. |
| 1299 | * |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1300 | * @param {integer} column Zero based column. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1301 | */ |
| 1302 | hterm.Terminal.prototype.setTabStop = function(column) { |
| 1303 | for (var i = this.tabStops_.length - 1; i >= 0; i--) { |
| 1304 | if (this.tabStops_[i] == column) |
| 1305 | return; |
| 1306 | |
| 1307 | if (this.tabStops_[i] < column) { |
| 1308 | this.tabStops_.splice(i + 1, 0, column); |
| 1309 | return; |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | this.tabStops_.splice(0, 0, column); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1314 | }; |
| 1315 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1316 | /** |
| 1317 | * Clear the tab stop at the current cursor position. |
| 1318 | * |
| 1319 | * No effect if there is no tab stop at the current cursor position. |
| 1320 | */ |
| 1321 | hterm.Terminal.prototype.clearTabStopAtCursor = function() { |
| 1322 | var column = this.screen_.cursorPosition.column; |
| 1323 | |
| 1324 | var i = this.tabStops_.indexOf(column); |
| 1325 | if (i == -1) |
| 1326 | return; |
| 1327 | |
| 1328 | this.tabStops_.splice(i, 1); |
| 1329 | }; |
| 1330 | |
| 1331 | /** |
| 1332 | * Clear all tab stops. |
| 1333 | */ |
| 1334 | hterm.Terminal.prototype.clearAllTabStops = function() { |
| 1335 | this.tabStops_.length = 0; |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1336 | this.defaultTabStops = false; |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1337 | }; |
| 1338 | |
| 1339 | /** |
| 1340 | * Set up the default tab stops, starting from a given column. |
| 1341 | * |
| 1342 | * This sets a tabstop every (column % this.tabWidth) column, starting |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1343 | * from the specified column, or 0 if no column is provided. It also flags |
| 1344 | * future resizes to set them up. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1345 | * |
| 1346 | * This does not clear the existing tab stops first, use clearAllTabStops |
| 1347 | * for that. |
| 1348 | * |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1349 | * @param {integer} opt_start Optional starting zero based starting column, useful |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1350 | * for filling out missing tab stops when the terminal is resized. |
| 1351 | */ |
| 1352 | hterm.Terminal.prototype.setDefaultTabStops = function(opt_start) { |
| 1353 | var start = opt_start || 0; |
| 1354 | var w = this.tabWidth; |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1355 | // Round start up to a default tab stop. |
| 1356 | start = start - 1 - ((start - 1) % w) + w; |
| 1357 | for (var i = start; i < this.screenSize.width; i += w) { |
| 1358 | this.setTabStop(i); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1359 | } |
David Benjamin | 66e954d | 2012-05-05 21:08:12 -0400 | [diff] [blame] | 1360 | |
| 1361 | this.defaultTabStops = true; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1362 | }; |
| 1363 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 1364 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1365 | * Interpret a sequence of characters. |
| 1366 | * |
| 1367 | * Incomplete escape sequences are buffered until the next call. |
| 1368 | * |
| 1369 | * @param {string} str Sequence of characters to interpret or pass through. |
| 1370 | */ |
| 1371 | hterm.Terminal.prototype.interpret = function(str) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1372 | this.vt.interpret(str); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1373 | this.scheduleSyncCursorPosition_(); |
| 1374 | }; |
| 1375 | |
| 1376 | /** |
| 1377 | * Take over the given DIV for use as the terminal display. |
| 1378 | * |
| 1379 | * @param {HTMLDivElement} div The div to use as the terminal display. |
| 1380 | */ |
| 1381 | hterm.Terminal.prototype.decorate = function(div) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1382 | this.div_ = div; |
| 1383 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1384 | this.scrollPort_.decorate(div); |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 1385 | this.scrollPort_.setBackgroundImage(this.prefs_.get('background-image')); |
Philip Douglass | 959b49d | 2012-05-30 13:29:29 -0400 | [diff] [blame] | 1386 | this.scrollPort_.setBackgroundSize(this.prefs_.get('background-size')); |
| 1387 | this.scrollPort_.setBackgroundPosition( |
| 1388 | this.prefs_.get('background-position')); |
Mike Frysinger | 08bad43 | 2017-04-24 00:50:54 -0400 | [diff] [blame] | 1389 | this.scrollPort_.setUserCssUrl(this.prefs_.get('user-css')); |
| 1390 | this.scrollPort_.setUserCssText(this.prefs_.get('user-css-text')); |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 1391 | |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 1392 | this.div_.focus = this.focus.bind(this); |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 1393 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1394 | this.setFontSize(this.prefs_.get('font-size')); |
| 1395 | this.syncFontFamily(); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1396 | |
David Reveman | 8f55249 | 2012-03-28 12:18:41 -0400 | [diff] [blame] | 1397 | this.setScrollbarVisible(this.prefs_.get('scrollbar-visible')); |
Rob Spies | 49039e5 | 2014-12-17 13:40:04 -0800 | [diff] [blame] | 1398 | this.setScrollWheelMoveMultipler( |
| 1399 | this.prefs_.get('scroll-wheel-move-multiplier')); |
David Reveman | 8f55249 | 2012-03-28 12:18:41 -0400 | [diff] [blame] | 1400 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1401 | this.document_ = this.scrollPort_.getDocument(); |
| 1402 | |
Evan Jones | 5f9df81 | 2016-12-06 09:38:58 -0500 | [diff] [blame] | 1403 | this.document_.body.oncontextmenu = function() { return false; }; |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 1404 | |
| 1405 | var onMouse = this.onMouse_.bind(this); |
Toni Barzic | 0bfa892 | 2013-11-22 11:18:35 -0800 | [diff] [blame] | 1406 | var screenNode = this.scrollPort_.getScreenNode(); |
| 1407 | screenNode.addEventListener('mousedown', onMouse); |
| 1408 | screenNode.addEventListener('mouseup', onMouse); |
| 1409 | screenNode.addEventListener('mousemove', onMouse); |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 1410 | this.scrollPort_.onScrollWheel = onMouse; |
| 1411 | |
Toni Barzic | 0bfa892 | 2013-11-22 11:18:35 -0800 | [diff] [blame] | 1412 | screenNode.addEventListener( |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 1413 | 'focus', this.onFocusChange_.bind(this, true)); |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 1414 | // Listen for mousedown events on the screenNode as in FF the focus |
| 1415 | // events don't bubble. |
| 1416 | screenNode.addEventListener('mousedown', function() { |
| 1417 | setTimeout(this.onFocusChange_.bind(this, true)); |
| 1418 | }.bind(this)); |
| 1419 | |
Toni Barzic | 0bfa892 | 2013-11-22 11:18:35 -0800 | [diff] [blame] | 1420 | screenNode.addEventListener( |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 1421 | 'blur', this.onFocusChange_.bind(this, false)); |
| 1422 | |
| 1423 | var style = this.document_.createElement('style'); |
| 1424 | style.textContent = |
| 1425 | ('.cursor-node[focus="false"] {' + |
| 1426 | ' box-sizing: border-box;' + |
| 1427 | ' background-color: transparent !important;' + |
| 1428 | ' border-width: 2px;' + |
| 1429 | ' border-style: solid;' + |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1430 | '}' + |
| 1431 | '.wc-node {' + |
| 1432 | ' display: inline-block;' + |
| 1433 | ' text-align: center;' + |
Mike Frysinger | 66beb0b | 2017-05-30 19:44:51 -0400 | [diff] [blame] | 1434 | ' width: calc(var(--hterm-charsize-width) * 2);' + |
Mike Frysinger | 4036f6e | 2017-05-31 14:02:55 -0400 | [diff] [blame] | 1435 | ' line-height: var(--hterm-charsize-height);' + |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 1436 | '}' + |
| 1437 | ':root {' + |
Mike Frysinger | 66beb0b | 2017-05-30 19:44:51 -0400 | [diff] [blame] | 1438 | ' --hterm-charsize-width: ' + this.scrollPort_.characterSize.width + 'px;' + |
| 1439 | ' --hterm-charsize-height: ' + this.scrollPort_.characterSize.height + 'px;' + |
Mike Frysinger | a27c050 | 2017-08-23 22:37:10 -0400 | [diff] [blame] | 1440 | // Default position hides the cursor for when the window is initializing. |
| 1441 | ' --hterm-cursor-offset-col: -1;' + |
| 1442 | ' --hterm-cursor-offset-row: -1;' + |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 1443 | ' --hterm-blink-node-duration: 0.7s;' + |
Mike Frysinger | 6ab275c | 2017-05-28 12:48:44 -0400 | [diff] [blame] | 1444 | ' --hterm-mouse-cursor-text: text;' + |
| 1445 | ' --hterm-mouse-cursor-pointer: default;' + |
| 1446 | ' --hterm-mouse-cursor-style: var(--hterm-mouse-cursor-text);' + |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 1447 | '}' + |
Mike Frysinger | d390720 | 2017-10-23 01:23:50 -0400 | [diff] [blame] | 1448 | '.uri-node:hover {' + |
| 1449 | ' text-decoration: underline;' + |
| 1450 | ' cursor: pointer;' + |
| 1451 | '}' + |
Mike Frysinger | 93b75ba | 2017-04-05 19:43:18 -0400 | [diff] [blame] | 1452 | '@keyframes blink {' + |
| 1453 | ' from { opacity: 1.0; }' + |
| 1454 | ' to { opacity: 0.0; }' + |
| 1455 | '}' + |
| 1456 | '.blink-node {' + |
| 1457 | ' animation-name: blink;' + |
| 1458 | ' animation-duration: var(--hterm-blink-node-duration);' + |
| 1459 | ' animation-iteration-count: infinite;' + |
| 1460 | ' animation-timing-function: ease-in-out;' + |
| 1461 | ' animation-direction: alternate;' + |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 1462 | '}'); |
| 1463 | this.document_.head.appendChild(style); |
| 1464 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1465 | this.cursorNode_ = this.document_.createElement('div'); |
Mike Frysinger | d826f1a | 2017-07-06 16:20:06 -0400 | [diff] [blame] | 1466 | this.cursorNode_.id = 'hterm:terminal-cursor'; |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 1467 | this.cursorNode_.className = 'cursor-node'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1468 | this.cursorNode_.style.cssText = |
| 1469 | ('position: absolute;' + |
Mike Frysinger | 44c3220 | 2017-08-05 01:13:09 -0400 | [diff] [blame] | 1470 | 'left: calc(var(--hterm-charsize-width) * var(--hterm-cursor-offset-col));' + |
| 1471 | 'top: calc(var(--hterm-charsize-height) * var(--hterm-cursor-offset-row));' + |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1472 | 'display: block;' + |
Mike Frysinger | 66beb0b | 2017-05-30 19:44:51 -0400 | [diff] [blame] | 1473 | 'width: var(--hterm-charsize-width);' + |
| 1474 | 'height: var(--hterm-charsize-height);' + |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 1475 | '-webkit-transition: opacity, background-color 100ms linear;' + |
| 1476 | '-moz-transition: opacity, background-color 100ms linear;'); |
Robert Ginda | fb1be6a | 2013-12-11 11:56:22 -0800 | [diff] [blame] | 1477 | |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 1478 | this.setCursorColor(this.prefs_.get('cursor-color')); |
Robert Ginda | fb1be6a | 2013-12-11 11:56:22 -0800 | [diff] [blame] | 1479 | this.setCursorBlink(!!this.prefs_.get('cursor-blink')); |
| 1480 | this.restyleCursor_(); |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 1481 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1482 | this.document_.body.appendChild(this.cursorNode_); |
| 1483 | |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 1484 | // When 'enableMouseDragScroll' is off we reposition this element directly |
| 1485 | // under the mouse cursor after a click. This makes Chrome associate |
| 1486 | // subsequent mousemove events with the scroll-blocker. Since the |
| 1487 | // scroll-blocker is a peer (not a child) of the scrollport, the mousemove |
| 1488 | // events do not cause the scrollport to scroll. |
| 1489 | // |
| 1490 | // It's a hack, but it's the cleanest way I could find. |
| 1491 | this.scrollBlockerNode_ = this.document_.createElement('div'); |
Mike Frysinger | d826f1a | 2017-07-06 16:20:06 -0400 | [diff] [blame] | 1492 | this.scrollBlockerNode_.id = 'hterm:mouse-drag-scroll-blocker'; |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 1493 | this.scrollBlockerNode_.style.cssText = |
| 1494 | ('position: absolute;' + |
| 1495 | 'top: -99px;' + |
| 1496 | 'display: block;' + |
| 1497 | 'width: 10px;' + |
| 1498 | 'height: 10px;'); |
| 1499 | this.document_.body.appendChild(this.scrollBlockerNode_); |
| 1500 | |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 1501 | this.scrollPort_.onScrollWheel = onMouse; |
| 1502 | ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick', |
| 1503 | ].forEach(function(event) { |
| 1504 | this.scrollBlockerNode_.addEventListener(event, onMouse); |
| 1505 | this.cursorNode_.addEventListener(event, onMouse); |
| 1506 | this.document_.addEventListener(event, onMouse); |
| 1507 | }.bind(this)); |
| 1508 | |
| 1509 | this.cursorNode_.addEventListener('mousedown', function() { |
| 1510 | setTimeout(this.focus.bind(this)); |
| 1511 | }.bind(this)); |
| 1512 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1513 | this.setReverseVideo(false); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1514 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1515 | this.scrollPort_.focus(); |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 1516 | this.scrollPort_.scheduleRedraw(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1517 | }; |
| 1518 | |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 1519 | /** |
| 1520 | * Return the HTML document that contains the terminal DOM nodes. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1521 | * |
| 1522 | * @return {HTMLDocument} |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 1523 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1524 | hterm.Terminal.prototype.getDocument = function() { |
| 1525 | return this.document_; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1526 | }; |
| 1527 | |
| 1528 | /** |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 1529 | * Focus the terminal. |
| 1530 | */ |
| 1531 | hterm.Terminal.prototype.focus = function() { |
| 1532 | this.scrollPort_.focus(); |
| 1533 | }; |
| 1534 | |
| 1535 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1536 | * Return the HTML Element for a given row index. |
| 1537 | * |
| 1538 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 1539 | * it to fetch rows on demand as they are scrolled into view. |
| 1540 | * |
| 1541 | * TODO(rginda): Consider saving scrollback rows as (HTML source, text content) |
| 1542 | * pairs to conserve memory. |
| 1543 | * |
| 1544 | * @param {integer} index The zero-based row index, measured relative to the |
| 1545 | * start of the scrollback buffer. On-screen rows will always have the |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 1546 | * largest indices. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1547 | * @return {HTMLElement} The 'x-row' element containing for the requested row. |
| 1548 | */ |
| 1549 | hterm.Terminal.prototype.getRowNode = function(index) { |
| 1550 | if (index < this.scrollbackRows_.length) |
| 1551 | return this.scrollbackRows_[index]; |
| 1552 | |
| 1553 | var screenIndex = index - this.scrollbackRows_.length; |
| 1554 | return this.screen_.rowsArray[screenIndex]; |
| 1555 | }; |
| 1556 | |
| 1557 | /** |
| 1558 | * Return the text content for a given range of rows. |
| 1559 | * |
| 1560 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 1561 | * it to fetch text content on demand when the user attempts to copy their |
| 1562 | * selection to the clipboard. |
| 1563 | * |
| 1564 | * @param {integer} start The zero-based row index to start from, measured |
| 1565 | * relative to the start of the scrollback buffer. On-screen rows will |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 1566 | * always have the largest indices. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1567 | * @param {integer} end The zero-based row index to end on, measured |
| 1568 | * relative to the start of the scrollback buffer. |
| 1569 | * @return {string} A single string containing the text value of the range of |
| 1570 | * rows. Lines will be newline delimited, with no trailing newline. |
| 1571 | */ |
| 1572 | hterm.Terminal.prototype.getRowsText = function(start, end) { |
| 1573 | var ary = []; |
| 1574 | for (var i = start; i < end; i++) { |
| 1575 | var node = this.getRowNode(i); |
| 1576 | ary.push(node.textContent); |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 1577 | if (i < end - 1 && !node.getAttribute('line-overflow')) |
| 1578 | ary.push('\n'); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 1581 | return ary.join(''); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1582 | }; |
| 1583 | |
| 1584 | /** |
| 1585 | * Return the text content for a given row. |
| 1586 | * |
| 1587 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 1588 | * it to fetch text content on demand when the user attempts to copy their |
| 1589 | * selection to the clipboard. |
| 1590 | * |
| 1591 | * @param {integer} index The zero-based row index to return, measured |
| 1592 | * relative to the start of the scrollback buffer. On-screen rows will |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 1593 | * always have the largest indices. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1594 | * @return {string} A string containing the text value of the selected row. |
| 1595 | */ |
| 1596 | hterm.Terminal.prototype.getRowText = function(index) { |
| 1597 | var node = this.getRowNode(index); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1598 | return node.textContent; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1599 | }; |
| 1600 | |
| 1601 | /** |
| 1602 | * Return the total number of rows in the addressable screen and in the |
| 1603 | * scrollback buffer of this terminal. |
| 1604 | * |
| 1605 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 1606 | * it to compute the size of the scrollbar. |
| 1607 | * |
| 1608 | * @return {integer} The number of rows in this terminal. |
| 1609 | */ |
| 1610 | hterm.Terminal.prototype.getRowCount = function() { |
| 1611 | return this.scrollbackRows_.length + this.screen_.rowsArray.length; |
| 1612 | }; |
| 1613 | |
| 1614 | /** |
| 1615 | * Create DOM nodes for new rows and append them to the end of the terminal. |
| 1616 | * |
| 1617 | * This is the only correct way to add a new DOM node for a row. Notice that |
| 1618 | * the new row is appended to the bottom of the list of rows, and does not |
| 1619 | * require renumbering (of the rowIndex property) of previous rows. |
| 1620 | * |
| 1621 | * If you think you want a new blank row somewhere in the middle of the |
| 1622 | * terminal, look into moveRows_(). |
| 1623 | * |
| 1624 | * This method does not pay attention to vtScrollTop/Bottom, since you should |
| 1625 | * be using moveRows() in cases where they would matter. |
| 1626 | * |
| 1627 | * The cursor will be positioned at column 0 of the first inserted line. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1628 | * |
| 1629 | * @param {number} count The number of rows to created. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1630 | */ |
| 1631 | hterm.Terminal.prototype.appendRows_ = function(count) { |
| 1632 | var cursorRow = this.screen_.rowsArray.length; |
| 1633 | var offset = this.scrollbackRows_.length + cursorRow; |
| 1634 | for (var i = 0; i < count; i++) { |
| 1635 | var row = this.document_.createElement('x-row'); |
| 1636 | row.appendChild(this.document_.createTextNode('')); |
| 1637 | row.rowIndex = offset + i; |
| 1638 | this.screen_.pushRow(row); |
| 1639 | } |
| 1640 | |
| 1641 | var extraRows = this.screen_.rowsArray.length - this.screenSize.height; |
| 1642 | if (extraRows > 0) { |
| 1643 | var ary = this.screen_.shiftRows(extraRows); |
| 1644 | Array.prototype.push.apply(this.scrollbackRows_, ary); |
Robert Ginda | 36c5aa6 | 2012-10-15 11:17:47 -0700 | [diff] [blame] | 1645 | if (this.scrollPort_.isScrolledEnd) |
| 1646 | this.scheduleScrollDown_(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | if (cursorRow >= this.screen_.rowsArray.length) |
| 1650 | cursorRow = this.screen_.rowsArray.length - 1; |
| 1651 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1652 | this.setAbsoluteCursorPosition(cursorRow, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1653 | }; |
| 1654 | |
| 1655 | /** |
| 1656 | * Relocate rows from one part of the addressable screen to another. |
| 1657 | * |
| 1658 | * This is used to recycle rows during VT scrolls (those which are driven |
| 1659 | * by VT commands, rather than by the user manipulating the scrollbar.) |
| 1660 | * |
| 1661 | * In this case, the blank lines scrolled into the scroll region are made of |
| 1662 | * the nodes we scrolled off. These have their rowIndex properties carefully |
| 1663 | * renumbered so as not to confuse the ScrollPort. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1664 | * |
| 1665 | * @param {number} fromIndex The start index. |
| 1666 | * @param {number} count The number of rows to move. |
| 1667 | * @param {number} toIndex The destination index. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1668 | */ |
| 1669 | hterm.Terminal.prototype.moveRows_ = function(fromIndex, count, toIndex) { |
| 1670 | var ary = this.screen_.removeRows(fromIndex, count); |
| 1671 | this.screen_.insertRows(toIndex, ary); |
| 1672 | |
| 1673 | var start, end; |
| 1674 | if (fromIndex < toIndex) { |
| 1675 | start = fromIndex; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1676 | end = toIndex + count; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1677 | } else { |
| 1678 | start = toIndex; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1679 | end = fromIndex + count; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | this.renumberRows_(start, end); |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 1683 | this.scrollPort_.scheduleInvalidate(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1684 | }; |
| 1685 | |
| 1686 | /** |
| 1687 | * Renumber the rowIndex property of the given range of rows. |
| 1688 | * |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 1689 | * The start and end indices are relative to the screen, not the scrollback. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1690 | * Rows in the scrollback buffer cannot be renumbered. Since they are not |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 1691 | * addressable (you can't delete them, scroll them, etc), you should have |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1692 | * no need to renumber scrollback rows. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1693 | * |
| 1694 | * @param {number} start The start index. |
| 1695 | * @param {number} end The end index. |
| 1696 | * @param {hterm.Screen} opt_screen The screen to renumber. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1697 | */ |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 1698 | hterm.Terminal.prototype.renumberRows_ = function(start, end, opt_screen) { |
| 1699 | var screen = opt_screen || this.screen_; |
| 1700 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1701 | var offset = this.scrollbackRows_.length; |
| 1702 | for (var i = start; i < end; i++) { |
Robert Ginda | 4093289 | 2012-12-10 17:26:40 -0800 | [diff] [blame] | 1703 | screen.rowsArray[i].rowIndex = offset + i; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1704 | } |
| 1705 | }; |
| 1706 | |
| 1707 | /** |
| 1708 | * Print a string to the terminal. |
| 1709 | * |
| 1710 | * This respects the current insert and wraparound modes. It will add new lines |
| 1711 | * to the end of the terminal, scrolling off the top into the scrollback buffer |
| 1712 | * if necessary. |
| 1713 | * |
| 1714 | * The string is *not* parsed for escape codes. Use the interpret() method if |
| 1715 | * that's what you're after. |
| 1716 | * |
| 1717 | * @param{string} str The string to print. |
| 1718 | */ |
| 1719 | hterm.Terminal.prototype.print = function(str) { |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1720 | var startOffset = 0; |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 1721 | |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1722 | var strWidth = lib.wc.strWidth(str); |
Mike Frysinger | 67fc8ef | 2017-08-21 16:03:16 -0400 | [diff] [blame] | 1723 | // Fun edge case: If the string only contains zero width codepoints (like |
| 1724 | // combining characters), we make sure to iterate at least once below. |
| 1725 | if (strWidth == 0 && str) |
| 1726 | strWidth = 1; |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1727 | |
| 1728 | while (startOffset < strWidth) { |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 1729 | if (this.options_.wraparound && this.screen_.cursorPosition.overflow) { |
| 1730 | this.screen_.commitLineOverflow(); |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1731 | this.newLine(); |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 1732 | } |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1733 | |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1734 | var count = strWidth - startOffset; |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1735 | var didOverflow = false; |
| 1736 | var substr; |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1737 | |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1738 | if (this.screen_.cursorPosition.column + count >= this.screenSize.width) { |
| 1739 | didOverflow = true; |
| 1740 | count = this.screenSize.width - this.screen_.cursorPosition.column; |
| 1741 | } |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1742 | |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1743 | if (didOverflow && !this.options_.wraparound) { |
| 1744 | // If the string overflowed the line but wraparound is off, then the |
| 1745 | // last printed character should be the last of the string. |
| 1746 | // TODO: This will add to our problems with multibyte UTF-16 characters. |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1747 | substr = lib.wc.substr(str, startOffset, count - 1) + |
| 1748 | lib.wc.substr(str, strWidth - 1); |
| 1749 | count = strWidth; |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1750 | } else { |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1751 | substr = lib.wc.substr(str, startOffset, count); |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1752 | } |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1753 | |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1754 | var tokens = hterm.TextAttributes.splitWidecharString(substr); |
| 1755 | for (var i = 0; i < tokens.length; i++) { |
Mike Frysinger | 1e98c0f | 2017-08-15 01:21:31 -0400 | [diff] [blame] | 1756 | this.screen_.textAttributes.wcNode = tokens[i].wcNode; |
| 1757 | this.screen_.textAttributes.asciiNode = tokens[i].asciiNode; |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1758 | |
| 1759 | if (this.options_.insertMode) { |
Mike Frysinger | 6380bed | 2017-08-24 18:46:39 -0400 | [diff] [blame] | 1760 | this.screen_.insertString(tokens[i].str, tokens[i].wcStrWidth); |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1761 | } else { |
Mike Frysinger | 6380bed | 2017-08-24 18:46:39 -0400 | [diff] [blame] | 1762 | this.screen_.overwriteString(tokens[i].str, tokens[i].wcStrWidth); |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1763 | } |
| 1764 | this.screen_.textAttributes.wcNode = false; |
Mike Frysinger | 1e98c0f | 2017-08-15 01:21:31 -0400 | [diff] [blame] | 1765 | this.screen_.textAttributes.asciiNode = true; |
rginda | a9abdd8 | 2012-08-06 18:05:09 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | this.screen_.maybeClipCurrentRow(); |
| 1769 | startOffset += count; |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1770 | } |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1771 | |
| 1772 | this.scheduleSyncCursorPosition_(); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1773 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1774 | if (this.scrollOnOutput_) |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1775 | this.scrollPort_.scrollRowToBottom(this.getRowCount()); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1776 | }; |
| 1777 | |
| 1778 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1779 | * Set the VT scroll region. |
| 1780 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1781 | * This also resets the cursor position to the absolute (0, 0) position, since |
| 1782 | * that's what xterm appears to do. |
| 1783 | * |
Robert Ginda | 5b9fbe6 | 2013-10-30 14:05:53 -0700 | [diff] [blame] | 1784 | * Setting the scroll region to the full height of the terminal will clear |
| 1785 | * the scroll region. This is *NOT* what most terminals do. We're explicitly |
| 1786 | * going "off-spec" here because it makes `screen` and `tmux` overflow into the |
| 1787 | * local scrollback buffer, which means the scrollbars and shift-pgup/pgdn |
| 1788 | * continue to work as most users would expect. |
| 1789 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1790 | * @param {integer} scrollTop The zero-based top of the scroll region. |
| 1791 | * @param {integer} scrollBottom The zero-based bottom of the scroll region, |
| 1792 | * inclusive. |
| 1793 | */ |
| 1794 | hterm.Terminal.prototype.setVTScrollRegion = function(scrollTop, scrollBottom) { |
Robert Ginda | 5b9fbe6 | 2013-10-30 14:05:53 -0700 | [diff] [blame] | 1795 | if (scrollTop == 0 && scrollBottom == this.screenSize.height - 1) { |
Robert Ginda | 43684e2 | 2013-11-25 14:18:52 -0800 | [diff] [blame] | 1796 | this.vtScrollTop_ = null; |
| 1797 | this.vtScrollBottom_ = null; |
Robert Ginda | 5b9fbe6 | 2013-10-30 14:05:53 -0700 | [diff] [blame] | 1798 | } else { |
| 1799 | this.vtScrollTop_ = scrollTop; |
| 1800 | this.vtScrollBottom_ = scrollBottom; |
| 1801 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1802 | }; |
| 1803 | |
| 1804 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1805 | * Return the top row index according to the VT. |
| 1806 | * |
| 1807 | * This will return 0 unless the terminal has been told to restrict scrolling |
| 1808 | * to some lower row. It is used for some VT cursor positioning and scrolling |
| 1809 | * commands. |
| 1810 | * |
| 1811 | * @return {integer} The topmost row in the terminal's scroll region. |
| 1812 | */ |
| 1813 | hterm.Terminal.prototype.getVTScrollTop = function() { |
| 1814 | if (this.vtScrollTop_ != null) |
| 1815 | return this.vtScrollTop_; |
| 1816 | |
| 1817 | return 0; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1818 | }; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1819 | |
| 1820 | /** |
| 1821 | * Return the bottom row index according to the VT. |
| 1822 | * |
| 1823 | * This will return the height of the terminal unless the it has been told to |
| 1824 | * restrict scrolling to some higher row. It is used for some VT cursor |
| 1825 | * positioning and scrolling commands. |
| 1826 | * |
Zhu Qunying | 30d4071 | 2017-03-14 16:27:00 -0700 | [diff] [blame] | 1827 | * @return {integer} The bottom most row in the terminal's scroll region. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1828 | */ |
| 1829 | hterm.Terminal.prototype.getVTScrollBottom = function() { |
| 1830 | if (this.vtScrollBottom_ != null) |
| 1831 | return this.vtScrollBottom_; |
| 1832 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1833 | return this.screenSize.height - 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /** |
| 1837 | * Process a '\n' character. |
| 1838 | * |
| 1839 | * If the cursor is on the final row of the terminal this will append a new |
| 1840 | * blank row to the screen and scroll the topmost row into the scrollback |
| 1841 | * buffer. |
| 1842 | * |
| 1843 | * Otherwise, this moves the cursor to column zero of the next row. |
| 1844 | */ |
| 1845 | hterm.Terminal.prototype.newLine = function() { |
Robert Ginda | 9937abc | 2013-07-25 16:09:23 -0700 | [diff] [blame] | 1846 | var cursorAtEndOfScreen = (this.screen_.cursorPosition.row == |
| 1847 | this.screen_.rowsArray.length - 1); |
| 1848 | |
| 1849 | if (this.vtScrollBottom_ != null) { |
| 1850 | // A VT Scroll region is active, we never append new rows. |
| 1851 | if (this.screen_.cursorPosition.row == this.vtScrollBottom_) { |
| 1852 | // We're at the end of the VT Scroll Region, perform a VT scroll. |
| 1853 | this.vtScrollUp(1); |
| 1854 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0); |
| 1855 | } else if (cursorAtEndOfScreen) { |
| 1856 | // We're at the end of the screen, the only thing to do is put the |
| 1857 | // cursor to column 0. |
| 1858 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0); |
| 1859 | } else { |
| 1860 | // Anywhere else, advance the cursor row, and reset the column. |
| 1861 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0); |
| 1862 | } |
| 1863 | } else if (cursorAtEndOfScreen) { |
Robert Ginda | 1b06b37 | 2013-07-19 15:22:51 -0700 | [diff] [blame] | 1864 | // We're at the end of the screen. Append a new row to the terminal, |
| 1865 | // shifting the top row into the scrollback. |
| 1866 | this.appendRows_(1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1867 | } else { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1868 | // Anywhere else in the screen just moves the cursor. |
| 1869 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1870 | } |
| 1871 | }; |
| 1872 | |
| 1873 | /** |
| 1874 | * Like newLine(), except maintain the cursor column. |
| 1875 | */ |
| 1876 | hterm.Terminal.prototype.lineFeed = function() { |
| 1877 | var column = this.screen_.cursorPosition.column; |
| 1878 | this.newLine(); |
| 1879 | this.setCursorColumn(column); |
| 1880 | }; |
| 1881 | |
| 1882 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1883 | * If autoCarriageReturn is set then newLine(), else lineFeed(). |
| 1884 | */ |
| 1885 | hterm.Terminal.prototype.formFeed = function() { |
| 1886 | if (this.options_.autoCarriageReturn) { |
| 1887 | this.newLine(); |
| 1888 | } else { |
| 1889 | this.lineFeed(); |
| 1890 | } |
| 1891 | }; |
| 1892 | |
| 1893 | /** |
| 1894 | * Move the cursor up one row, possibly inserting a blank line. |
| 1895 | * |
| 1896 | * The cursor column is not changed. |
| 1897 | */ |
| 1898 | hterm.Terminal.prototype.reverseLineFeed = function() { |
| 1899 | var scrollTop = this.getVTScrollTop(); |
| 1900 | var currentRow = this.screen_.cursorPosition.row; |
| 1901 | |
| 1902 | if (currentRow == scrollTop) { |
| 1903 | this.insertLines(1); |
| 1904 | } else { |
| 1905 | this.setAbsoluteCursorRow(currentRow - 1); |
| 1906 | } |
| 1907 | }; |
| 1908 | |
| 1909 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1910 | * Replace all characters to the left of the current cursor with the space |
| 1911 | * character. |
| 1912 | * |
| 1913 | * TODO(rginda): This should probably *remove* the characters (not just replace |
| 1914 | * with a space) if there are no characters at or beyond the current cursor |
Robert Ginda | f2547f1 | 2012-10-25 20:36:21 -0700 | [diff] [blame] | 1915 | * position. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1916 | */ |
| 1917 | hterm.Terminal.prototype.eraseToLeft = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1918 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1919 | this.setCursorColumn(0); |
Mike Frysinger | 6380bed | 2017-08-24 18:46:39 -0400 | [diff] [blame] | 1920 | const count = cursor.column + 1; |
| 1921 | this.screen_.overwriteString(lib.f.getWhitespace(count), count); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1922 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1923 | }; |
| 1924 | |
| 1925 | /** |
David Benjamin | 684a9b7 | 2012-05-01 17:19:58 -0400 | [diff] [blame] | 1926 | * Erase a given number of characters to the right of the cursor. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1927 | * |
| 1928 | * The cursor position is unchanged. |
| 1929 | * |
Robert Ginda | f2547f1 | 2012-10-25 20:36:21 -0700 | [diff] [blame] | 1930 | * If the current background color is not the default background color this |
| 1931 | * will insert spaces rather than delete. This is unfortunate because the |
| 1932 | * trailing space will affect text selection, but it's difficult to come up |
| 1933 | * with a way to style empty space that wouldn't trip up the hterm.Screen |
| 1934 | * code. |
Robert Ginda | cd5637d | 2013-10-30 14:59:10 -0700 | [diff] [blame] | 1935 | * |
| 1936 | * eraseToRight is ignored in the presence of a cursor overflow. This deviates |
| 1937 | * from xterm, but agrees with gnome-terminal and konsole, xfce4-terminal. See |
| 1938 | * crbug.com/232390 for details. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 1939 | * |
| 1940 | * @param {number} opt_count The number of characters to erase. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1941 | */ |
| 1942 | hterm.Terminal.prototype.eraseToRight = function(opt_count) { |
Robert Ginda | cd5637d | 2013-10-30 14:59:10 -0700 | [diff] [blame] | 1943 | if (this.screen_.cursorPosition.overflow) |
| 1944 | return; |
| 1945 | |
Robert Ginda | 7fd5708 | 2012-09-25 14:41:47 -0700 | [diff] [blame] | 1946 | var maxCount = this.screenSize.width - this.screen_.cursorPosition.column; |
| 1947 | var count = opt_count ? Math.min(opt_count, maxCount) : maxCount; |
Robert Ginda | f2547f1 | 2012-10-25 20:36:21 -0700 | [diff] [blame] | 1948 | |
| 1949 | if (this.screen_.textAttributes.background === |
| 1950 | this.screen_.textAttributes.DEFAULT_COLOR) { |
| 1951 | var cursorRow = this.screen_.rowsArray[this.screen_.cursorPosition.row]; |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 1952 | if (hterm.TextAttributes.nodeWidth(cursorRow) <= |
Robert Ginda | f2547f1 | 2012-10-25 20:36:21 -0700 | [diff] [blame] | 1953 | this.screen_.cursorPosition.column + count) { |
| 1954 | this.screen_.deleteChars(count); |
| 1955 | this.clearCursorOverflow(); |
| 1956 | return; |
| 1957 | } |
| 1958 | } |
| 1959 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1960 | var cursor = this.saveCursor(); |
Mike Frysinger | 6380bed | 2017-08-24 18:46:39 -0400 | [diff] [blame] | 1961 | this.screen_.overwriteString(lib.f.getWhitespace(count), count); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1962 | this.restoreCursor(cursor); |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 1963 | this.clearCursorOverflow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1964 | }; |
| 1965 | |
| 1966 | /** |
| 1967 | * Erase the current line. |
| 1968 | * |
| 1969 | * The cursor position is unchanged. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1970 | */ |
| 1971 | hterm.Terminal.prototype.eraseLine = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1972 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1973 | this.screen_.clearCursorRow(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1974 | this.restoreCursor(cursor); |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 1975 | this.clearCursorOverflow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1976 | }; |
| 1977 | |
| 1978 | /** |
David Benjamin | a08d78f | 2012-05-05 00:28:49 -0400 | [diff] [blame] | 1979 | * Erase all characters from the start of the screen to the current cursor |
| 1980 | * position, regardless of scroll region. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1981 | * |
| 1982 | * The cursor position is unchanged. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1983 | */ |
| 1984 | hterm.Terminal.prototype.eraseAbove = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1985 | var cursor = this.saveCursor(); |
| 1986 | |
| 1987 | this.eraseToLeft(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1988 | |
David Benjamin | a08d78f | 2012-05-05 00:28:49 -0400 | [diff] [blame] | 1989 | for (var i = 0; i < cursor.row; i++) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1990 | this.setAbsoluteCursorPosition(i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1991 | this.screen_.clearCursorRow(); |
| 1992 | } |
| 1993 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1994 | this.restoreCursor(cursor); |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 1995 | this.clearCursorOverflow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1996 | }; |
| 1997 | |
| 1998 | /** |
| 1999 | * Erase all characters from the current cursor position to the end of the |
David Benjamin | a08d78f | 2012-05-05 00:28:49 -0400 | [diff] [blame] | 2000 | * screen, regardless of scroll region. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2001 | * |
| 2002 | * The cursor position is unchanged. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2003 | */ |
| 2004 | hterm.Terminal.prototype.eraseBelow = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2005 | var cursor = this.saveCursor(); |
| 2006 | |
| 2007 | this.eraseToRight(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2008 | |
David Benjamin | a08d78f | 2012-05-05 00:28:49 -0400 | [diff] [blame] | 2009 | var bottom = this.screenSize.height - 1; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2010 | for (var i = cursor.row + 1; i <= bottom; i++) { |
| 2011 | this.setAbsoluteCursorPosition(i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2012 | this.screen_.clearCursorRow(); |
| 2013 | } |
| 2014 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2015 | this.restoreCursor(cursor); |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 2016 | this.clearCursorOverflow(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2017 | }; |
| 2018 | |
| 2019 | /** |
| 2020 | * Fill the terminal with a given character. |
| 2021 | * |
| 2022 | * This methods does not respect the VT scroll region. |
| 2023 | * |
| 2024 | * @param {string} ch The character to use for the fill. |
| 2025 | */ |
| 2026 | hterm.Terminal.prototype.fill = function(ch) { |
| 2027 | var cursor = this.saveCursor(); |
| 2028 | |
| 2029 | this.setAbsoluteCursorPosition(0, 0); |
| 2030 | for (var row = 0; row < this.screenSize.height; row++) { |
| 2031 | for (var col = 0; col < this.screenSize.width; col++) { |
| 2032 | this.setAbsoluteCursorPosition(row, col); |
Mike Frysinger | 6380bed | 2017-08-24 18:46:39 -0400 | [diff] [blame] | 2033 | this.screen_.overwriteString(ch, 1); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2038 | }; |
| 2039 | |
| 2040 | /** |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 2041 | * Erase the entire display and leave the cursor at (0, 0). |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2042 | * |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 2043 | * This does not respect the scroll region. |
| 2044 | * |
| 2045 | * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults |
| 2046 | * to the current screen. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2047 | */ |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 2048 | hterm.Terminal.prototype.clearHome = function(opt_screen) { |
| 2049 | var screen = opt_screen || this.screen_; |
| 2050 | var bottom = screen.getHeight(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2051 | |
rginda | 11057d5 | 2012-04-25 12:29:56 -0700 | [diff] [blame] | 2052 | if (bottom == 0) { |
| 2053 | // Empty screen, nothing to do. |
| 2054 | return; |
| 2055 | } |
| 2056 | |
rginda | e4d2923 | 2012-01-19 10:47:13 -0800 | [diff] [blame] | 2057 | for (var i = 0; i < bottom; i++) { |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 2058 | screen.setCursorPosition(i, 0); |
| 2059 | screen.clearCursorRow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 2062 | screen.setCursorPosition(0, 0); |
| 2063 | }; |
| 2064 | |
| 2065 | /** |
| 2066 | * Erase the entire display without changing the cursor position. |
| 2067 | * |
| 2068 | * The cursor position is unchanged. This does not respect the scroll |
| 2069 | * region. |
| 2070 | * |
| 2071 | * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults |
| 2072 | * to the current screen. |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 2073 | */ |
| 2074 | hterm.Terminal.prototype.clear = function(opt_screen) { |
| 2075 | var screen = opt_screen || this.screen_; |
| 2076 | var cursor = screen.cursorPosition.clone(); |
| 2077 | this.clearHome(screen); |
| 2078 | screen.setCursorPosition(cursor.row, cursor.column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2079 | }; |
| 2080 | |
| 2081 | /** |
| 2082 | * VT command to insert lines at the current cursor row. |
| 2083 | * |
| 2084 | * This respects the current scroll region. Rows pushed off the bottom are |
| 2085 | * lost (they won't show up in the scrollback buffer). |
| 2086 | * |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2087 | * @param {integer} count The number of lines to insert. |
| 2088 | */ |
| 2089 | hterm.Terminal.prototype.insertLines = function(count) { |
Robert Ginda | 579186b | 2012-09-26 11:40:04 -0700 | [diff] [blame] | 2090 | var cursorRow = this.screen_.cursorPosition.row; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2091 | |
| 2092 | var bottom = this.getVTScrollBottom(); |
Robert Ginda | 579186b | 2012-09-26 11:40:04 -0700 | [diff] [blame] | 2093 | count = Math.min(count, bottom - cursorRow); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2094 | |
Robert Ginda | 579186b | 2012-09-26 11:40:04 -0700 | [diff] [blame] | 2095 | // The moveCount is the number of rows we need to relocate to make room for |
| 2096 | // the new row(s). The count is the distance to move them. |
| 2097 | var moveCount = bottom - cursorRow - count + 1; |
| 2098 | if (moveCount) |
| 2099 | this.moveRows_(cursorRow, moveCount, cursorRow + count); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2100 | |
Robert Ginda | 579186b | 2012-09-26 11:40:04 -0700 | [diff] [blame] | 2101 | for (var i = count - 1; i >= 0; i--) { |
| 2102 | this.setAbsoluteCursorPosition(cursorRow + i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2103 | this.screen_.clearCursorRow(); |
| 2104 | } |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2105 | }; |
| 2106 | |
| 2107 | /** |
| 2108 | * VT command to delete lines at the current cursor row. |
| 2109 | * |
| 2110 | * New rows are added to the bottom of scroll region to take their place. New |
| 2111 | * rows are strictly there to take up space and have no content or style. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2112 | * |
| 2113 | * @param {number} count The number of lines to delete. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2114 | */ |
| 2115 | hterm.Terminal.prototype.deleteLines = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2116 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2117 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2118 | var top = cursor.row; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2119 | var bottom = this.getVTScrollBottom(); |
| 2120 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2121 | var maxCount = bottom - top + 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2122 | count = Math.min(count, maxCount); |
| 2123 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2124 | var moveStart = bottom - count + 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2125 | if (count != maxCount) |
| 2126 | this.moveRows_(top, count, moveStart); |
| 2127 | |
| 2128 | for (var i = 0; i < count; i++) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2129 | this.setAbsoluteCursorPosition(moveStart + i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2130 | this.screen_.clearCursorRow(); |
| 2131 | } |
| 2132 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2133 | this.restoreCursor(cursor); |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 2134 | this.clearCursorOverflow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2135 | }; |
| 2136 | |
| 2137 | /** |
| 2138 | * Inserts the given number of spaces at the current cursor position. |
| 2139 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2140 | * The cursor position is not changed. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2141 | * |
| 2142 | * @param {number} count The number of spaces to insert. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2143 | */ |
| 2144 | hterm.Terminal.prototype.insertSpace = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2145 | var cursor = this.saveCursor(); |
| 2146 | |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 2147 | var ws = lib.f.getWhitespace(count || 1); |
Mike Frysinger | 6380bed | 2017-08-24 18:46:39 -0400 | [diff] [blame] | 2148 | this.screen_.insertString(ws, ws.length); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 2149 | this.screen_.maybeClipCurrentRow(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2150 | |
| 2151 | this.restoreCursor(cursor); |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 2152 | this.clearCursorOverflow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2153 | }; |
| 2154 | |
| 2155 | /** |
| 2156 | * Forward-delete the specified number of characters starting at the cursor |
| 2157 | * position. |
| 2158 | * |
| 2159 | * @param {integer} count The number of characters to delete. |
| 2160 | */ |
| 2161 | hterm.Terminal.prototype.deleteChars = function(count) { |
Robert Ginda | 7fd5708 | 2012-09-25 14:41:47 -0700 | [diff] [blame] | 2162 | var deleted = this.screen_.deleteChars(count); |
| 2163 | if (deleted && !this.screen_.textAttributes.isDefault()) { |
| 2164 | var cursor = this.saveCursor(); |
| 2165 | this.setCursorColumn(this.screenSize.width - deleted); |
| 2166 | this.screen_.insertString(lib.f.getWhitespace(deleted)); |
| 2167 | this.restoreCursor(cursor); |
| 2168 | } |
| 2169 | |
David Benjamin | 54e8bf6 | 2012-06-01 22:31:40 -0400 | [diff] [blame] | 2170 | this.clearCursorOverflow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2171 | }; |
| 2172 | |
| 2173 | /** |
| 2174 | * Shift rows in the scroll region upwards by a given number of lines. |
| 2175 | * |
| 2176 | * New rows are inserted at the bottom of the scroll region to fill the |
| 2177 | * vacated rows. The new rows not filled out with the current text attributes. |
| 2178 | * |
| 2179 | * This function does not affect the scrollback rows at all. Rows shifted |
| 2180 | * off the top are lost. |
| 2181 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2182 | * The cursor position is not altered. |
| 2183 | * |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2184 | * @param {integer} count The number of rows to scroll. |
| 2185 | */ |
| 2186 | hterm.Terminal.prototype.vtScrollUp = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2187 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2188 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2189 | this.setAbsoluteCursorRow(this.getVTScrollTop()); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2190 | this.deleteLines(count); |
| 2191 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2192 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2193 | }; |
| 2194 | |
| 2195 | /** |
| 2196 | * Shift rows below the cursor down by a given number of lines. |
| 2197 | * |
| 2198 | * This function respects the current scroll region. |
| 2199 | * |
| 2200 | * New rows are inserted at the top of the scroll region to fill the |
| 2201 | * vacated rows. The new rows not filled out with the current text attributes. |
| 2202 | * |
| 2203 | * This function does not affect the scrollback rows at all. Rows shifted |
| 2204 | * off the bottom are lost. |
| 2205 | * |
| 2206 | * @param {integer} count The number of rows to scroll. |
| 2207 | */ |
| 2208 | hterm.Terminal.prototype.vtScrollDown = function(opt_count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2209 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2210 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2211 | this.setAbsoluteCursorPosition(this.getVTScrollTop(), 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2212 | this.insertLines(opt_count); |
| 2213 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2214 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2215 | }; |
| 2216 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2217 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2218 | /** |
| 2219 | * Set the cursor position. |
| 2220 | * |
| 2221 | * The cursor row is relative to the scroll region if the terminal has |
| 2222 | * 'origin mode' enabled, or relative to the addressable screen otherwise. |
| 2223 | * |
| 2224 | * @param {integer} row The new zero-based cursor row. |
| 2225 | * @param {integer} row The new zero-based cursor column. |
| 2226 | */ |
| 2227 | hterm.Terminal.prototype.setCursorPosition = function(row, column) { |
| 2228 | if (this.options_.originMode) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2229 | this.setRelativeCursorPosition(row, column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2230 | } else { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2231 | this.setAbsoluteCursorPosition(row, column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2232 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2233 | }; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2234 | |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2235 | /** |
| 2236 | * Move the cursor relative to its current position. |
| 2237 | * |
| 2238 | * @param {number} row |
| 2239 | * @param {number} column |
| 2240 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2241 | hterm.Terminal.prototype.setRelativeCursorPosition = function(row, column) { |
| 2242 | var scrollTop = this.getVTScrollTop(); |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 2243 | row = lib.f.clamp(row + scrollTop, scrollTop, this.getVTScrollBottom()); |
| 2244 | column = lib.f.clamp(column, 0, this.screenSize.width - 1); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2245 | this.screen_.setCursorPosition(row, column); |
| 2246 | }; |
| 2247 | |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2248 | /** |
| 2249 | * Move the cursor to the specified position. |
| 2250 | * |
| 2251 | * @param {number} row |
| 2252 | * @param {number} column |
| 2253 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2254 | hterm.Terminal.prototype.setAbsoluteCursorPosition = function(row, column) { |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 2255 | row = lib.f.clamp(row, 0, this.screenSize.height - 1); |
| 2256 | column = lib.f.clamp(column, 0, this.screenSize.width - 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2257 | this.screen_.setCursorPosition(row, column); |
| 2258 | }; |
| 2259 | |
| 2260 | /** |
| 2261 | * Set the cursor column. |
| 2262 | * |
| 2263 | * @param {integer} column The new zero-based cursor column. |
| 2264 | */ |
| 2265 | hterm.Terminal.prototype.setCursorColumn = function(column) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2266 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2267 | }; |
| 2268 | |
| 2269 | /** |
| 2270 | * Return the cursor column. |
| 2271 | * |
| 2272 | * @return {integer} The zero-based cursor column. |
| 2273 | */ |
| 2274 | hterm.Terminal.prototype.getCursorColumn = function() { |
| 2275 | return this.screen_.cursorPosition.column; |
| 2276 | }; |
| 2277 | |
| 2278 | /** |
| 2279 | * Set the cursor row. |
| 2280 | * |
| 2281 | * The cursor row is relative to the scroll region if the terminal has |
| 2282 | * 'origin mode' enabled, or relative to the addressable screen otherwise. |
| 2283 | * |
| 2284 | * @param {integer} row The new cursor row. |
| 2285 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2286 | hterm.Terminal.prototype.setAbsoluteCursorRow = function(row) { |
| 2287 | this.setAbsoluteCursorPosition(row, this.screen_.cursorPosition.column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2288 | }; |
| 2289 | |
| 2290 | /** |
| 2291 | * Return the cursor row. |
| 2292 | * |
| 2293 | * @return {integer} The zero-based cursor row. |
| 2294 | */ |
Mike Frysinger | cf3c762 | 2017-04-21 11:37:33 -0400 | [diff] [blame] | 2295 | hterm.Terminal.prototype.getCursorRow = function() { |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2296 | return this.screen_.cursorPosition.row; |
| 2297 | }; |
| 2298 | |
| 2299 | /** |
| 2300 | * Request that the ScrollPort redraw itself soon. |
| 2301 | * |
| 2302 | * The redraw will happen asynchronously, soon after the call stack winds down. |
| 2303 | * Multiple calls will be coalesced into a single redraw. |
| 2304 | */ |
| 2305 | hterm.Terminal.prototype.scheduleRedraw_ = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2306 | if (this.timeouts_.redraw) |
| 2307 | return; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2308 | |
| 2309 | var self = this; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2310 | this.timeouts_.redraw = setTimeout(function() { |
| 2311 | delete self.timeouts_.redraw; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2312 | self.scrollPort_.redraw_(); |
| 2313 | }, 0); |
| 2314 | }; |
| 2315 | |
| 2316 | /** |
| 2317 | * Request that the ScrollPort be scrolled to the bottom. |
| 2318 | * |
| 2319 | * The scroll will happen asynchronously, soon after the call stack winds down. |
| 2320 | * Multiple calls will be coalesced into a single scroll. |
| 2321 | * |
| 2322 | * This affects the scrollbar position of the ScrollPort, and has nothing to |
| 2323 | * do with the VT scroll commands. |
| 2324 | */ |
| 2325 | hterm.Terminal.prototype.scheduleScrollDown_ = function() { |
| 2326 | if (this.timeouts_.scrollDown) |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2327 | return; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2328 | |
| 2329 | var self = this; |
| 2330 | this.timeouts_.scrollDown = setTimeout(function() { |
| 2331 | delete self.timeouts_.scrollDown; |
| 2332 | self.scrollPort_.scrollRowToBottom(self.getRowCount()); |
| 2333 | }, 10); |
| 2334 | }; |
| 2335 | |
| 2336 | /** |
| 2337 | * Move the cursor up a specified number of rows. |
| 2338 | * |
| 2339 | * @param {integer} count The number of rows to move the cursor. |
| 2340 | */ |
| 2341 | hterm.Terminal.prototype.cursorUp = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 2342 | return this.cursorDown(-(count || 1)); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2343 | }; |
| 2344 | |
| 2345 | /** |
| 2346 | * Move the cursor down a specified number of rows. |
| 2347 | * |
| 2348 | * @param {integer} count The number of rows to move the cursor. |
| 2349 | */ |
| 2350 | hterm.Terminal.prototype.cursorDown = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 2351 | count = count || 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2352 | var minHeight = (this.options_.originMode ? this.getVTScrollTop() : 0); |
| 2353 | var maxHeight = (this.options_.originMode ? this.getVTScrollBottom() : |
| 2354 | this.screenSize.height - 1); |
| 2355 | |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 2356 | var row = lib.f.clamp(this.screen_.cursorPosition.row + count, |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2357 | minHeight, maxHeight); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2358 | this.setAbsoluteCursorRow(row); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2359 | }; |
| 2360 | |
| 2361 | /** |
| 2362 | * Move the cursor left a specified number of columns. |
| 2363 | * |
Robert Ginda | aaba613 | 2014-07-16 16:33:07 -0700 | [diff] [blame] | 2364 | * If reverse wraparound mode is enabled and the previous row wrapped into |
| 2365 | * the current row then we back up through the wraparound as well. |
| 2366 | * |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2367 | * @param {integer} count The number of columns to move the cursor. |
| 2368 | */ |
| 2369 | hterm.Terminal.prototype.cursorLeft = function(count) { |
Robert Ginda | aaba613 | 2014-07-16 16:33:07 -0700 | [diff] [blame] | 2370 | count = count || 1; |
| 2371 | |
| 2372 | if (count < 1) |
| 2373 | return; |
| 2374 | |
| 2375 | var currentColumn = this.screen_.cursorPosition.column; |
Robert Ginda | bfb3262 | 2014-07-17 13:20:27 -0700 | [diff] [blame] | 2376 | if (this.options_.reverseWraparound) { |
| 2377 | if (this.screen_.cursorPosition.overflow) { |
| 2378 | // If this cursor is in the right margin, consume one count to get it |
| 2379 | // back to the last column. This only applies when we're in reverse |
| 2380 | // wraparound mode. |
| 2381 | count--; |
| 2382 | this.clearCursorOverflow(); |
| 2383 | |
| 2384 | if (!count) |
Robert Ginda | aaba613 | 2014-07-16 16:33:07 -0700 | [diff] [blame] | 2385 | return; |
Robert Ginda | aaba613 | 2014-07-16 16:33:07 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Robert Ginda | bfb3262 | 2014-07-17 13:20:27 -0700 | [diff] [blame] | 2388 | var newRow = this.screen_.cursorPosition.row; |
| 2389 | var newColumn = currentColumn - count; |
| 2390 | if (newColumn < 0) { |
| 2391 | newRow = newRow - Math.floor(count / this.screenSize.width) - 1; |
| 2392 | if (newRow < 0) { |
| 2393 | // xterm also wraps from row 0 to the last row. |
| 2394 | newRow = this.screenSize.height + newRow % this.screenSize.height; |
| 2395 | } |
| 2396 | newColumn = this.screenSize.width + newColumn % this.screenSize.width; |
| 2397 | } |
Robert Ginda | aaba613 | 2014-07-16 16:33:07 -0700 | [diff] [blame] | 2398 | |
Robert Ginda | bfb3262 | 2014-07-17 13:20:27 -0700 | [diff] [blame] | 2399 | this.setCursorPosition(Math.max(newRow, 0), newColumn); |
| 2400 | |
| 2401 | } else { |
| 2402 | var newColumn = Math.max(currentColumn - count, 0); |
| 2403 | this.setCursorColumn(newColumn); |
| 2404 | } |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2405 | }; |
| 2406 | |
| 2407 | /** |
| 2408 | * Move the cursor right a specified number of columns. |
| 2409 | * |
| 2410 | * @param {integer} count The number of columns to move the cursor. |
| 2411 | */ |
| 2412 | hterm.Terminal.prototype.cursorRight = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 2413 | count = count || 1; |
Robert Ginda | aaba613 | 2014-07-16 16:33:07 -0700 | [diff] [blame] | 2414 | |
| 2415 | if (count < 1) |
| 2416 | return; |
| 2417 | |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 2418 | var column = lib.f.clamp(this.screen_.cursorPosition.column + count, |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2419 | 0, this.screenSize.width - 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2420 | this.setCursorColumn(column); |
| 2421 | }; |
| 2422 | |
| 2423 | /** |
| 2424 | * Reverse the foreground and background colors of the terminal. |
| 2425 | * |
| 2426 | * This only affects text that was drawn with no attributes. |
| 2427 | * |
| 2428 | * TODO(rginda): Test xterm to see if reverse is respected for text that has |
| 2429 | * been drawn with attributes that happen to coincide with the default |
| 2430 | * 'no-attribute' colors. My guess is probably not. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2431 | * |
| 2432 | * @param {boolean} state The state to set. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2433 | */ |
| 2434 | hterm.Terminal.prototype.setReverseVideo = function(state) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2435 | this.options_.reverseVideo = state; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2436 | if (state) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 2437 | this.scrollPort_.setForegroundColor(this.prefs_.get('background-color')); |
| 2438 | this.scrollPort_.setBackgroundColor(this.prefs_.get('foreground-color')); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2439 | } else { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 2440 | this.scrollPort_.setForegroundColor(this.prefs_.get('foreground-color')); |
| 2441 | this.scrollPort_.setBackgroundColor(this.prefs_.get('background-color')); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2442 | } |
| 2443 | }; |
| 2444 | |
| 2445 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2446 | * Ring the terminal bell. |
Robert Ginda | 92e1810 | 2013-03-14 13:56:37 -0700 | [diff] [blame] | 2447 | * |
| 2448 | * This will not play the bell audio more than once per second. |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2449 | */ |
| 2450 | hterm.Terminal.prototype.ringBell = function() { |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 2451 | this.cursorNode_.style.backgroundColor = |
| 2452 | this.scrollPort_.getForegroundColor(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2453 | |
| 2454 | var self = this; |
| 2455 | setTimeout(function() { |
Matheus Fernandes | 2d73308 | 2017-09-11 06:43:01 -0400 | [diff] [blame] | 2456 | self.restyleCursor_(); |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 2457 | }, 200); |
Robert Ginda | 92e1810 | 2013-03-14 13:56:37 -0700 | [diff] [blame] | 2458 | |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 2459 | // bellSquelchTimeout_ affects both audio and notification bells. |
| 2460 | if (this.bellSquelchTimeout_) |
| 2461 | return; |
| 2462 | |
Robert Ginda | 92e1810 | 2013-03-14 13:56:37 -0700 | [diff] [blame] | 2463 | if (this.bellAudio_.getAttribute('src')) { |
Robert Ginda | 92e1810 | 2013-03-14 13:56:37 -0700 | [diff] [blame] | 2464 | this.bellAudio_.play(); |
Robert Ginda | 92e1810 | 2013-03-14 13:56:37 -0700 | [diff] [blame] | 2465 | this.bellSequelchTimeout_ = setTimeout(function() { |
| 2466 | delete this.bellSquelchTimeout_; |
Robert Ginda | a633137 | 2013-03-19 10:35:39 -0700 | [diff] [blame] | 2467 | }.bind(this), 500); |
Robert Ginda | 92e1810 | 2013-03-14 13:56:37 -0700 | [diff] [blame] | 2468 | } else { |
| 2469 | delete this.bellSquelchTimeout_; |
| 2470 | } |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 2471 | |
| 2472 | if (this.desktopNotificationBell_ && !this.document_.hasFocus()) { |
Mike Frysinger | a5fb83c | 2017-06-22 14:48:35 -0700 | [diff] [blame] | 2473 | var n = hterm.notify(); |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 2474 | this.bellNotificationList_.push(n); |
| 2475 | // TODO: Should we try to raise the window here? |
| 2476 | n.onclick = function() { self.closeBellNotifications_(); }; |
| 2477 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2478 | }; |
| 2479 | |
| 2480 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2481 | * Set the origin mode bit. |
| 2482 | * |
| 2483 | * If origin mode is on, certain VT cursor and scrolling commands measure their |
| 2484 | * row parameter relative to the VT scroll region. Otherwise, row 0 corresponds |
| 2485 | * to the top of the addressable screen. |
| 2486 | * |
| 2487 | * Defaults to off. |
| 2488 | * |
| 2489 | * @param {boolean} state True to set origin mode, false to unset. |
| 2490 | */ |
| 2491 | hterm.Terminal.prototype.setOriginMode = function(state) { |
| 2492 | this.options_.originMode = state; |
rginda | e4d2923 | 2012-01-19 10:47:13 -0800 | [diff] [blame] | 2493 | this.setCursorPosition(0, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2494 | }; |
| 2495 | |
| 2496 | /** |
| 2497 | * Set the insert mode bit. |
| 2498 | * |
| 2499 | * If insert mode is on, existing text beyond the cursor position will be |
| 2500 | * shifted right to make room for new text. Otherwise, new text overwrites |
| 2501 | * any existing text. |
| 2502 | * |
| 2503 | * Defaults to off. |
| 2504 | * |
| 2505 | * @param {boolean} state True to set insert mode, false to unset. |
| 2506 | */ |
| 2507 | hterm.Terminal.prototype.setInsertMode = function(state) { |
| 2508 | this.options_.insertMode = state; |
| 2509 | }; |
| 2510 | |
| 2511 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2512 | * Set the auto carriage return bit. |
| 2513 | * |
| 2514 | * If auto carriage return is on then a formfeed character is interpreted |
| 2515 | * as a newline, otherwise it's the same as a linefeed. The difference boils |
| 2516 | * down to whether or not the cursor column is reset. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2517 | * |
| 2518 | * @param {boolean} state The state to set. |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2519 | */ |
| 2520 | hterm.Terminal.prototype.setAutoCarriageReturn = function(state) { |
| 2521 | this.options_.autoCarriageReturn = state; |
| 2522 | }; |
| 2523 | |
| 2524 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2525 | * Set the wraparound mode bit. |
| 2526 | * |
| 2527 | * If wraparound mode is on, certain VT commands will allow the cursor to wrap |
| 2528 | * to the start of the following row. Otherwise, the cursor is clamped to the |
| 2529 | * end of the screen and attempts to write past it are ignored. |
| 2530 | * |
| 2531 | * Defaults to on. |
| 2532 | * |
| 2533 | * @param {boolean} state True to set wraparound mode, false to unset. |
| 2534 | */ |
| 2535 | hterm.Terminal.prototype.setWraparound = function(state) { |
| 2536 | this.options_.wraparound = state; |
| 2537 | }; |
| 2538 | |
| 2539 | /** |
| 2540 | * Set the reverse-wraparound mode bit. |
| 2541 | * |
| 2542 | * If wraparound mode is off, certain VT commands will allow the cursor to wrap |
| 2543 | * to the end of the previous row. Otherwise, the cursor is clamped to column |
| 2544 | * 0. |
| 2545 | * |
| 2546 | * Defaults to off. |
| 2547 | * |
| 2548 | * @param {boolean} state True to set reverse-wraparound mode, false to unset. |
| 2549 | */ |
| 2550 | hterm.Terminal.prototype.setReverseWraparound = function(state) { |
| 2551 | this.options_.reverseWraparound = state; |
| 2552 | }; |
| 2553 | |
| 2554 | /** |
| 2555 | * Selects between the primary and alternate screens. |
| 2556 | * |
| 2557 | * If alternate mode is on, the alternate screen is active. Otherwise the |
| 2558 | * primary screen is active. |
| 2559 | * |
| 2560 | * Swapping screens has no effect on the scrollback buffer. |
| 2561 | * |
| 2562 | * Each screen maintains its own cursor position. |
| 2563 | * |
| 2564 | * Defaults to off. |
| 2565 | * |
| 2566 | * @param {boolean} state True to set alternate mode, false to unset. |
| 2567 | */ |
| 2568 | hterm.Terminal.prototype.setAlternateMode = function(state) { |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 2569 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2570 | this.screen_ = state ? this.alternateScreen_ : this.primaryScreen_; |
| 2571 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 2572 | if (this.screen_.rowsArray.length && |
| 2573 | this.screen_.rowsArray[0].rowIndex != this.scrollbackRows_.length) { |
| 2574 | // If the screen changed sizes while we were away, our rowIndexes may |
| 2575 | // be incorrect. |
| 2576 | var offset = this.scrollbackRows_.length; |
| 2577 | var ary = this.screen_.rowsArray; |
rginda | cbbd748 | 2012-06-13 15:06:16 -0700 | [diff] [blame] | 2578 | for (var i = 0; i < ary.length; i++) { |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 2579 | ary[i].rowIndex = offset + i; |
| 2580 | } |
| 2581 | } |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2582 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 2583 | this.realizeWidth_(this.screenSize.width); |
| 2584 | this.realizeHeight_(this.screenSize.height); |
| 2585 | this.scrollPort_.syncScrollHeight(); |
| 2586 | this.scrollPort_.invalidate(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2587 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 2588 | this.restoreCursor(cursor); |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 2589 | this.scrollPort_.resize(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2590 | }; |
| 2591 | |
| 2592 | /** |
| 2593 | * Set the cursor-blink mode bit. |
| 2594 | * |
| 2595 | * If cursor-blink is on, the cursor will blink when it is visible. Otherwise |
| 2596 | * a visible cursor does not blink. |
| 2597 | * |
| 2598 | * You should make sure to turn blinking off if you're going to dispose of a |
| 2599 | * terminal, otherwise you'll leak a timeout. |
| 2600 | * |
| 2601 | * Defaults to on. |
| 2602 | * |
| 2603 | * @param {boolean} state True to set cursor-blink mode, false to unset. |
| 2604 | */ |
| 2605 | hterm.Terminal.prototype.setCursorBlink = function(state) { |
| 2606 | this.options_.cursorBlink = state; |
| 2607 | |
| 2608 | if (!state && this.timeouts_.cursorBlink) { |
| 2609 | clearTimeout(this.timeouts_.cursorBlink); |
| 2610 | delete this.timeouts_.cursorBlink; |
| 2611 | } |
| 2612 | |
| 2613 | if (this.options_.cursorVisible) |
| 2614 | this.setCursorVisible(true); |
| 2615 | }; |
| 2616 | |
| 2617 | /** |
| 2618 | * Set the cursor-visible mode bit. |
| 2619 | * |
| 2620 | * If cursor-visible is on, the cursor will be visible. Otherwise it will not. |
| 2621 | * |
| 2622 | * Defaults to on. |
| 2623 | * |
| 2624 | * @param {boolean} state True to set cursor-visible mode, false to unset. |
| 2625 | */ |
| 2626 | hterm.Terminal.prototype.setCursorVisible = function(state) { |
| 2627 | this.options_.cursorVisible = state; |
| 2628 | |
| 2629 | if (!state) { |
Brad Town | 1c2afa8 | 2015-03-11 21:36:58 -0700 | [diff] [blame] | 2630 | if (this.timeouts_.cursorBlink) { |
| 2631 | clearTimeout(this.timeouts_.cursorBlink); |
| 2632 | delete this.timeouts_.cursorBlink; |
| 2633 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2634 | this.cursorNode_.style.opacity = '0'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2635 | return; |
| 2636 | } |
| 2637 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2638 | this.syncCursorPosition_(); |
| 2639 | |
| 2640 | this.cursorNode_.style.opacity = '1'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2641 | |
| 2642 | if (this.options_.cursorBlink) { |
| 2643 | if (this.timeouts_.cursorBlink) |
| 2644 | return; |
| 2645 | |
Robert Ginda | ea2183e | 2014-07-17 09:51:51 -0700 | [diff] [blame] | 2646 | this.onCursorBlink_(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2647 | } else { |
| 2648 | if (this.timeouts_.cursorBlink) { |
| 2649 | clearTimeout(this.timeouts_.cursorBlink); |
| 2650 | delete this.timeouts_.cursorBlink; |
| 2651 | } |
| 2652 | } |
| 2653 | }; |
| 2654 | |
| 2655 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2656 | * Synchronizes the visible cursor and document selection with the current |
| 2657 | * cursor coordinates. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2658 | */ |
| 2659 | hterm.Terminal.prototype.syncCursorPosition_ = function() { |
| 2660 | var topRowIndex = this.scrollPort_.getTopRowIndex(); |
| 2661 | var bottomRowIndex = this.scrollPort_.getBottomRowIndex(topRowIndex); |
| 2662 | var cursorRowIndex = this.scrollbackRows_.length + |
| 2663 | this.screen_.cursorPosition.row; |
| 2664 | |
| 2665 | if (cursorRowIndex > bottomRowIndex) { |
| 2666 | // Cursor is scrolled off screen, move it outside of the visible area. |
Mike Frysinger | 44c3220 | 2017-08-05 01:13:09 -0400 | [diff] [blame] | 2667 | this.setCssVar('cursor-offset-row', '-1'); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2668 | return; |
| 2669 | } |
| 2670 | |
Robert Ginda | b837c05 | 2014-08-11 11:17:51 -0700 | [diff] [blame] | 2671 | if (this.options_.cursorVisible && |
| 2672 | this.cursorNode_.style.display == 'none') { |
| 2673 | // Re-display the terminal cursor if it was hidden by the mouse cursor. |
| 2674 | this.cursorNode_.style.display = ''; |
| 2675 | } |
| 2676 | |
Mike Frysinger | 44c3220 | 2017-08-05 01:13:09 -0400 | [diff] [blame] | 2677 | // Position the cursor using CSS variable math. If we do the math in JS, |
| 2678 | // the float math will end up being more precise than the CSS which will |
| 2679 | // cause the cursor tracking to be off. |
| 2680 | this.setCssVar( |
| 2681 | 'cursor-offset-row', |
| 2682 | `${cursorRowIndex - topRowIndex} + ` + |
| 2683 | `${this.scrollPort_.visibleRowTopMargin}px`); |
| 2684 | this.setCssVar('cursor-offset-col', this.screen_.cursorPosition.column); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2685 | |
| 2686 | this.cursorNode_.setAttribute('title', |
Mike Frysinger | 44c3220 | 2017-08-05 01:13:09 -0400 | [diff] [blame] | 2687 | '(' + this.screen_.cursorPosition.column + |
| 2688 | ', ' + this.screen_.cursorPosition.row + |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2689 | ')'); |
| 2690 | |
| 2691 | // Update the caret for a11y purposes. |
| 2692 | var selection = this.document_.getSelection(); |
| 2693 | if (selection && selection.isCollapsed) |
| 2694 | this.screen_.syncSelectionCaret(selection); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2695 | }; |
| 2696 | |
Robert Ginda | fb1be6a | 2013-12-11 11:56:22 -0800 | [diff] [blame] | 2697 | /** |
| 2698 | * Adjusts the style of this.cursorNode_ according to the current cursor shape |
| 2699 | * and character cell dimensions. |
| 2700 | */ |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 2701 | hterm.Terminal.prototype.restyleCursor_ = function() { |
| 2702 | var shape = this.cursorShape_; |
| 2703 | |
| 2704 | if (this.cursorNode_.getAttribute('focus') == 'false') { |
| 2705 | // Always show a block cursor when unfocused. |
| 2706 | shape = hterm.Terminal.cursorShape.BLOCK; |
| 2707 | } |
| 2708 | |
| 2709 | var style = this.cursorNode_.style; |
| 2710 | |
| 2711 | switch (shape) { |
| 2712 | case hterm.Terminal.cursorShape.BEAM: |
Mike Frysinger | 66beb0b | 2017-05-30 19:44:51 -0400 | [diff] [blame] | 2713 | style.height = 'var(--hterm-charsize-height)'; |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 2714 | style.backgroundColor = 'transparent'; |
| 2715 | style.borderBottomStyle = null; |
| 2716 | style.borderLeftStyle = 'solid'; |
| 2717 | break; |
| 2718 | |
| 2719 | case hterm.Terminal.cursorShape.UNDERLINE: |
| 2720 | style.height = this.scrollPort_.characterSize.baseline + 'px'; |
| 2721 | style.backgroundColor = 'transparent'; |
| 2722 | style.borderBottomStyle = 'solid'; |
| 2723 | // correct the size to put it exactly at the baseline |
| 2724 | style.borderLeftStyle = null; |
| 2725 | break; |
| 2726 | |
| 2727 | default: |
Mike Frysinger | 66beb0b | 2017-05-30 19:44:51 -0400 | [diff] [blame] | 2728 | style.height = 'var(--hterm-charsize-height)'; |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 2729 | style.backgroundColor = this.cursorColor_; |
| 2730 | style.borderBottomStyle = null; |
| 2731 | style.borderLeftStyle = null; |
| 2732 | break; |
| 2733 | } |
| 2734 | }; |
| 2735 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2736 | /** |
| 2737 | * Synchronizes the visible cursor with the current cursor coordinates. |
| 2738 | * |
| 2739 | * The sync will happen asynchronously, soon after the call stack winds down. |
| 2740 | * Multiple calls will be coalesced into a single sync. |
| 2741 | */ |
| 2742 | hterm.Terminal.prototype.scheduleSyncCursorPosition_ = function() { |
| 2743 | if (this.timeouts_.syncCursor) |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2744 | return; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 2745 | |
| 2746 | var self = this; |
| 2747 | this.timeouts_.syncCursor = setTimeout(function() { |
| 2748 | self.syncCursorPosition_(); |
| 2749 | delete self.timeouts_.syncCursor; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 2750 | }, 0); |
| 2751 | }; |
| 2752 | |
rginda | cc2996c | 2012-02-24 14:59:31 -0800 | [diff] [blame] | 2753 | /** |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 2754 | * Show or hide the zoom warning. |
| 2755 | * |
| 2756 | * The zoom warning is a message warning the user that their browser zoom must |
| 2757 | * be set to 100% in order for hterm to function properly. |
| 2758 | * |
| 2759 | * @param {boolean} state True to show the message, false to hide it. |
| 2760 | */ |
| 2761 | hterm.Terminal.prototype.showZoomWarning_ = function(state) { |
| 2762 | if (!this.zoomWarningNode_) { |
| 2763 | if (!state) |
| 2764 | return; |
| 2765 | |
| 2766 | this.zoomWarningNode_ = this.document_.createElement('div'); |
Mike Frysinger | d826f1a | 2017-07-06 16:20:06 -0400 | [diff] [blame] | 2767 | this.zoomWarningNode_.id = 'hterm:zoom-warning'; |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 2768 | this.zoomWarningNode_.style.cssText = ( |
| 2769 | 'color: black;' + |
| 2770 | 'background-color: #ff2222;' + |
| 2771 | 'font-size: large;' + |
| 2772 | 'border-radius: 8px;' + |
| 2773 | 'opacity: 0.75;' + |
| 2774 | 'padding: 0.2em 0.5em 0.2em 0.5em;' + |
| 2775 | 'top: 0.5em;' + |
| 2776 | 'right: 1.2em;' + |
| 2777 | 'position: absolute;' + |
| 2778 | '-webkit-text-size-adjust: none;' + |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 2779 | '-webkit-user-select: none;' + |
| 2780 | '-moz-text-size-adjust: none;' + |
| 2781 | '-moz-user-select: none;'); |
Mike Frysinger | 4c0c5e0 | 2016-03-12 23:11:25 -0500 | [diff] [blame] | 2782 | |
| 2783 | this.zoomWarningNode_.addEventListener('click', function(e) { |
| 2784 | this.parentNode.removeChild(this); |
| 2785 | }); |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Robert Ginda | b4839c2 | 2013-02-28 16:52:10 -0800 | [diff] [blame] | 2788 | this.zoomWarningNode_.textContent = lib.MessageManager.replaceReferences( |
| 2789 | hterm.zoomWarningMessage, |
| 2790 | [parseInt(this.scrollPort_.characterSize.zoomFactor * 100)]); |
| 2791 | |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 2792 | this.zoomWarningNode_.style.fontFamily = this.prefs_.get('font-family'); |
| 2793 | |
| 2794 | if (state) { |
| 2795 | if (!this.zoomWarningNode_.parentNode) |
| 2796 | this.div_.parentNode.appendChild(this.zoomWarningNode_); |
| 2797 | } else if (this.zoomWarningNode_.parentNode) { |
| 2798 | this.zoomWarningNode_.parentNode.removeChild(this.zoomWarningNode_); |
| 2799 | } |
| 2800 | }; |
| 2801 | |
| 2802 | /** |
rginda | cc2996c | 2012-02-24 14:59:31 -0800 | [diff] [blame] | 2803 | * Show the terminal overlay for a given amount of time. |
| 2804 | * |
| 2805 | * The terminal overlay appears in inverse video in a large font, centered |
| 2806 | * over the terminal. You should probably keep the overlay message brief, |
| 2807 | * since it's in a large font and you probably aren't going to check the size |
| 2808 | * of the terminal first. |
| 2809 | * |
| 2810 | * @param {string} msg The text (not HTML) message to display in the overlay. |
| 2811 | * @param {number} opt_timeout The amount of time to wait before fading out |
| 2812 | * the overlay. Defaults to 1.5 seconds. Pass null to have the overlay |
| 2813 | * stay up forever (or until the next overlay). |
| 2814 | */ |
| 2815 | hterm.Terminal.prototype.showOverlay = function(msg, opt_timeout) { |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2816 | if (!this.overlayNode_) { |
| 2817 | if (!this.div_) |
| 2818 | return; |
| 2819 | |
| 2820 | this.overlayNode_ = this.document_.createElement('div'); |
| 2821 | this.overlayNode_.style.cssText = ( |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2822 | 'border-radius: 15px;' + |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2823 | 'font-size: xx-large;' + |
| 2824 | 'opacity: 0.75;' + |
| 2825 | 'padding: 0.2em 0.5em 0.2em 0.5em;' + |
| 2826 | 'position: absolute;' + |
| 2827 | '-webkit-user-select: none;' + |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 2828 | '-webkit-transition: opacity 180ms ease-in;' + |
| 2829 | '-moz-user-select: none;' + |
| 2830 | '-moz-transition: opacity 180ms ease-in;'); |
Robert Ginda | 70926e4 | 2013-11-25 14:56:36 -0800 | [diff] [blame] | 2831 | |
| 2832 | this.overlayNode_.addEventListener('mousedown', function(e) { |
| 2833 | e.preventDefault(); |
| 2834 | e.stopPropagation(); |
| 2835 | }, true); |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2836 | } |
| 2837 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 2838 | this.overlayNode_.style.color = this.prefs_.get('background-color'); |
| 2839 | this.overlayNode_.style.backgroundColor = this.prefs_.get('foreground-color'); |
| 2840 | this.overlayNode_.style.fontFamily = this.prefs_.get('font-family'); |
| 2841 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2842 | this.overlayNode_.textContent = msg; |
| 2843 | this.overlayNode_.style.opacity = '0.75'; |
| 2844 | |
| 2845 | if (!this.overlayNode_.parentNode) |
| 2846 | this.div_.appendChild(this.overlayNode_); |
| 2847 | |
Robert Ginda | 9776928 | 2013-02-01 15:30:30 -0800 | [diff] [blame] | 2848 | var divSize = hterm.getClientSize(this.div_); |
| 2849 | var overlaySize = hterm.getClientSize(this.overlayNode_); |
| 2850 | |
Robert Ginda | 8a59f76 | 2014-07-23 11:29:55 -0700 | [diff] [blame] | 2851 | this.overlayNode_.style.top = |
| 2852 | (divSize.height - overlaySize.height) / 2 + 'px'; |
Robert Ginda | 9776928 | 2013-02-01 15:30:30 -0800 | [diff] [blame] | 2853 | this.overlayNode_.style.left = (divSize.width - overlaySize.width - |
Robert Ginda | 8a59f76 | 2014-07-23 11:29:55 -0700 | [diff] [blame] | 2854 | this.scrollPort_.currentScrollbarWidthPx) / 2 + 'px'; |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2855 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2856 | if (this.overlayTimeout_) |
| 2857 | clearTimeout(this.overlayTimeout_); |
| 2858 | |
rginda | cc2996c | 2012-02-24 14:59:31 -0800 | [diff] [blame] | 2859 | if (opt_timeout === null) |
| 2860 | return; |
| 2861 | |
Mike Frysinger | b6cfded | 2017-09-18 00:39:31 -0400 | [diff] [blame] | 2862 | this.overlayTimeout_ = setTimeout(() => { |
| 2863 | this.overlayNode_.style.opacity = '0'; |
| 2864 | this.overlayTimeout_ = setTimeout(() => this.hideOverlay(), 200); |
| 2865 | }, opt_timeout || 1500); |
| 2866 | }; |
| 2867 | |
| 2868 | /** |
| 2869 | * Hide the terminal overlay immediately. |
| 2870 | * |
| 2871 | * Useful when we show an overlay for an event with an unknown end time. |
| 2872 | */ |
| 2873 | hterm.Terminal.prototype.hideOverlay = function() { |
| 2874 | if (this.overlayTimeout_) |
| 2875 | clearTimeout(this.overlayTimeout_); |
| 2876 | this.overlayTimeout_ = null; |
| 2877 | |
| 2878 | if (this.overlayNode_.parentNode) |
| 2879 | this.overlayNode_.parentNode.removeChild(this.overlayNode_); |
| 2880 | this.overlayNode_.style.opacity = '0.75'; |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 2881 | }; |
| 2882 | |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2883 | /** |
| 2884 | * Paste from the system clipboard to the terminal. |
| 2885 | */ |
| 2886 | hterm.Terminal.prototype.paste = function() { |
Mike Frysinger | 4628ad2 | 2017-07-20 02:44:20 -0400 | [diff] [blame] | 2887 | return hterm.pasteFromClipboard(this.document_); |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2888 | }; |
| 2889 | |
| 2890 | /** |
| 2891 | * Copy a string to the system clipboard. |
| 2892 | * |
| 2893 | * Note: If there is a selected range in the terminal, it'll be cleared. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2894 | * |
| 2895 | * @param {string} str The string to copy. |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2896 | */ |
| 2897 | hterm.Terminal.prototype.copyStringToClipboard = function(str) { |
Robert Ginda | 4e4d42c | 2014-03-04 14:07:23 -0800 | [diff] [blame] | 2898 | if (this.prefs_.get('enable-clipboard-notice')) |
| 2899 | setTimeout(this.showOverlay.bind(this, hterm.notifyCopyMessage, 500), 200); |
| 2900 | |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2901 | var copySource = this.document_.createElement('pre'); |
Mike Frysinger | d826f1a | 2017-07-06 16:20:06 -0400 | [diff] [blame] | 2902 | copySource.id = 'hterm:copy-to-clipboard-source'; |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2903 | copySource.textContent = str; |
| 2904 | copySource.style.cssText = ( |
| 2905 | '-webkit-user-select: text;' + |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 2906 | '-moz-user-select: text;' + |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2907 | 'position: absolute;' + |
| 2908 | 'top: -99px'); |
| 2909 | |
| 2910 | this.document_.body.appendChild(copySource); |
rginda | faa7474 | 2012-08-21 13:34:03 -0700 | [diff] [blame] | 2911 | |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2912 | var selection = this.document_.getSelection(); |
rginda | faa7474 | 2012-08-21 13:34:03 -0700 | [diff] [blame] | 2913 | var anchorNode = selection.anchorNode; |
| 2914 | var anchorOffset = selection.anchorOffset; |
| 2915 | var focusNode = selection.focusNode; |
| 2916 | var focusOffset = selection.focusOffset; |
| 2917 | |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2918 | selection.selectAllChildren(copySource); |
| 2919 | |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2920 | hterm.copySelectionToClipboard(this.document_); |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2921 | |
Rob Spies | 5695341 | 2014-04-28 14:09:47 -0700 | [diff] [blame] | 2922 | // IE doesn't support selection.extend. This means that the selection |
| 2923 | // won't return on IE. |
Robert Ginda | 6f4f0aa | 2014-07-28 10:21:39 -0700 | [diff] [blame] | 2924 | if (selection.extend) { |
Rob Spies | 5695341 | 2014-04-28 14:09:47 -0700 | [diff] [blame] | 2925 | selection.collapse(anchorNode, anchorOffset); |
| 2926 | selection.extend(focusNode, focusOffset); |
| 2927 | } |
rginda | faa7474 | 2012-08-21 13:34:03 -0700 | [diff] [blame] | 2928 | |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2929 | copySource.parentNode.removeChild(copySource); |
| 2930 | }; |
| 2931 | |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 2932 | /** |
| 2933 | * Returns the selected text, or null if no text is selected. |
| 2934 | * |
| 2935 | * @return {string|null} |
| 2936 | */ |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2937 | hterm.Terminal.prototype.getSelectionText = function() { |
| 2938 | var selection = this.scrollPort_.selection; |
| 2939 | selection.sync(); |
| 2940 | |
| 2941 | if (selection.isCollapsed) |
| 2942 | return null; |
| 2943 | |
| 2944 | |
| 2945 | // Start offset measures from the beginning of the line. |
| 2946 | var startOffset = selection.startOffset; |
| 2947 | var node = selection.startNode; |
Robert Ginda | 0d19050 | 2012-10-02 10:59:00 -0700 | [diff] [blame] | 2948 | |
Robert Ginda | fdbb3f2 | 2012-09-06 20:23:06 -0700 | [diff] [blame] | 2949 | if (node.nodeName != 'X-ROW') { |
| 2950 | // If the selection doesn't start on an x-row node, then it must be |
| 2951 | // somewhere inside the x-row. Add any characters from previous siblings |
| 2952 | // into the start offset. |
Robert Ginda | 0d19050 | 2012-10-02 10:59:00 -0700 | [diff] [blame] | 2953 | |
| 2954 | if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') { |
| 2955 | // If node is the text node in a styled span, move up to the span node. |
| 2956 | node = node.parentNode; |
| 2957 | } |
| 2958 | |
Robert Ginda | fdbb3f2 | 2012-09-06 20:23:06 -0700 | [diff] [blame] | 2959 | while (node.previousSibling) { |
| 2960 | node = node.previousSibling; |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 2961 | startOffset += hterm.TextAttributes.nodeWidth(node); |
Robert Ginda | fdbb3f2 | 2012-09-06 20:23:06 -0700 | [diff] [blame] | 2962 | } |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | // End offset measures from the end of the line. |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 2966 | var endOffset = (hterm.TextAttributes.nodeWidth(selection.endNode) - |
| 2967 | selection.endOffset); |
Evan Jones | 5f9df81 | 2016-12-06 09:38:58 -0500 | [diff] [blame] | 2968 | node = selection.endNode; |
Robert Ginda | 0d19050 | 2012-10-02 10:59:00 -0700 | [diff] [blame] | 2969 | |
Robert Ginda | fdbb3f2 | 2012-09-06 20:23:06 -0700 | [diff] [blame] | 2970 | if (node.nodeName != 'X-ROW') { |
| 2971 | // If the selection doesn't end on an x-row node, then it must be |
| 2972 | // somewhere inside the x-row. Add any characters from following siblings |
| 2973 | // into the end offset. |
Robert Ginda | 0d19050 | 2012-10-02 10:59:00 -0700 | [diff] [blame] | 2974 | |
| 2975 | if (node.nodeName == '#text' && node.parentNode.nodeName == 'SPAN') { |
| 2976 | // If node is the text node in a styled span, move up to the span node. |
| 2977 | node = node.parentNode; |
| 2978 | } |
| 2979 | |
Robert Ginda | fdbb3f2 | 2012-09-06 20:23:06 -0700 | [diff] [blame] | 2980 | while (node.nextSibling) { |
| 2981 | node = node.nextSibling; |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 2982 | endOffset += hterm.TextAttributes.nodeWidth(node); |
Robert Ginda | fdbb3f2 | 2012-09-06 20:23:06 -0700 | [diff] [blame] | 2983 | } |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | var rv = this.getRowsText(selection.startRow.rowIndex, |
| 2987 | selection.endRow.rowIndex + 1); |
Ricky Liang | 48f05cb | 2013-12-31 23:35:29 +0800 | [diff] [blame] | 2988 | return lib.wc.substring(rv, startOffset, lib.wc.strWidth(rv) - endOffset); |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2989 | }; |
| 2990 | |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2991 | /** |
| 2992 | * Copy the current selection to the system clipboard, then clear it after a |
| 2993 | * short delay. |
| 2994 | */ |
| 2995 | hterm.Terminal.prototype.copySelectionToClipboard = function() { |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 2996 | var text = this.getSelectionText(); |
| 2997 | if (text != null) |
| 2998 | this.copyStringToClipboard(text); |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 2999 | }; |
| 3000 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 3001 | hterm.Terminal.prototype.overlaySize = function() { |
| 3002 | this.showOverlay(this.screenSize.width + 'x' + this.screenSize.height); |
| 3003 | }; |
| 3004 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 3005 | /** |
| 3006 | * Invoked by hterm.Terminal.Keyboard when a VT keystroke is detected. |
| 3007 | * |
Robert Ginda | 8cb7d90 | 2013-06-20 14:37:18 -0700 | [diff] [blame] | 3008 | * @param {string} string The VT string representing the keystroke, in UTF-16. |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 3009 | */ |
| 3010 | hterm.Terminal.prototype.onVTKeystroke = function(string) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 3011 | if (this.scrollOnKeystroke_) |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 3012 | this.scrollPort_.scrollRowToBottom(this.getRowCount()); |
| 3013 | |
Robert Ginda | 8cb7d90 | 2013-06-20 14:37:18 -0700 | [diff] [blame] | 3014 | this.io.onVTKeystroke(this.keyboard.encode(string)); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3015 | }; |
| 3016 | |
| 3017 | /** |
Mike Frysinger | 70b9469 | 2017-01-26 18:57:50 -1000 | [diff] [blame] | 3018 | * Open the selected url. |
| 3019 | */ |
| 3020 | hterm.Terminal.prototype.openSelectedUrl_ = function() { |
| 3021 | var str = this.getSelectionText(); |
| 3022 | |
| 3023 | // If there is no selection, try and expand wherever they clicked. |
| 3024 | if (str == null) { |
| 3025 | this.screen_.expandSelection(this.document_.getSelection()); |
| 3026 | str = this.getSelectionText(); |
Mike Frysinger | 498192d | 2017-06-26 18:23:31 -0400 | [diff] [blame] | 3027 | |
| 3028 | // If clicking in empty space, return. |
| 3029 | if (str == null) |
| 3030 | return; |
Mike Frysinger | 70b9469 | 2017-01-26 18:57:50 -1000 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | // Make sure URL is valid before opening. |
| 3034 | if (str.length > 2048 || str.search(/[\s\[\](){}<>"'\\^`]/) >= 0) |
| 3035 | return; |
Mike Frysinger | 4347262 | 2017-06-26 18:11:07 -0400 | [diff] [blame] | 3036 | |
| 3037 | // If the URI isn't anchored, it'll open relative to the extension. |
Mike Frysinger | 70b9469 | 2017-01-26 18:57:50 -1000 | [diff] [blame] | 3038 | // We have no way of knowing the correct schema, so assume http. |
Mike Frysinger | 4347262 | 2017-06-26 18:11:07 -0400 | [diff] [blame] | 3039 | if (str.search('^[a-zA-Z][a-zA-Z0-9+.-]*://') < 0) { |
| 3040 | // We have to whitelist a few protocols that lack authorities and thus |
| 3041 | // never use the //. Like mailto. |
| 3042 | switch (str.split(':', 1)[0]) { |
| 3043 | case 'mailto': |
| 3044 | break; |
| 3045 | default: |
| 3046 | str = 'http://' + str; |
| 3047 | break; |
| 3048 | } |
| 3049 | } |
Mike Frysinger | 70b9469 | 2017-01-26 18:57:50 -1000 | [diff] [blame] | 3050 | |
Mike Frysinger | 720fa83 | 2017-10-23 01:15:52 -0400 | [diff] [blame] | 3051 | hterm.openUrl(str); |
Mike Frysinger | 70b9469 | 2017-01-26 18:57:50 -1000 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | /** |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3056 | * Add the terminalRow and terminalColumn properties to mouse events and |
| 3057 | * then forward on to onMouse(). |
| 3058 | * |
| 3059 | * The terminalRow and terminalColumn properties contain the (row, column) |
| 3060 | * coordinates for the mouse event. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 3061 | * |
| 3062 | * @param {Event} e The mouse event to handle. |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3063 | */ |
| 3064 | hterm.Terminal.prototype.onMouse_ = function(e) { |
rginda | faa7474 | 2012-08-21 13:34:03 -0700 | [diff] [blame] | 3065 | if (e.processedByTerminalHandler_) { |
| 3066 | // We register our event handlers on the document, as well as the cursor |
| 3067 | // and the scroll blocker. Mouse events that occur on the cursor or |
| 3068 | // scroll blocker will also appear on the document, but we don't want to |
| 3069 | // process them twice. |
| 3070 | // |
| 3071 | // We can't just prevent bubbling because that has other side effects, so |
| 3072 | // we decorate the event object with this property instead. |
| 3073 | return; |
| 3074 | } |
| 3075 | |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3076 | var reportMouseEvents = (!this.defeatMouseReports_ && |
| 3077 | this.vt.mouseReport != this.vt.MOUSE_REPORT_DISABLED); |
| 3078 | |
rginda | faa7474 | 2012-08-21 13:34:03 -0700 | [diff] [blame] | 3079 | e.processedByTerminalHandler_ = true; |
| 3080 | |
Robert Ginda | eda48db | 2014-07-17 09:25:30 -0700 | [diff] [blame] | 3081 | // One based row/column stored on the mouse event. |
| 3082 | e.terminalRow = parseInt((e.clientY - this.scrollPort_.visibleRowTopMargin) / |
| 3083 | this.scrollPort_.characterSize.height) + 1; |
| 3084 | e.terminalColumn = parseInt(e.clientX / |
| 3085 | this.scrollPort_.characterSize.width) + 1; |
| 3086 | |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3087 | if (e.type == 'mousedown' && e.terminalColumn > this.screenSize.width) { |
| 3088 | // Mousedown in the scrollbar area. |
rginda | 4bba5e1 | 2012-06-20 16:15:30 -0700 | [diff] [blame] | 3089 | return; |
| 3090 | } |
| 3091 | |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3092 | if (this.options_.cursorVisible && !reportMouseEvents) { |
Robert Ginda | b837c05 | 2014-08-11 11:17:51 -0700 | [diff] [blame] | 3093 | // If the cursor is visible and we're not sending mouse events to the |
| 3094 | // host app, then we want to hide the terminal cursor when the mouse |
| 3095 | // cursor is over top. This keeps the terminal cursor from interfering |
| 3096 | // with local text selection. |
Robert Ginda | eda48db | 2014-07-17 09:25:30 -0700 | [diff] [blame] | 3097 | if (e.terminalRow - 1 == this.screen_.cursorPosition.row && |
| 3098 | e.terminalColumn - 1 == this.screen_.cursorPosition.column) { |
| 3099 | this.cursorNode_.style.display = 'none'; |
| 3100 | } else if (this.cursorNode_.style.display == 'none') { |
| 3101 | this.cursorNode_.style.display = ''; |
| 3102 | } |
| 3103 | } |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3104 | |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3105 | if (e.type == 'mousedown') { |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3106 | if (e.altKey || !reportMouseEvents) { |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3107 | // If VT mouse reporting is disabled, or has been defeated with |
| 3108 | // alt-mousedown, then the mouse will act on the local selection. |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3109 | this.defeatMouseReports_ = true; |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3110 | this.setSelectionEnabled(true); |
| 3111 | } else { |
| 3112 | // Otherwise we defer ownership of the mouse to the VT. |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3113 | this.defeatMouseReports_ = false; |
Robert Ginda | 3ae3782 | 2014-05-15 13:05:35 -0700 | [diff] [blame] | 3114 | this.document_.getSelection().collapseToEnd(); |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3115 | this.setSelectionEnabled(false); |
| 3116 | e.preventDefault(); |
| 3117 | } |
| 3118 | } |
| 3119 | |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3120 | if (!reportMouseEvents) { |
Robert Ginda | 15ed490 | 2016-07-12 10:43:22 -0700 | [diff] [blame] | 3121 | if (e.type == 'dblclick' && this.copyOnSelect) { |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3122 | this.screen_.expandSelection(this.document_.getSelection()); |
Robert Ginda | 15ed490 | 2016-07-12 10:43:22 -0700 | [diff] [blame] | 3123 | this.copySelectionToClipboard(this.document_); |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
Mihir Nimbalkar | 467fd8b | 2017-07-12 12:14:16 -0700 | [diff] [blame] | 3126 | if (e.type == 'click' && !e.shiftKey && (e.ctrlKey || e.metaKey)) { |
Mike Frysinger | 70b9469 | 2017-01-26 18:57:50 -1000 | [diff] [blame] | 3127 | // Debounce this event with the dblclick event. If you try to doubleclick |
| 3128 | // a URL to open it, Chrome will fire click then dblclick, but we won't |
| 3129 | // have expanded the selection text at the first click event. |
| 3130 | clearTimeout(this.timeouts_.openUrl); |
| 3131 | this.timeouts_.openUrl = setTimeout(this.openSelectedUrl_.bind(this), |
| 3132 | 500); |
| 3133 | return; |
| 3134 | } |
| 3135 | |
Mike Frysinger | 847577f | 2017-05-23 23:25:57 -0400 | [diff] [blame] | 3136 | if (e.type == 'mousedown') { |
| 3137 | if ((this.mouseRightClickPaste && e.button == 2 /* right button */) || |
Mike Frysinger | 2edd361 | 2017-05-24 00:54:39 -0400 | [diff] [blame] | 3138 | e.button == this.mousePasteButton) { |
Mike Frysinger | 4628ad2 | 2017-07-20 02:44:20 -0400 | [diff] [blame] | 3139 | if (!this.paste()) |
Mike Frysinger | 05a57f0 | 2017-08-27 17:48:55 -0400 | [diff] [blame] | 3140 | console.warn('Could not paste manually due to web restrictions'); |
Mike Frysinger | 847577f | 2017-05-23 23:25:57 -0400 | [diff] [blame] | 3141 | } |
| 3142 | } |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3143 | |
Mike Frysinger | 2edd361 | 2017-05-24 00:54:39 -0400 | [diff] [blame] | 3144 | if (e.type == 'mouseup' && e.button == 0 && this.copyOnSelect && |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3145 | !this.document_.getSelection().isCollapsed) { |
Robert Ginda | 15ed490 | 2016-07-12 10:43:22 -0700 | [diff] [blame] | 3146 | this.copySelectionToClipboard(this.document_); |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | if ((e.type == 'mousemove' || e.type == 'mouseup') && |
| 3150 | this.scrollBlockerNode_.engaged) { |
| 3151 | // Disengage the scroll-blocker after one of these events. |
| 3152 | this.scrollBlockerNode_.engaged = false; |
| 3153 | this.scrollBlockerNode_.style.top = '-99px'; |
| 3154 | } |
| 3155 | |
Mike Frysinger | 3c9fa07 | 2017-07-13 10:21:13 -0400 | [diff] [blame] | 3156 | // Emulate arrow key presses via scroll wheel events. |
| 3157 | if (this.scrollWheelArrowKeys_ && !e.shiftKey && |
| 3158 | this.keyboard.applicationCursor && !this.isPrimaryScreen()) { |
Mike Frysinger | c3030a8 | 2017-05-29 14:16:11 -0400 | [diff] [blame] | 3159 | if (e.type == 'wheel') { |
| 3160 | var delta = this.scrollPort_.scrollWheelDelta(e); |
| 3161 | var lines = lib.f.smartFloorDivide( |
| 3162 | Math.abs(delta), this.scrollPort_.characterSize.height); |
| 3163 | |
| 3164 | var data = '\x1bO' + (delta < 0 ? 'B' : 'A'); |
| 3165 | this.io.sendString(data.repeat(lines)); |
| 3166 | |
| 3167 | e.preventDefault(); |
| 3168 | } |
| 3169 | } |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3170 | } else /* if (this.reportMouseEvents) */ { |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3171 | if (!this.scrollBlockerNode_.engaged) { |
| 3172 | if (e.type == 'mousedown') { |
| 3173 | // Move the scroll-blocker into place if we want to keep the scrollport |
| 3174 | // from scrolling. |
| 3175 | this.scrollBlockerNode_.engaged = true; |
| 3176 | this.scrollBlockerNode_.style.top = (e.clientY - 5) + 'px'; |
| 3177 | this.scrollBlockerNode_.style.left = (e.clientX - 5) + 'px'; |
| 3178 | } else if (e.type == 'mousemove') { |
| 3179 | // Oh. This means that drag-scroll was disabled AFTER the mouse down, |
| 3180 | // in which case it's too late to engage the scroll-blocker. |
Robert Ginda | 3ae3782 | 2014-05-15 13:05:35 -0700 | [diff] [blame] | 3181 | this.document_.getSelection().collapseToEnd(); |
Robert Ginda | 4e24f8f | 2014-01-08 14:45:06 -0800 | [diff] [blame] | 3182 | e.preventDefault(); |
| 3183 | } |
| 3184 | } |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3185 | |
| 3186 | this.onMouse(e); |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3189 | if (e.type == 'mouseup' && this.document_.getSelection().isCollapsed) { |
| 3190 | // Restore this on mouseup in case it was temporarily defeated with a |
| 3191 | // alt-mousedown. Only do this when the selection is empty so that |
| 3192 | // we don't immediately kill the users selection. |
Robert Ginda | 6aec7eb | 2015-06-16 10:31:30 -0700 | [diff] [blame] | 3193 | this.defeatMouseReports_ = false; |
Robert Ginda | 928cf63 | 2014-03-05 15:07:41 -0800 | [diff] [blame] | 3194 | } |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3195 | }; |
| 3196 | |
| 3197 | /** |
| 3198 | * Clients should override this if they care to know about mouse events. |
| 3199 | * |
| 3200 | * The event parameter will be a normal DOM mouse click event with additional |
| 3201 | * 'terminalRow' and 'terminalColumn' properties. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 3202 | * |
| 3203 | * @param {Event} e The mouse event to handle. |
rginda | d561329 | 2012-06-19 15:40:37 -0700 | [diff] [blame] | 3204 | */ |
| 3205 | hterm.Terminal.prototype.onMouse = function(e) { }; |
| 3206 | |
| 3207 | /** |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 3208 | * React when focus changes. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 3209 | * |
| 3210 | * @param {boolean} focused True if focused, false otherwise. |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 3211 | */ |
Rob Spies | 06533ba | 2014-04-24 11:20:37 -0700 | [diff] [blame] | 3212 | hterm.Terminal.prototype.onFocusChange_ = function(focused) { |
| 3213 | this.cursorNode_.setAttribute('focus', focused); |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 3214 | this.restyleCursor_(); |
Gabriel Holodak | e8a09be | 2017-10-10 01:07:11 -0400 | [diff] [blame] | 3215 | |
| 3216 | if (this.reportFocus) { |
| 3217 | this.io.sendString(focused === true ? '\x1b[I' : '\x1b[O') |
| 3218 | } |
| 3219 | |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 3220 | if (focused === true) |
| 3221 | this.closeBellNotifications_(); |
rginda | 8e92a69 | 2012-05-20 19:37:20 -0700 | [diff] [blame] | 3222 | }; |
| 3223 | |
| 3224 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3225 | * React when the ScrollPort is scrolled. |
| 3226 | */ |
| 3227 | hterm.Terminal.prototype.onScroll_ = function() { |
| 3228 | this.scheduleSyncCursorPosition_(); |
| 3229 | }; |
| 3230 | |
| 3231 | /** |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 3232 | * React when text is pasted into the scrollPort. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 3233 | * |
| 3234 | * @param {Event} e The DOM paste event to handle. |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 3235 | */ |
| 3236 | hterm.Terminal.prototype.onPaste_ = function(e) { |
Robert Ginda | a063b20 | 2014-07-21 11:08:25 -0700 | [diff] [blame] | 3237 | var data = e.text.replace(/\n/mg, '\r'); |
Connor Hegarty | f525ceb | 2014-09-03 13:36:03 -0700 | [diff] [blame] | 3238 | data = this.keyboard.encode(data); |
Robert Ginda | a063b20 | 2014-07-21 11:08:25 -0700 | [diff] [blame] | 3239 | if (this.options_.bracketedPaste) |
| 3240 | data = '\x1b[200~' + data + '\x1b[201~'; |
| 3241 | |
| 3242 | this.io.sendString(data); |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 3243 | }; |
| 3244 | |
| 3245 | /** |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 3246 | * React when the user tries to copy from the scrollPort. |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 3247 | * |
| 3248 | * @param {Event} e The DOM copy event. |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 3249 | */ |
| 3250 | hterm.Terminal.prototype.onCopy_ = function(e) { |
Rob Spies | 0bec09b | 2014-06-06 15:58:09 -0700 | [diff] [blame] | 3251 | if (!this.useDefaultWindowCopy) { |
| 3252 | e.preventDefault(); |
| 3253 | setTimeout(this.copySelectionToClipboard.bind(this), 0); |
| 3254 | } |
rginda | a09e733 | 2012-08-17 12:49:51 -0700 | [diff] [blame] | 3255 | }; |
| 3256 | |
| 3257 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3258 | * React when the ScrollPort is resized. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 3259 | * |
| 3260 | * Note: This function should not directly contain code that alters the internal |
| 3261 | * state of the terminal. That kind of code belongs in realizeWidth or |
| 3262 | * realizeHeight, so that it can be executed synchronously in the case of a |
| 3263 | * programmatic width change. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3264 | */ |
| 3265 | hterm.Terminal.prototype.onResize_ = function() { |
Robert Ginda | 19f6129 | 2014-03-04 14:07:57 -0800 | [diff] [blame] | 3266 | var columnCount = Math.floor(this.scrollPort_.getScreenWidth() / |
Rob Spies | 0be2025 | 2015-07-16 14:36:47 -0700 | [diff] [blame] | 3267 | this.scrollPort_.characterSize.width) || 0; |
Rob Spies | f4e90e8 | 2015-01-28 12:10:13 -0800 | [diff] [blame] | 3268 | var rowCount = lib.f.smartFloorDivide(this.scrollPort_.getScreenHeight(), |
Rob Spies | 0be2025 | 2015-07-16 14:36:47 -0700 | [diff] [blame] | 3269 | this.scrollPort_.characterSize.height) || 0; |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 3270 | |
Robert Ginda | 4e83f3a | 2012-09-04 15:25:25 -0700 | [diff] [blame] | 3271 | if (columnCount <= 0 || rowCount <= 0) { |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 3272 | // We avoid these situations since they happen sometimes when the terminal |
Robert Ginda | 4e83f3a | 2012-09-04 15:25:25 -0700 | [diff] [blame] | 3273 | // gets removed from the document or during the initial load, and we can't |
| 3274 | // deal with that. |
Rob Spies | 0be2025 | 2015-07-16 14:36:47 -0700 | [diff] [blame] | 3275 | // This can also happen if called before the scrollPort calculates the |
| 3276 | // character size, meaning we dived by 0 above and default to 0 values. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 3277 | return; |
| 3278 | } |
| 3279 | |
rginda | a8ba17d | 2012-08-15 14:41:10 -0700 | [diff] [blame] | 3280 | var isNewSize = (columnCount != this.screenSize.width || |
| 3281 | rowCount != this.screenSize.height); |
| 3282 | |
| 3283 | // We do this even if the size didn't change, just to be sure everything is |
| 3284 | // in sync. |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 3285 | this.realizeSize_(columnCount, rowCount); |
rginda | f522ce0 | 2012-04-17 17:49:17 -0700 | [diff] [blame] | 3286 | this.showZoomWarning_(this.scrollPort_.characterSize.zoomFactor != 1); |
rginda | a8ba17d | 2012-08-15 14:41:10 -0700 | [diff] [blame] | 3287 | |
| 3288 | if (isNewSize) |
| 3289 | this.overlaySize(); |
| 3290 | |
Robert Ginda | fb1be6a | 2013-12-11 11:56:22 -0800 | [diff] [blame] | 3291 | this.restyleCursor_(); |
rginda | a8ba17d | 2012-08-15 14:41:10 -0700 | [diff] [blame] | 3292 | this.scheduleSyncCursorPosition_(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3293 | }; |
| 3294 | |
| 3295 | /** |
| 3296 | * Service the cursor blink timeout. |
| 3297 | */ |
| 3298 | hterm.Terminal.prototype.onCursorBlink_ = function() { |
Robert Ginda | ea2183e | 2014-07-17 09:51:51 -0700 | [diff] [blame] | 3299 | if (!this.options_.cursorBlink) { |
| 3300 | delete this.timeouts_.cursorBlink; |
| 3301 | return; |
| 3302 | } |
| 3303 | |
Robert Ginda | 830583c | 2013-08-07 13:20:46 -0700 | [diff] [blame] | 3304 | if (this.cursorNode_.getAttribute('focus') == 'false' || |
| 3305 | this.cursorNode_.style.opacity == '0') { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 3306 | this.cursorNode_.style.opacity = '1'; |
Robert Ginda | ea2183e | 2014-07-17 09:51:51 -0700 | [diff] [blame] | 3307 | this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_, |
| 3308 | this.cursorBlinkCycle_[0]); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3309 | } else { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 3310 | this.cursorNode_.style.opacity = '0'; |
Robert Ginda | ea2183e | 2014-07-17 09:51:51 -0700 | [diff] [blame] | 3311 | this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_, |
| 3312 | this.cursorBlinkCycle_[1]); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 3313 | } |
| 3314 | }; |
David Reveman | 8f55249 | 2012-03-28 12:18:41 -0400 | [diff] [blame] | 3315 | |
| 3316 | /** |
| 3317 | * Set the scrollbar-visible mode bit. |
| 3318 | * |
| 3319 | * If scrollbar-visible is on, the vertical scrollbar will be visible. |
| 3320 | * Otherwise it will not. |
| 3321 | * |
| 3322 | * Defaults to on. |
| 3323 | * |
| 3324 | * @param {boolean} state True to set scrollbar-visible mode, false to unset. |
| 3325 | */ |
| 3326 | hterm.Terminal.prototype.setScrollbarVisible = function(state) { |
| 3327 | this.scrollPort_.setScrollbarVisible(state); |
| 3328 | }; |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 3329 | |
| 3330 | /** |
Rob Spies | 49039e5 | 2014-12-17 13:40:04 -0800 | [diff] [blame] | 3331 | * Set the scroll wheel move multiplier. This will affect how fast the page |
Mike Frysinger | 9975de6 | 2017-04-28 00:01:14 -0400 | [diff] [blame] | 3332 | * scrolls on wheel events. |
Rob Spies | 49039e5 | 2014-12-17 13:40:04 -0800 | [diff] [blame] | 3333 | * |
| 3334 | * Defaults to 1. |
| 3335 | * |
Evan Jones | 2600d4f | 2016-12-06 09:29:36 -0500 | [diff] [blame] | 3336 | * @param {number} multiplier The multiplier to set. |
Rob Spies | 49039e5 | 2014-12-17 13:40:04 -0800 | [diff] [blame] | 3337 | */ |
| 3338 | hterm.Terminal.prototype.setScrollWheelMoveMultipler = function(multiplier) { |
| 3339 | this.scrollPort_.setScrollWheelMoveMultipler(multiplier); |
| 3340 | }; |
| 3341 | |
| 3342 | /** |
Michael Kelly | 485ecd1 | 2014-06-09 11:41:56 -0400 | [diff] [blame] | 3343 | * Close all web notifications created by terminal bells. |
| 3344 | */ |
| 3345 | hterm.Terminal.prototype.closeBellNotifications_ = function() { |
| 3346 | this.bellNotificationList_.forEach(function(n) { |
| 3347 | n.close(); |
| 3348 | }); |
| 3349 | this.bellNotificationList_.length = 0; |
| 3350 | }; |