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