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