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