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 | |
| 5 | /** |
| 6 | * Constructor for the Terminal class. |
| 7 | * |
| 8 | * A Terminal pulls together the hterm.ScrollPort, hterm.Screen and hterm.VT100 |
| 9 | * classes to provide the complete terminal functionality. |
| 10 | * |
| 11 | * There are a number of lower-level Terminal methods that can be called |
| 12 | * directly to manipulate the cursor, text, scroll region, and other terminal |
| 13 | * attributes. However, the primary method is interpret(), which parses VT |
| 14 | * escape sequences and invokes the appropriate Terminal methods. |
| 15 | * |
| 16 | * This class was heavily influenced by Cory Maccarrone's Framebuffer class. |
| 17 | * |
| 18 | * TODO(rginda): Eventually we're going to need to support characters which are |
| 19 | * displayed twice as wide as standard latin characters. This is to support |
| 20 | * CJK (and possibly other character sets). |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 21 | * |
| 22 | * @param {string} opt_profileName Optional preference profile name. If not |
| 23 | * provided, defaults to 'default'. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 24 | */ |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 25 | hterm.Terminal = function(opt_profileName) { |
| 26 | this.profileName_ = null; |
| 27 | this.setProfile(opt_profileName || 'default'); |
| 28 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 29 | // Two screen instances. |
| 30 | this.primaryScreen_ = new hterm.Screen(); |
| 31 | this.alternateScreen_ = new hterm.Screen(); |
| 32 | |
| 33 | // The "current" screen. |
| 34 | this.screen_ = this.primaryScreen_; |
| 35 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 36 | // The local notion of the screen size. ScreenBuffers also have a size which |
| 37 | // indicates their present size. During size changes, the two may disagree. |
| 38 | // Also, the inactive screen's size is not altered until it is made the active |
| 39 | // screen. |
| 40 | this.screenSize = new hterm.Size(0, 0); |
| 41 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 42 | // The scroll port we'll be using to display the visible rows. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 43 | this.scrollPort_ = new hterm.ScrollPort(this); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 44 | this.scrollPort_.subscribe('resize', this.onResize_.bind(this)); |
| 45 | this.scrollPort_.subscribe('scroll', this.onScroll_.bind(this)); |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 46 | this.scrollPort_.subscribe('paste', this.onPaste_.bind(this)); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 47 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 48 | // The div that contains this terminal. |
| 49 | this.div_ = null; |
| 50 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 51 | // The document that contains the scrollPort. Defaulted to the global |
| 52 | // document here so that the terminal is functional even if it hasn't been |
| 53 | // inserted into a document yet, but re-set in decorate(). |
| 54 | this.document_ = window.document; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 55 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 56 | // The rows that have scrolled off screen and are no longer addressable. |
| 57 | this.scrollbackRows_ = []; |
| 58 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 59 | // Saved tab stops. |
| 60 | this.tabStops_ = []; |
| 61 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 62 | // The VT's notion of the top and bottom rows. Used during some VT |
| 63 | // cursor positioning and scrolling commands. |
| 64 | this.vtScrollTop_ = null; |
| 65 | this.vtScrollBottom_ = null; |
| 66 | |
| 67 | // The DIV element for the visible cursor. |
| 68 | this.cursorNode_ = null; |
| 69 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 70 | // These prefs are cached so we don't have to read from local storage with |
| 71 | // each output and keystroke. |
| 72 | this.scrollOnOutput_ = this.prefs_.get('scroll-on-output'); |
| 73 | this.scrollOnKeystroke_ = this.prefs_.get('scroll-on-keystroke'); |
| 74 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 75 | // Terminal bell sound. |
| 76 | this.bellAudio_ = this.document_.createElement('audio'); |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 77 | this.bellAudio_.setAttribute('src', this.prefs_.get('audible-bell-sound')); |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 78 | this.bellAudio_.setAttribute('preload', 'auto'); |
| 79 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 80 | // Cursor position and attributes saved with DECSC. |
| 81 | this.savedOptions_ = {}; |
| 82 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 83 | // The current mode bits for the terminal. |
| 84 | this.options_ = new hterm.Options(); |
| 85 | |
| 86 | // Timeouts we might need to clear. |
| 87 | this.timeouts_ = {}; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 88 | |
| 89 | // The VT escape sequence interpreter. |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 90 | this.vt = new hterm.VT(this); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 91 | |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 92 | // The keyboard hander. |
| 93 | this.keyboard = new hterm.Keyboard(this); |
| 94 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 95 | // General IO interface that can be given to third parties without exposing |
| 96 | // the entire terminal object. |
| 97 | this.io = new hterm.Terminal.IO(this); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 98 | |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 99 | this.realizeSize_(80, 24); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 100 | this.setDefaultTabStops(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 104 | * Default tab with of 8 to match xterm. |
| 105 | */ |
| 106 | hterm.Terminal.prototype.tabWidth = 8; |
| 107 | |
| 108 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 109 | * The assumed width of a scrollbar. |
| 110 | */ |
| 111 | hterm.Terminal.prototype.scrollbarWidthPx = 16; |
| 112 | |
| 113 | /** |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 114 | * Select a preference profile. |
| 115 | * |
| 116 | * This will load the terminal preferences for the given profile name and |
| 117 | * associate subsequent preference changes with the new preference profile. |
| 118 | * |
| 119 | * @param {string} newName The name of the preference profile. Forward slash |
| 120 | * characters will be removed from the name. |
| 121 | */ |
| 122 | hterm.Terminal.prototype.setProfile = function(profileName) { |
| 123 | // If we already have a profile selected, we're going to need to re-sync |
| 124 | // with the new profile. |
| 125 | var needSync = !!this.profileName_; |
| 126 | |
| 127 | this.profileName_ = profileName.replace(/\//g, ''); |
| 128 | |
| 129 | this.prefs_ = new hterm.PreferenceManager( |
| 130 | '/hterm/prefs/profiles/' + this.profileName_); |
| 131 | |
| 132 | var self = this; |
| 133 | this.prefs_.definePreferences |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 134 | ([ |
| 135 | /** |
| 136 | * Set whether the alt key acts as a meta key or as a distinct alt key. |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 137 | */ |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 138 | ['alt-is-meta', false, function(v) { |
| 139 | self.vt.keyboard.altIsMeta = v; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 140 | } |
| 141 | ], |
| 142 | |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 143 | /** |
| 144 | * Set whether the alt key acts as a meta key instead of producing 8-bit |
| 145 | * characters. |
| 146 | */ |
| 147 | ['alt-sends-escape', true, function(v) { |
| 148 | self.vt.keyboard.altSendsEscape = v; |
| 149 | } |
| 150 | ], |
| 151 | |
| 152 | /** |
| 153 | * Terminal bell sound. Empty string for no audible bell. |
| 154 | */ |
| 155 | ['audible-bell-sound', '../audio/bell.ogg', function(v) { |
| 156 | self.bellAudio_.setAttribute('src', v); |
| 157 | } |
| 158 | ], |
| 159 | |
| 160 | /** |
| 161 | * The background color for text with no other color attributes. |
| 162 | */ |
| 163 | ['background-color', 'rgb(16, 16, 16)', function(v) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 164 | self.scrollPort_.setBackgroundColor(v); |
| 165 | } |
| 166 | ], |
| 167 | |
| 168 | /** |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 169 | * The background image. |
| 170 | * |
| 171 | * Defaults to a subtle light-to-transparent-to-dark gradient that is |
| 172 | * mostly transparent. |
| 173 | */ |
| 174 | ['background-image', |
| 175 | ('-webkit-linear-gradient(bottom, ' + |
| 176 | 'rgba(0,0,0,0.01) 0%, ' + |
| 177 | 'rgba(0,0,0,0) 30%, ' + |
| 178 | 'rgba(255,255,255,0) 70%, ' + |
| 179 | 'rgba(255,255,255,0.05) 100%)'), |
| 180 | function(v) { |
| 181 | self.scrollPort_.setBackgroundImage(v); |
| 182 | } |
| 183 | ], |
| 184 | |
| 185 | /** |
| 186 | * If true, the backspace should send BS ('\x08', aka ^H). Otherwise |
| 187 | * the backspace key should send '\x7f'. |
| 188 | */ |
| 189 | ['backspace-sends-backspace', false, function(v) { |
| 190 | self.keyboard.backspaceSendsBackspace = v; |
| 191 | } |
| 192 | ], |
| 193 | |
| 194 | /** |
| 195 | * The color of the visible cursor. |
| 196 | */ |
| 197 | ['cursor-color', 'rgba(255,0,0,0.5)', function(v) { |
| 198 | self.cursorNode_.style.backgroundColor = v; |
| 199 | } |
| 200 | ], |
| 201 | |
| 202 | /** |
| 203 | * True if we should use bold weight font for text with the bold/bright |
| 204 | * attribute. False to use bright colors only. Null to autodetect. |
| 205 | */ |
| 206 | ['enable-bold', null, function(v) { |
| 207 | self.syncBoldSafeState(); |
| 208 | } |
| 209 | ], |
| 210 | |
| 211 | /** |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 212 | * Default font family for the terminal text. |
| 213 | */ |
| 214 | ['font-family', ('"DejaVu Sans Mono", "Everson Mono", ' + |
| 215 | 'FreeMono, "Menlo", "Lucida Console", ' + |
| 216 | 'monospace'), |
| 217 | function(v) { self.syncFontFamily() } |
| 218 | ], |
| 219 | |
| 220 | /** |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 221 | * The default font size in pixels. |
| 222 | */ |
| 223 | ['font-size', 15, function(v) { |
| 224 | self.setFontSize(v); |
| 225 | } |
| 226 | ], |
| 227 | |
| 228 | /** |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 229 | * Anti-aliasing. |
| 230 | */ |
| 231 | ['font-smoothing', 'antialiased', |
| 232 | function(v) { self.syncFontFamily() } |
| 233 | ], |
| 234 | |
| 235 | /** |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 236 | * The foreground color for text with no other color attributes. |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 237 | */ |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 238 | ['foreground-color', 'rgb(240, 240, 240)', function(v) { |
| 239 | self.scrollPort_.setForegroundColor(v); |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 240 | } |
| 241 | ], |
| 242 | |
| 243 | /** |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 244 | * If true, home/end will control the terminal scrollbar and shift home/end |
| 245 | * will send the VT keycodes. If false then home/end sends VT codes and |
| 246 | * shift home/end scrolls. |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 247 | */ |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 248 | ['home-keys-scroll', false, function(v) { |
| 249 | self.keyboard.homeKeysScroll = v; |
| 250 | } |
| 251 | ], |
| 252 | |
| 253 | /** |
| 254 | * Set whether the meta key sends a leading escape or not. |
| 255 | */ |
| 256 | ['meta-sends-escape', true, function(v) { |
| 257 | self.keyboard.metaSendsEscape = v; |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 258 | } |
| 259 | ], |
| 260 | |
| 261 | /** |
| 262 | * If true, scroll to the bottom on any keystroke. |
| 263 | */ |
| 264 | ['scroll-on-keystroke', true, function(v) { |
| 265 | self.scrollOnKeystroke_ = v; |
| 266 | } |
| 267 | ], |
| 268 | |
| 269 | /** |
| 270 | * If true, scroll to the bottom on terminal output. |
| 271 | */ |
| 272 | ['scroll-on-output', false, function(v) { |
| 273 | self.scrollOnOutput_ = v; |
| 274 | } |
| 275 | ], |
| 276 | |
| 277 | /** |
David Reveman | 8f55249 | 2012-03-28 12:18:41 -0400 | [diff] [blame] | 278 | * The vertical scrollbar mode. |
| 279 | */ |
| 280 | ['scrollbar-visible', true, function(v) { |
| 281 | self.setScrollbarVisible(v); |
| 282 | } |
| 283 | ], |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * If true, page up/down will control the terminal scrollbar and shift |
| 287 | * page up/down will send the VT keycodes. If false then page up/down |
| 288 | * sends VT codes and shift page up/down scrolls. |
| 289 | */ |
| 290 | ['page-keys-scroll', false, function(v) { |
| 291 | self.keyboard.pageKeysScroll = v; |
| 292 | } |
| 293 | ], |
| 294 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 295 | ]); |
| 296 | |
| 297 | if (needSync) |
| 298 | this.prefs_.notifyAll(); |
| 299 | }; |
| 300 | |
| 301 | /** |
| 302 | * Return the current terminal background color. |
| 303 | * |
| 304 | * Intended for use by other classes, so we don't have to expose the entire |
| 305 | * prefs_ object. |
| 306 | */ |
| 307 | hterm.Terminal.prototype.getBackgroundColor = function() { |
| 308 | return this.prefs_.get('background-color'); |
| 309 | }; |
| 310 | |
| 311 | /** |
| 312 | * Return the current terminal foreground color. |
| 313 | * |
| 314 | * Intended for use by other classes, so we don't have to expose the entire |
| 315 | * prefs_ object. |
| 316 | */ |
| 317 | hterm.Terminal.prototype.getForegroundColor = function() { |
| 318 | return this.prefs_.get('foreground-color'); |
| 319 | }; |
| 320 | |
| 321 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 322 | * Create a new instance of a terminal command and run it with a given |
| 323 | * argument string. |
| 324 | * |
| 325 | * @param {function} commandClass The constructor for a terminal command. |
| 326 | * @param {string} argString The argument string to pass to the command. |
| 327 | */ |
| 328 | hterm.Terminal.prototype.runCommandClass = function(commandClass, argString) { |
| 329 | var self = this; |
| 330 | this.command = new commandClass( |
| 331 | { argString: argString || '', |
| 332 | io: this.io.push(), |
| 333 | onExit: function(code) { |
| 334 | self.io.pop(); |
| 335 | self.io.println(hterm.msg('COMMAND_COMPLETE', |
| 336 | [self.command.commandName, code])); |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 337 | self.uninstallKeyboard(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 338 | } |
| 339 | }); |
| 340 | |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 341 | this.installKeyboard(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 342 | this.command.run(); |
| 343 | }; |
| 344 | |
| 345 | /** |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 346 | * Returns true if the current screen is the primary screen, false otherwise. |
| 347 | */ |
| 348 | hterm.Terminal.prototype.isPrimaryScreen = function() { |
| 349 | return this.screen_ = this.primaryScreen_; |
| 350 | }; |
| 351 | |
| 352 | /** |
| 353 | * Install the keyboard handler for this terminal. |
| 354 | * |
| 355 | * This will prevent the browser from seeing any keystrokes sent to the |
| 356 | * terminal. |
| 357 | */ |
| 358 | hterm.Terminal.prototype.installKeyboard = function() { |
| 359 | this.keyboard.installKeyboard(this.document_.body.firstChild); |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Uninstall the keyboard handler for this terminal. |
| 364 | */ |
| 365 | hterm.Terminal.prototype.uninstallKeyboard = function() { |
| 366 | this.keyboard.installKeyboard(null); |
| 367 | } |
| 368 | |
| 369 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 370 | * Set the font size for this terminal. |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 371 | * |
| 372 | * Call setFontSize(0) to reset to the default font size. |
| 373 | * |
| 374 | * This function does not modify the font-size preference. |
| 375 | * |
| 376 | * @param {number} px The desired font size, in pixels. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 377 | */ |
| 378 | hterm.Terminal.prototype.setFontSize = function(px) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 379 | if (px === 0) |
| 380 | px = this.prefs_.get('font-size'); |
| 381 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 382 | this.scrollPort_.setFontSize(px); |
| 383 | }; |
| 384 | |
| 385 | /** |
| 386 | * Get the current font size. |
| 387 | */ |
| 388 | hterm.Terminal.prototype.getFontSize = function() { |
| 389 | return this.scrollPort_.getFontSize(); |
| 390 | }; |
| 391 | |
| 392 | /** |
| 393 | * Set the CSS "font-family" for this terminal. |
| 394 | */ |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 395 | hterm.Terminal.prototype.syncFontFamily = function() { |
| 396 | this.scrollPort_.setFontFamily(this.prefs_.get('font-family'), |
| 397 | this.prefs_.get('font-smoothing')); |
| 398 | this.syncBoldSafeState(); |
| 399 | }; |
| 400 | |
| 401 | hterm.Terminal.prototype.syncBoldSafeState = function() { |
| 402 | var enableBold = this.prefs_.get('enable-bold'); |
| 403 | if (enableBold !== null) { |
| 404 | this.screen_.textAttributes.enableBold = enableBold; |
| 405 | return; |
| 406 | } |
| 407 | |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 408 | var normalSize = this.scrollPort_.measureCharacterSize(); |
| 409 | var boldSize = this.scrollPort_.measureCharacterSize('bold'); |
| 410 | |
| 411 | var isBoldSafe = normalSize.equals(boldSize); |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 412 | if (!isBoldSafe) { |
| 413 | console.warn('Bold characters disabled: Size of bold weight differs ' + |
rginda | c9759de | 2012-03-19 13:21:41 -0700 | [diff] [blame] | 414 | 'from normal. Font family is: ' + |
| 415 | this.scrollPort_.getFontFamily()); |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 416 | } |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 417 | |
| 418 | this.screen_.textAttributes.enableBold = isBoldSafe; |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 422 | * Return a copy of the current cursor position. |
| 423 | * |
| 424 | * @return {hterm.RowCol} The RowCol object representing the current position. |
| 425 | */ |
| 426 | hterm.Terminal.prototype.saveCursor = function() { |
| 427 | return this.screen_.cursorPosition.clone(); |
| 428 | }; |
| 429 | |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 430 | hterm.Terminal.prototype.getTextAttributes = function() { |
| 431 | return this.screen_.textAttributes; |
| 432 | }; |
| 433 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 434 | /** |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 435 | * Change the title of this terminal's window. |
| 436 | */ |
| 437 | hterm.Terminal.prototype.setWindowTitle = function(title) { |
rginda | feaf314 | 2012-01-31 15:14:20 -0800 | [diff] [blame] | 438 | window.document.title = title; |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 442 | * Restore a previously saved cursor position. |
| 443 | * |
| 444 | * @param {hterm.RowCol} cursor The position to restore. |
| 445 | */ |
| 446 | hterm.Terminal.prototype.restoreCursor = function(cursor) { |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 447 | var row = hterm.clamp(cursor.row, 0, this.screenSize.height - 1); |
| 448 | var column = hterm.clamp(cursor.column, 0, this.screenSize.width - 1); |
| 449 | this.screen_.setCursorPosition(row, column); |
| 450 | if (cursor.column > column || |
| 451 | cursor.column == column && cursor.overflow) { |
| 452 | this.screen_.cursorPosition.overflow = true; |
| 453 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | /** |
| 457 | * Set the width of the terminal, resizing the UI to match. |
| 458 | */ |
| 459 | hterm.Terminal.prototype.setWidth = function(columnCount) { |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 460 | if (columnCount == null) { |
| 461 | this.div_.style.width = '100%'; |
| 462 | return; |
| 463 | } |
| 464 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 465 | this.div_.style.width = this.scrollPort_.characterSize.width * |
| 466 | columnCount + this.scrollbarWidthPx + 'px'; |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 467 | this.realizeSize_(columnCount, this.screenSize.height); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 468 | this.scheduleSyncCursorPosition_(); |
| 469 | }; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 470 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 471 | /** |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 472 | * Set the height of the terminal, resizing the UI to match. |
| 473 | */ |
| 474 | hterm.Terminal.prototype.setHeight = function(rowCount) { |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 475 | if (rowCount == null) { |
| 476 | this.div_.style.height = '100%'; |
| 477 | return; |
| 478 | } |
| 479 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 480 | this.div_.style.height = |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 481 | this.scrollPort_.characterSize.height * rowCount + 'px'; |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 482 | this.realizeSize_(this.screenSize.width, rowCount); |
| 483 | this.scheduleSyncCursorPosition_(); |
| 484 | }; |
| 485 | |
| 486 | /** |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 487 | * Deal with terminal size changes. |
| 488 | * |
| 489 | */ |
| 490 | hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) { |
| 491 | if (columnCount != this.screenSize.width) |
| 492 | this.realizeWidth_(columnCount); |
| 493 | |
| 494 | if (rowCount != this.screenSize.height) |
| 495 | this.realizeHeight_(rowCount); |
| 496 | |
| 497 | // Send new terminal size to plugin. |
| 498 | this.io.onTerminalResize(columnCount, rowCount); |
| 499 | }; |
| 500 | |
| 501 | /** |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 502 | * Deal with terminal width changes. |
| 503 | * |
| 504 | * This function does what needs to be done when the terminal width changes |
| 505 | * out from under us. It happens here rather than in onResize_() because this |
| 506 | * code may need to run synchronously to handle programmatic changes of |
| 507 | * terminal width. |
| 508 | * |
| 509 | * Relying on the browser to send us an async resize event means we may not be |
| 510 | * in the correct state yet when the next escape sequence hits. |
| 511 | */ |
| 512 | hterm.Terminal.prototype.realizeWidth_ = function(columnCount) { |
| 513 | var deltaColumns = columnCount - this.screen_.getWidth(); |
| 514 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 515 | this.screenSize.width = columnCount; |
| 516 | this.screen_.setColumnCount(columnCount); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 517 | |
| 518 | if (deltaColumns > 0) { |
| 519 | this.setDefaultTabStops(this.screenSize.width - deltaColumns); |
| 520 | } else { |
| 521 | for (var i = this.tabStops_.length - 1; i >= 0; i--) { |
| 522 | if (this.tabStops_[i] <= columnCount) |
| 523 | break; |
| 524 | |
| 525 | this.tabStops_.pop(); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | this.screen_.setColumnCount(this.screenSize.width); |
| 530 | }; |
| 531 | |
| 532 | /** |
| 533 | * Deal with terminal height changes. |
| 534 | * |
| 535 | * This function does what needs to be done when the terminal height changes |
| 536 | * out from under us. It happens here rather than in onResize_() because this |
| 537 | * code may need to run synchronously to handle programmatic changes of |
| 538 | * terminal height. |
| 539 | * |
| 540 | * Relying on the browser to send us an async resize event means we may not be |
| 541 | * in the correct state yet when the next escape sequence hits. |
| 542 | */ |
| 543 | hterm.Terminal.prototype.realizeHeight_ = function(rowCount) { |
| 544 | var deltaRows = rowCount - this.screen_.getHeight(); |
| 545 | |
| 546 | this.screenSize.height = rowCount; |
| 547 | |
| 548 | var cursor = this.saveCursor(); |
| 549 | |
| 550 | if (deltaRows < 0) { |
| 551 | // Screen got smaller. |
| 552 | deltaRows *= -1; |
| 553 | while (deltaRows) { |
| 554 | var lastRow = this.getRowCount() - 1; |
| 555 | if (lastRow - this.scrollbackRows_.length == cursor.row) |
| 556 | break; |
| 557 | |
| 558 | if (this.getRowText(lastRow)) |
| 559 | break; |
| 560 | |
| 561 | this.screen_.popRow(); |
| 562 | deltaRows--; |
| 563 | } |
| 564 | |
| 565 | var ary = this.screen_.shiftRows(deltaRows); |
| 566 | this.scrollbackRows_.push.apply(this.scrollbackRows_, ary); |
| 567 | |
| 568 | // We just removed rows from the top of the screen, we need to update |
| 569 | // the cursor to match. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 570 | cursor.row = Math.max(cursor.row - deltaRows, 0); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 571 | } else if (deltaRows > 0) { |
| 572 | // Screen got larger. |
| 573 | |
| 574 | if (deltaRows <= this.scrollbackRows_.length) { |
| 575 | var scrollbackCount = Math.min(deltaRows, this.scrollbackRows_.length); |
| 576 | var rows = this.scrollbackRows_.splice( |
| 577 | this.scrollbackRows_.length - scrollbackCount, scrollbackCount); |
| 578 | this.screen_.unshiftRows(rows); |
| 579 | deltaRows -= scrollbackCount; |
| 580 | cursor.row += scrollbackCount; |
| 581 | } |
| 582 | |
| 583 | if (deltaRows) |
| 584 | this.appendRows_(deltaRows); |
| 585 | } |
| 586 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 587 | this.setVTScrollRegion(null, null); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 588 | this.restoreCursor(cursor); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 589 | }; |
| 590 | |
| 591 | /** |
| 592 | * Scroll the terminal to the top of the scrollback buffer. |
| 593 | */ |
| 594 | hterm.Terminal.prototype.scrollHome = function() { |
| 595 | this.scrollPort_.scrollRowToTop(0); |
| 596 | }; |
| 597 | |
| 598 | /** |
| 599 | * Scroll the terminal to the end. |
| 600 | */ |
| 601 | hterm.Terminal.prototype.scrollEnd = function() { |
| 602 | this.scrollPort_.scrollRowToBottom(this.getRowCount()); |
| 603 | }; |
| 604 | |
| 605 | /** |
| 606 | * Scroll the terminal one page up (minus one line) relative to the current |
| 607 | * position. |
| 608 | */ |
| 609 | hterm.Terminal.prototype.scrollPageUp = function() { |
| 610 | var i = this.scrollPort_.getTopRowIndex(); |
| 611 | this.scrollPort_.scrollRowToTop(i - this.screenSize.height + 1); |
| 612 | }; |
| 613 | |
| 614 | /** |
| 615 | * Scroll the terminal one page down (minus one line) relative to the current |
| 616 | * position. |
| 617 | */ |
| 618 | hterm.Terminal.prototype.scrollPageDown = function() { |
| 619 | var i = this.scrollPort_.getTopRowIndex(); |
| 620 | this.scrollPort_.scrollRowToTop(i + this.screenSize.height - 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 621 | }; |
| 622 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 623 | /** |
| 624 | * Full terminal reset. |
| 625 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 626 | hterm.Terminal.prototype.reset = function() { |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 627 | this.clearAllTabStops(); |
| 628 | this.setDefaultTabStops(); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 629 | this.setVTScrollRegion(null, null); |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 630 | |
| 631 | this.clearHome(this.primaryScreen_); |
| 632 | this.primaryScreen_.textAttributes.reset(); |
| 633 | |
| 634 | this.clearHome(this.alternateScreen_); |
| 635 | this.alternateScreen_.textAttributes.reset(); |
| 636 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 637 | this.softReset(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 638 | }; |
| 639 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 640 | /** |
| 641 | * Soft terminal reset. |
| 642 | */ |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 643 | hterm.Terminal.prototype.softReset = function() { |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 644 | this.options_ = new hterm.Options(); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 645 | this.setCursorVisible(true); |
| 646 | this.setCursorBlink(false); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 647 | }; |
| 648 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 649 | /** |
| 650 | * Move the cursor forward to the next tab stop, or to the last column |
| 651 | * if no more tab stops are set. |
| 652 | */ |
| 653 | hterm.Terminal.prototype.forwardTabStop = function() { |
| 654 | var column = this.screen_.cursorPosition.column; |
| 655 | |
| 656 | for (var i = 0; i < this.tabStops_.length; i++) { |
| 657 | if (this.tabStops_[i] > column) { |
| 658 | this.setCursorColumn(this.tabStops_[i]); |
| 659 | return; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | this.setCursorColumn(this.screenSize.width - 1); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 664 | }; |
| 665 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 666 | /** |
| 667 | * Move the cursor backward to the previous tab stop, or to the first column |
| 668 | * if no previous tab stops are set. |
| 669 | */ |
| 670 | hterm.Terminal.prototype.backwardTabStop = function() { |
| 671 | var column = this.screen_.cursorPosition.column; |
| 672 | |
| 673 | for (var i = this.tabStops_.length - 1; i >= 0; i--) { |
| 674 | if (this.tabStops_[i] < column) { |
| 675 | this.setCursorColumn(this.tabStops_[i]); |
| 676 | return; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | this.setCursorColumn(1); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 681 | }; |
| 682 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 683 | /** |
| 684 | * Set a tab stop at the given column. |
| 685 | * |
| 686 | * @param {int} column Zero based column. |
| 687 | */ |
| 688 | hterm.Terminal.prototype.setTabStop = function(column) { |
| 689 | for (var i = this.tabStops_.length - 1; i >= 0; i--) { |
| 690 | if (this.tabStops_[i] == column) |
| 691 | return; |
| 692 | |
| 693 | if (this.tabStops_[i] < column) { |
| 694 | this.tabStops_.splice(i + 1, 0, column); |
| 695 | return; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | this.tabStops_.splice(0, 0, column); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 700 | }; |
| 701 | |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 702 | /** |
| 703 | * Clear the tab stop at the current cursor position. |
| 704 | * |
| 705 | * No effect if there is no tab stop at the current cursor position. |
| 706 | */ |
| 707 | hterm.Terminal.prototype.clearTabStopAtCursor = function() { |
| 708 | var column = this.screen_.cursorPosition.column; |
| 709 | |
| 710 | var i = this.tabStops_.indexOf(column); |
| 711 | if (i == -1) |
| 712 | return; |
| 713 | |
| 714 | this.tabStops_.splice(i, 1); |
| 715 | }; |
| 716 | |
| 717 | /** |
| 718 | * Clear all tab stops. |
| 719 | */ |
| 720 | hterm.Terminal.prototype.clearAllTabStops = function() { |
| 721 | this.tabStops_.length = 0; |
| 722 | }; |
| 723 | |
| 724 | /** |
| 725 | * Set up the default tab stops, starting from a given column. |
| 726 | * |
| 727 | * This sets a tabstop every (column % this.tabWidth) column, starting |
| 728 | * from the specified column, or 0 if no column is provided. |
| 729 | * |
| 730 | * This does not clear the existing tab stops first, use clearAllTabStops |
| 731 | * for that. |
| 732 | * |
| 733 | * @param {int} opt_start Optional starting zero based starting column, useful |
| 734 | * for filling out missing tab stops when the terminal is resized. |
| 735 | */ |
| 736 | hterm.Terminal.prototype.setDefaultTabStops = function(opt_start) { |
| 737 | var start = opt_start || 0; |
| 738 | var w = this.tabWidth; |
| 739 | var stopCount = Math.floor((this.screenSize.width - start) / this.tabWidth) |
| 740 | for (var i = 0; i < stopCount; i++) { |
| 741 | this.setTabStop(Math.floor((start + i * w) / w) * w + w); |
| 742 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 743 | }; |
| 744 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 745 | /** |
| 746 | * Save cursor position and attributes. |
| 747 | * |
| 748 | * TODO(rginda): Save attributes once we support them. |
| 749 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 750 | hterm.Terminal.prototype.saveOptions = function() { |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 751 | this.savedOptions_.cursor = this.saveCursor(); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 752 | this.savedOptions_.textAttributes = this.screen_.textAttributes.clone(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 753 | }; |
| 754 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 755 | /** |
| 756 | * Restore cursor position and attributes. |
| 757 | * |
| 758 | * TODO(rginda): Restore attributes once we support them. |
| 759 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 760 | hterm.Terminal.prototype.restoreOptions = function() { |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 761 | if (this.savedOptions_.cursor) |
| 762 | this.restoreCursor(this.savedOptions_.cursor); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 763 | if (this.savedOptions_.textAttributes) |
| 764 | this.screen_.textAttributes = this.savedOptions_.textAttributes; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 765 | }; |
| 766 | |
| 767 | /** |
| 768 | * Interpret a sequence of characters. |
| 769 | * |
| 770 | * Incomplete escape sequences are buffered until the next call. |
| 771 | * |
| 772 | * @param {string} str Sequence of characters to interpret or pass through. |
| 773 | */ |
| 774 | hterm.Terminal.prototype.interpret = function(str) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 775 | this.vt.interpret(str); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 776 | this.scheduleSyncCursorPosition_(); |
| 777 | }; |
| 778 | |
| 779 | /** |
| 780 | * Take over the given DIV for use as the terminal display. |
| 781 | * |
| 782 | * @param {HTMLDivElement} div The div to use as the terminal display. |
| 783 | */ |
| 784 | hterm.Terminal.prototype.decorate = function(div) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 785 | this.div_ = div; |
| 786 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 787 | this.scrollPort_.decorate(div); |
rginda | 30f20f6 | 2012-04-05 16:36:19 -0700 | [diff] [blame] | 788 | this.scrollPort_.setBackgroundImage(this.prefs_.get('background-image')); |
| 789 | |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 790 | this.div_.focus = this.focus.bind(this); |
rginda | f752139 | 2012-02-28 17:20:34 -0800 | [diff] [blame] | 791 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 792 | this.setFontSize(this.prefs_.get('font-size')); |
| 793 | this.syncFontFamily(); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 794 | |
David Reveman | 8f55249 | 2012-03-28 12:18:41 -0400 | [diff] [blame] | 795 | this.setScrollbarVisible(this.prefs_.get('scrollbar-visible')); |
| 796 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 797 | this.document_ = this.scrollPort_.getDocument(); |
| 798 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 799 | this.cursorNode_ = this.document_.createElement('div'); |
| 800 | this.cursorNode_.style.cssText = |
| 801 | ('position: absolute;' + |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 802 | 'top: -99px;' + |
| 803 | 'display: block;' + |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 804 | 'width: ' + this.scrollPort_.characterSize.width + 'px;' + |
| 805 | 'height: ' + this.scrollPort_.characterSize.height + 'px;' + |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 806 | '-webkit-transition: opacity, background-color 100ms linear;' + |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 807 | 'background-color: ' + this.prefs_.get('cursor-color')); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 808 | this.document_.body.appendChild(this.cursorNode_); |
| 809 | |
| 810 | this.setReverseVideo(false); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 811 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 812 | this.scrollPort_.focus(); |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 813 | this.scrollPort_.scheduleRedraw(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 814 | }; |
| 815 | |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 816 | /** |
| 817 | * Return the HTML document that contains the terminal DOM nodes. |
| 818 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 819 | hterm.Terminal.prototype.getDocument = function() { |
| 820 | return this.document_; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 821 | }; |
| 822 | |
| 823 | /** |
rginda | 0918b65 | 2012-04-04 11:26:24 -0700 | [diff] [blame] | 824 | * Focus the terminal. |
| 825 | */ |
| 826 | hterm.Terminal.prototype.focus = function() { |
| 827 | this.scrollPort_.focus(); |
| 828 | }; |
| 829 | |
| 830 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 831 | * Return the HTML Element for a given row index. |
| 832 | * |
| 833 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 834 | * it to fetch rows on demand as they are scrolled into view. |
| 835 | * |
| 836 | * TODO(rginda): Consider saving scrollback rows as (HTML source, text content) |
| 837 | * pairs to conserve memory. |
| 838 | * |
| 839 | * @param {integer} index The zero-based row index, measured relative to the |
| 840 | * start of the scrollback buffer. On-screen rows will always have the |
| 841 | * largest indicies. |
| 842 | * @return {HTMLElement} The 'x-row' element containing for the requested row. |
| 843 | */ |
| 844 | hterm.Terminal.prototype.getRowNode = function(index) { |
| 845 | if (index < this.scrollbackRows_.length) |
| 846 | return this.scrollbackRows_[index]; |
| 847 | |
| 848 | var screenIndex = index - this.scrollbackRows_.length; |
| 849 | return this.screen_.rowsArray[screenIndex]; |
| 850 | }; |
| 851 | |
| 852 | /** |
| 853 | * Return the text content for a given range of rows. |
| 854 | * |
| 855 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 856 | * it to fetch text content on demand when the user attempts to copy their |
| 857 | * selection to the clipboard. |
| 858 | * |
| 859 | * @param {integer} start The zero-based row index to start from, measured |
| 860 | * relative to the start of the scrollback buffer. On-screen rows will |
| 861 | * always have the largest indicies. |
| 862 | * @param {integer} end The zero-based row index to end on, measured |
| 863 | * relative to the start of the scrollback buffer. |
| 864 | * @return {string} A single string containing the text value of the range of |
| 865 | * rows. Lines will be newline delimited, with no trailing newline. |
| 866 | */ |
| 867 | hterm.Terminal.prototype.getRowsText = function(start, end) { |
| 868 | var ary = []; |
| 869 | for (var i = start; i < end; i++) { |
| 870 | var node = this.getRowNode(i); |
| 871 | ary.push(node.textContent); |
| 872 | } |
| 873 | |
| 874 | return ary.join('\n'); |
| 875 | }; |
| 876 | |
| 877 | /** |
| 878 | * Return the text content for a given row. |
| 879 | * |
| 880 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 881 | * it to fetch text content on demand when the user attempts to copy their |
| 882 | * selection to the clipboard. |
| 883 | * |
| 884 | * @param {integer} index The zero-based row index to return, measured |
| 885 | * relative to the start of the scrollback buffer. On-screen rows will |
| 886 | * always have the largest indicies. |
| 887 | * @return {string} A string containing the text value of the selected row. |
| 888 | */ |
| 889 | hterm.Terminal.prototype.getRowText = function(index) { |
| 890 | var node = this.getRowNode(index); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 891 | return node.textContent; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 892 | }; |
| 893 | |
| 894 | /** |
| 895 | * Return the total number of rows in the addressable screen and in the |
| 896 | * scrollback buffer of this terminal. |
| 897 | * |
| 898 | * This is a method from the RowProvider interface. The ScrollPort uses |
| 899 | * it to compute the size of the scrollbar. |
| 900 | * |
| 901 | * @return {integer} The number of rows in this terminal. |
| 902 | */ |
| 903 | hterm.Terminal.prototype.getRowCount = function() { |
| 904 | return this.scrollbackRows_.length + this.screen_.rowsArray.length; |
| 905 | }; |
| 906 | |
| 907 | /** |
| 908 | * Create DOM nodes for new rows and append them to the end of the terminal. |
| 909 | * |
| 910 | * This is the only correct way to add a new DOM node for a row. Notice that |
| 911 | * the new row is appended to the bottom of the list of rows, and does not |
| 912 | * require renumbering (of the rowIndex property) of previous rows. |
| 913 | * |
| 914 | * If you think you want a new blank row somewhere in the middle of the |
| 915 | * terminal, look into moveRows_(). |
| 916 | * |
| 917 | * This method does not pay attention to vtScrollTop/Bottom, since you should |
| 918 | * be using moveRows() in cases where they would matter. |
| 919 | * |
| 920 | * The cursor will be positioned at column 0 of the first inserted line. |
| 921 | */ |
| 922 | hterm.Terminal.prototype.appendRows_ = function(count) { |
| 923 | var cursorRow = this.screen_.rowsArray.length; |
| 924 | var offset = this.scrollbackRows_.length + cursorRow; |
| 925 | for (var i = 0; i < count; i++) { |
| 926 | var row = this.document_.createElement('x-row'); |
| 927 | row.appendChild(this.document_.createTextNode('')); |
| 928 | row.rowIndex = offset + i; |
| 929 | this.screen_.pushRow(row); |
| 930 | } |
| 931 | |
| 932 | var extraRows = this.screen_.rowsArray.length - this.screenSize.height; |
| 933 | if (extraRows > 0) { |
| 934 | var ary = this.screen_.shiftRows(extraRows); |
| 935 | Array.prototype.push.apply(this.scrollbackRows_, ary); |
| 936 | this.scheduleScrollDown_(); |
| 937 | } |
| 938 | |
| 939 | if (cursorRow >= this.screen_.rowsArray.length) |
| 940 | cursorRow = this.screen_.rowsArray.length - 1; |
| 941 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 942 | this.setAbsoluteCursorPosition(cursorRow, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 943 | }; |
| 944 | |
| 945 | /** |
| 946 | * Relocate rows from one part of the addressable screen to another. |
| 947 | * |
| 948 | * This is used to recycle rows during VT scrolls (those which are driven |
| 949 | * by VT commands, rather than by the user manipulating the scrollbar.) |
| 950 | * |
| 951 | * In this case, the blank lines scrolled into the scroll region are made of |
| 952 | * the nodes we scrolled off. These have their rowIndex properties carefully |
| 953 | * renumbered so as not to confuse the ScrollPort. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 954 | */ |
| 955 | hterm.Terminal.prototype.moveRows_ = function(fromIndex, count, toIndex) { |
| 956 | var ary = this.screen_.removeRows(fromIndex, count); |
| 957 | this.screen_.insertRows(toIndex, ary); |
| 958 | |
| 959 | var start, end; |
| 960 | if (fromIndex < toIndex) { |
| 961 | start = fromIndex; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 962 | end = toIndex + count; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 963 | } else { |
| 964 | start = toIndex; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 965 | end = fromIndex + count; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | this.renumberRows_(start, end); |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 969 | this.scrollPort_.scheduleInvalidate(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 970 | }; |
| 971 | |
| 972 | /** |
| 973 | * Renumber the rowIndex property of the given range of rows. |
| 974 | * |
| 975 | * The start and end indicies are relative to the screen, not the scrollback. |
| 976 | * Rows in the scrollback buffer cannot be renumbered. Since they are not |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 977 | * addressable (you can't delete them, scroll them, etc), you should have |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 978 | * no need to renumber scrollback rows. |
| 979 | */ |
| 980 | hterm.Terminal.prototype.renumberRows_ = function(start, end) { |
| 981 | var offset = this.scrollbackRows_.length; |
| 982 | for (var i = start; i < end; i++) { |
| 983 | this.screen_.rowsArray[i].rowIndex = offset + i; |
| 984 | } |
| 985 | }; |
| 986 | |
| 987 | /** |
| 988 | * Print a string to the terminal. |
| 989 | * |
| 990 | * This respects the current insert and wraparound modes. It will add new lines |
| 991 | * to the end of the terminal, scrolling off the top into the scrollback buffer |
| 992 | * if necessary. |
| 993 | * |
| 994 | * The string is *not* parsed for escape codes. Use the interpret() method if |
| 995 | * that's what you're after. |
| 996 | * |
| 997 | * @param{string} str The string to print. |
| 998 | */ |
| 999 | hterm.Terminal.prototype.print = function(str) { |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1000 | if (this.options_.wraparound && this.screen_.cursorPosition.overflow) |
| 1001 | this.newLine(); |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 1002 | |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1003 | if (this.options_.insertMode) { |
| 1004 | this.screen_.insertString(str); |
| 1005 | } else { |
| 1006 | this.screen_.overwriteString(str); |
| 1007 | } |
| 1008 | |
| 1009 | var overflow = this.screen_.maybeClipCurrentRow(); |
| 1010 | |
| 1011 | if (this.options_.wraparound && overflow) { |
| 1012 | var lastColumn; |
| 1013 | |
| 1014 | do { |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1015 | this.newLine(); |
| 1016 | lastColumn = overflow.characterLength; |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1017 | |
| 1018 | if (!this.options_.insertMode) |
| 1019 | this.screen_.deleteChars(overflow.characterLength); |
| 1020 | |
| 1021 | this.screen_.prependNodes(overflow); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1022 | |
| 1023 | overflow = this.screen_.maybeClipCurrentRow(); |
| 1024 | } while (overflow); |
| 1025 | |
| 1026 | this.setCursorColumn(lastColumn); |
| 1027 | } |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1028 | |
| 1029 | this.scheduleSyncCursorPosition_(); |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1030 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1031 | if (this.scrollOnOutput_) |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1032 | this.scrollPort_.scrollRowToBottom(this.getRowCount()); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1033 | }; |
| 1034 | |
| 1035 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1036 | * Set the VT scroll region. |
| 1037 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1038 | * This also resets the cursor position to the absolute (0, 0) position, since |
| 1039 | * that's what xterm appears to do. |
| 1040 | * |
| 1041 | * @param {integer} scrollTop The zero-based top of the scroll region. |
| 1042 | * @param {integer} scrollBottom The zero-based bottom of the scroll region, |
| 1043 | * inclusive. |
| 1044 | */ |
| 1045 | hterm.Terminal.prototype.setVTScrollRegion = function(scrollTop, scrollBottom) { |
| 1046 | this.vtScrollTop_ = scrollTop; |
| 1047 | this.vtScrollBottom_ = scrollBottom; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1048 | }; |
| 1049 | |
| 1050 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1051 | * Return the top row index according to the VT. |
| 1052 | * |
| 1053 | * This will return 0 unless the terminal has been told to restrict scrolling |
| 1054 | * to some lower row. It is used for some VT cursor positioning and scrolling |
| 1055 | * commands. |
| 1056 | * |
| 1057 | * @return {integer} The topmost row in the terminal's scroll region. |
| 1058 | */ |
| 1059 | hterm.Terminal.prototype.getVTScrollTop = function() { |
| 1060 | if (this.vtScrollTop_ != null) |
| 1061 | return this.vtScrollTop_; |
| 1062 | |
| 1063 | return 0; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1064 | }; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1065 | |
| 1066 | /** |
| 1067 | * Return the bottom row index according to the VT. |
| 1068 | * |
| 1069 | * This will return the height of the terminal unless the it has been told to |
| 1070 | * restrict scrolling to some higher row. It is used for some VT cursor |
| 1071 | * positioning and scrolling commands. |
| 1072 | * |
| 1073 | * @return {integer} The bottommost row in the terminal's scroll region. |
| 1074 | */ |
| 1075 | hterm.Terminal.prototype.getVTScrollBottom = function() { |
| 1076 | if (this.vtScrollBottom_ != null) |
| 1077 | return this.vtScrollBottom_; |
| 1078 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1079 | return this.screenSize.height - 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * Process a '\n' character. |
| 1084 | * |
| 1085 | * If the cursor is on the final row of the terminal this will append a new |
| 1086 | * blank row to the screen and scroll the topmost row into the scrollback |
| 1087 | * buffer. |
| 1088 | * |
| 1089 | * Otherwise, this moves the cursor to column zero of the next row. |
| 1090 | */ |
| 1091 | hterm.Terminal.prototype.newLine = function() { |
| 1092 | if (this.screen_.cursorPosition.row == this.screen_.rowsArray.length - 1) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1093 | // If we're at the end of the screen we need to append a new line and |
| 1094 | // scroll the top line into the scrollback buffer. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1095 | this.appendRows_(1); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1096 | } else if (this.screen_.cursorPosition.row == this.getVTScrollBottom()) { |
| 1097 | // End of the scroll region does not affect the scrollback buffer. |
| 1098 | this.vtScrollUp(1); |
| 1099 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1100 | } else { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1101 | // Anywhere else in the screen just moves the cursor. |
| 1102 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row + 1, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1103 | } |
| 1104 | }; |
| 1105 | |
| 1106 | /** |
| 1107 | * Like newLine(), except maintain the cursor column. |
| 1108 | */ |
| 1109 | hterm.Terminal.prototype.lineFeed = function() { |
| 1110 | var column = this.screen_.cursorPosition.column; |
| 1111 | this.newLine(); |
| 1112 | this.setCursorColumn(column); |
| 1113 | }; |
| 1114 | |
| 1115 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1116 | * If autoCarriageReturn is set then newLine(), else lineFeed(). |
| 1117 | */ |
| 1118 | hterm.Terminal.prototype.formFeed = function() { |
| 1119 | if (this.options_.autoCarriageReturn) { |
| 1120 | this.newLine(); |
| 1121 | } else { |
| 1122 | this.lineFeed(); |
| 1123 | } |
| 1124 | }; |
| 1125 | |
| 1126 | /** |
| 1127 | * Move the cursor up one row, possibly inserting a blank line. |
| 1128 | * |
| 1129 | * The cursor column is not changed. |
| 1130 | */ |
| 1131 | hterm.Terminal.prototype.reverseLineFeed = function() { |
| 1132 | var scrollTop = this.getVTScrollTop(); |
| 1133 | var currentRow = this.screen_.cursorPosition.row; |
| 1134 | |
| 1135 | if (currentRow == scrollTop) { |
| 1136 | this.insertLines(1); |
| 1137 | } else { |
| 1138 | this.setAbsoluteCursorRow(currentRow - 1); |
| 1139 | } |
| 1140 | }; |
| 1141 | |
| 1142 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1143 | * Replace all characters to the left of the current cursor with the space |
| 1144 | * character. |
| 1145 | * |
| 1146 | * TODO(rginda): This should probably *remove* the characters (not just replace |
| 1147 | * with a space) if there are no characters at or beyond the current cursor |
| 1148 | * position. Once it does that, it'll have the same text-attribute related |
| 1149 | * issues as hterm.Screen.prototype.clearCursorRow :/ |
| 1150 | */ |
| 1151 | hterm.Terminal.prototype.eraseToLeft = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1152 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1153 | this.setCursorColumn(0); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1154 | this.screen_.overwriteString(hterm.getWhitespace(cursor.column + 1)); |
| 1155 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1156 | }; |
| 1157 | |
| 1158 | /** |
| 1159 | * Erase a given number of characters to the right of the cursor, shifting |
| 1160 | * remaining characters to the left. |
| 1161 | * |
| 1162 | * The cursor position is unchanged. |
| 1163 | * |
| 1164 | * TODO(rginda): Test that this works even when the cursor is positioned beyond |
| 1165 | * the end of the text. |
| 1166 | * |
| 1167 | * TODO(rginda): This likely has text-attribute related troubles similar to the |
| 1168 | * todo on hterm.Screen.prototype.clearCursorRow. |
| 1169 | */ |
| 1170 | hterm.Terminal.prototype.eraseToRight = function(opt_count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1171 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1172 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1173 | var maxCount = this.screenSize.width - cursor.column; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1174 | var count = (opt_count && opt_count < maxCount) ? opt_count : maxCount; |
| 1175 | this.screen_.deleteChars(count); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1176 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1177 | }; |
| 1178 | |
| 1179 | /** |
| 1180 | * Erase the current line. |
| 1181 | * |
| 1182 | * The cursor position is unchanged. |
| 1183 | * |
| 1184 | * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which |
| 1185 | * has a text-attribute related TODO. |
| 1186 | */ |
| 1187 | hterm.Terminal.prototype.eraseLine = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1188 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1189 | this.screen_.clearCursorRow(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1190 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1191 | }; |
| 1192 | |
| 1193 | /** |
| 1194 | * Erase all characters from the start of the scroll region to the current |
| 1195 | * cursor position. |
| 1196 | * |
| 1197 | * The cursor position is unchanged. |
| 1198 | * |
| 1199 | * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which |
| 1200 | * has a text-attribute related TODO. |
| 1201 | */ |
| 1202 | hterm.Terminal.prototype.eraseAbove = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1203 | var cursor = this.saveCursor(); |
| 1204 | |
| 1205 | this.eraseToLeft(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1206 | |
| 1207 | var top = this.getVTScrollTop(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1208 | for (var i = top; i < cursor.row; i++) { |
| 1209 | this.setAbsoluteCursorPosition(i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1210 | this.screen_.clearCursorRow(); |
| 1211 | } |
| 1212 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1213 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1214 | }; |
| 1215 | |
| 1216 | /** |
| 1217 | * Erase all characters from the current cursor position to the end of the |
| 1218 | * scroll region. |
| 1219 | * |
| 1220 | * The cursor position is unchanged. |
| 1221 | * |
| 1222 | * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which |
| 1223 | * has a text-attribute related TODO. |
| 1224 | */ |
| 1225 | hterm.Terminal.prototype.eraseBelow = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1226 | var cursor = this.saveCursor(); |
| 1227 | |
| 1228 | this.eraseToRight(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1229 | |
| 1230 | var bottom = this.getVTScrollBottom(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1231 | for (var i = cursor.row + 1; i <= bottom; i++) { |
| 1232 | this.setAbsoluteCursorPosition(i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1233 | this.screen_.clearCursorRow(); |
| 1234 | } |
| 1235 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1236 | this.restoreCursor(cursor); |
| 1237 | }; |
| 1238 | |
| 1239 | /** |
| 1240 | * Fill the terminal with a given character. |
| 1241 | * |
| 1242 | * This methods does not respect the VT scroll region. |
| 1243 | * |
| 1244 | * @param {string} ch The character to use for the fill. |
| 1245 | */ |
| 1246 | hterm.Terminal.prototype.fill = function(ch) { |
| 1247 | var cursor = this.saveCursor(); |
| 1248 | |
| 1249 | this.setAbsoluteCursorPosition(0, 0); |
| 1250 | for (var row = 0; row < this.screenSize.height; row++) { |
| 1251 | for (var col = 0; col < this.screenSize.width; col++) { |
| 1252 | this.setAbsoluteCursorPosition(row, col); |
| 1253 | this.screen_.overwriteString(ch); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1258 | }; |
| 1259 | |
| 1260 | /** |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1261 | * Erase the entire display and leave the cursor at (0, 0). |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1262 | * |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1263 | * This does not respect the scroll region. |
| 1264 | * |
| 1265 | * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults |
| 1266 | * to the current screen. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1267 | * |
| 1268 | * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which |
| 1269 | * has a text-attribute related TODO. |
| 1270 | */ |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1271 | hterm.Terminal.prototype.clearHome = function(opt_screen) { |
| 1272 | var screen = opt_screen || this.screen_; |
| 1273 | var bottom = screen.getHeight(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1274 | |
rginda | e4d2923 | 2012-01-19 10:47:13 -0800 | [diff] [blame] | 1275 | for (var i = 0; i < bottom; i++) { |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1276 | screen.setCursorPosition(i, 0); |
| 1277 | screen.clearCursorRow(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
rginda | 9ea433c | 2012-03-16 11:57:00 -0700 | [diff] [blame] | 1280 | screen.setCursorPosition(0, 0); |
| 1281 | }; |
| 1282 | |
| 1283 | /** |
| 1284 | * Erase the entire display without changing the cursor position. |
| 1285 | * |
| 1286 | * The cursor position is unchanged. This does not respect the scroll |
| 1287 | * region. |
| 1288 | * |
| 1289 | * @param {hterm.Screen} opt_screen Optional screen to operate on. Defaults |
| 1290 | * to the current screen. |
| 1291 | * |
| 1292 | * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which |
| 1293 | * has a text-attribute related TODO. |
| 1294 | */ |
| 1295 | hterm.Terminal.prototype.clear = function(opt_screen) { |
| 1296 | var screen = opt_screen || this.screen_; |
| 1297 | var cursor = screen.cursorPosition.clone(); |
| 1298 | this.clearHome(screen); |
| 1299 | screen.setCursorPosition(cursor.row, cursor.column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1300 | }; |
| 1301 | |
| 1302 | /** |
| 1303 | * VT command to insert lines at the current cursor row. |
| 1304 | * |
| 1305 | * This respects the current scroll region. Rows pushed off the bottom are |
| 1306 | * lost (they won't show up in the scrollback buffer). |
| 1307 | * |
| 1308 | * TODO(rginda): This relies on hterm.Screen.prototype.clearCursorRow, which |
| 1309 | * has a text-attribute related TODO. |
| 1310 | * |
| 1311 | * @param {integer} count The number of lines to insert. |
| 1312 | */ |
| 1313 | hterm.Terminal.prototype.insertLines = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1314 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1315 | |
| 1316 | var bottom = this.getVTScrollBottom(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1317 | count = Math.min(count, bottom - cursor.row); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1318 | |
rginda | e4d2923 | 2012-01-19 10:47:13 -0800 | [diff] [blame] | 1319 | var start = bottom - count + 1; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1320 | if (start != cursor.row) |
| 1321 | this.moveRows_(start, count, cursor.row); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1322 | |
| 1323 | for (var i = 0; i < count; i++) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1324 | this.setAbsoluteCursorPosition(cursor.row + i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1325 | this.screen_.clearCursorRow(); |
| 1326 | } |
| 1327 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1328 | cursor.column = 0; |
| 1329 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1330 | }; |
| 1331 | |
| 1332 | /** |
| 1333 | * VT command to delete lines at the current cursor row. |
| 1334 | * |
| 1335 | * New rows are added to the bottom of scroll region to take their place. New |
| 1336 | * rows are strictly there to take up space and have no content or style. |
| 1337 | */ |
| 1338 | hterm.Terminal.prototype.deleteLines = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1339 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1340 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1341 | var top = cursor.row; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1342 | var bottom = this.getVTScrollBottom(); |
| 1343 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1344 | var maxCount = bottom - top + 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1345 | count = Math.min(count, maxCount); |
| 1346 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1347 | var moveStart = bottom - count + 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1348 | if (count != maxCount) |
| 1349 | this.moveRows_(top, count, moveStart); |
| 1350 | |
| 1351 | for (var i = 0; i < count; i++) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1352 | this.setAbsoluteCursorPosition(moveStart + i, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1353 | this.screen_.clearCursorRow(); |
| 1354 | } |
| 1355 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1356 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1357 | }; |
| 1358 | |
| 1359 | /** |
| 1360 | * Inserts the given number of spaces at the current cursor position. |
| 1361 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1362 | * The cursor position is not changed. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1363 | */ |
| 1364 | hterm.Terminal.prototype.insertSpace = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1365 | var cursor = this.saveCursor(); |
| 1366 | |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1367 | var ws = hterm.getWhitespace(count || 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1368 | this.screen_.insertString(ws); |
rginda | a19afe2 | 2012-01-25 15:40:22 -0800 | [diff] [blame] | 1369 | this.screen_.maybeClipCurrentRow(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1370 | |
| 1371 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1372 | }; |
| 1373 | |
| 1374 | /** |
| 1375 | * Forward-delete the specified number of characters starting at the cursor |
| 1376 | * position. |
| 1377 | * |
| 1378 | * @param {integer} count The number of characters to delete. |
| 1379 | */ |
| 1380 | hterm.Terminal.prototype.deleteChars = function(count) { |
| 1381 | this.screen_.deleteChars(count); |
| 1382 | }; |
| 1383 | |
| 1384 | /** |
| 1385 | * Shift rows in the scroll region upwards by a given number of lines. |
| 1386 | * |
| 1387 | * New rows are inserted at the bottom of the scroll region to fill the |
| 1388 | * vacated rows. The new rows not filled out with the current text attributes. |
| 1389 | * |
| 1390 | * This function does not affect the scrollback rows at all. Rows shifted |
| 1391 | * off the top are lost. |
| 1392 | * |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1393 | * The cursor position is not altered. |
| 1394 | * |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1395 | * @param {integer} count The number of rows to scroll. |
| 1396 | */ |
| 1397 | hterm.Terminal.prototype.vtScrollUp = function(count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1398 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1399 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1400 | this.setAbsoluteCursorRow(this.getVTScrollTop()); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1401 | this.deleteLines(count); |
| 1402 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1403 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1404 | }; |
| 1405 | |
| 1406 | /** |
| 1407 | * Shift rows below the cursor down by a given number of lines. |
| 1408 | * |
| 1409 | * This function respects the current scroll region. |
| 1410 | * |
| 1411 | * New rows are inserted at the top of the scroll region to fill the |
| 1412 | * vacated rows. The new rows not filled out with the current text attributes. |
| 1413 | * |
| 1414 | * This function does not affect the scrollback rows at all. Rows shifted |
| 1415 | * off the bottom are lost. |
| 1416 | * |
| 1417 | * @param {integer} count The number of rows to scroll. |
| 1418 | */ |
| 1419 | hterm.Terminal.prototype.vtScrollDown = function(opt_count) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1420 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1421 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1422 | this.setAbsoluteCursorPosition(this.getVTScrollTop(), 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1423 | this.insertLines(opt_count); |
| 1424 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1425 | this.restoreCursor(cursor); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1426 | }; |
| 1427 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1428 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1429 | /** |
| 1430 | * Set the cursor position. |
| 1431 | * |
| 1432 | * The cursor row is relative to the scroll region if the terminal has |
| 1433 | * 'origin mode' enabled, or relative to the addressable screen otherwise. |
| 1434 | * |
| 1435 | * @param {integer} row The new zero-based cursor row. |
| 1436 | * @param {integer} row The new zero-based cursor column. |
| 1437 | */ |
| 1438 | hterm.Terminal.prototype.setCursorPosition = function(row, column) { |
| 1439 | if (this.options_.originMode) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1440 | this.setRelativeCursorPosition(row, column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1441 | } else { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1442 | this.setAbsoluteCursorPosition(row, column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1443 | } |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1444 | }; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1445 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1446 | hterm.Terminal.prototype.setRelativeCursorPosition = function(row, column) { |
| 1447 | var scrollTop = this.getVTScrollTop(); |
| 1448 | row = hterm.clamp(row + scrollTop, scrollTop, this.getVTScrollBottom()); |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 1449 | column = hterm.clamp(column, 0, this.screenSize.width - 1); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1450 | this.screen_.setCursorPosition(row, column); |
| 1451 | }; |
| 1452 | |
| 1453 | hterm.Terminal.prototype.setAbsoluteCursorPosition = function(row, column) { |
rginda | 2312fff | 2012-01-05 16:20:52 -0800 | [diff] [blame] | 1454 | row = hterm.clamp(row, 0, this.screenSize.height - 1); |
| 1455 | column = hterm.clamp(column, 0, this.screenSize.width - 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1456 | this.screen_.setCursorPosition(row, column); |
| 1457 | }; |
| 1458 | |
| 1459 | /** |
| 1460 | * Set the cursor column. |
| 1461 | * |
| 1462 | * @param {integer} column The new zero-based cursor column. |
| 1463 | */ |
| 1464 | hterm.Terminal.prototype.setCursorColumn = function(column) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1465 | this.setAbsoluteCursorPosition(this.screen_.cursorPosition.row, column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1466 | }; |
| 1467 | |
| 1468 | /** |
| 1469 | * Return the cursor column. |
| 1470 | * |
| 1471 | * @return {integer} The zero-based cursor column. |
| 1472 | */ |
| 1473 | hterm.Terminal.prototype.getCursorColumn = function() { |
| 1474 | return this.screen_.cursorPosition.column; |
| 1475 | }; |
| 1476 | |
| 1477 | /** |
| 1478 | * Set the cursor row. |
| 1479 | * |
| 1480 | * The cursor row is relative to the scroll region if the terminal has |
| 1481 | * 'origin mode' enabled, or relative to the addressable screen otherwise. |
| 1482 | * |
| 1483 | * @param {integer} row The new cursor row. |
| 1484 | */ |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1485 | hterm.Terminal.prototype.setAbsoluteCursorRow = function(row) { |
| 1486 | this.setAbsoluteCursorPosition(row, this.screen_.cursorPosition.column); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1487 | }; |
| 1488 | |
| 1489 | /** |
| 1490 | * Return the cursor row. |
| 1491 | * |
| 1492 | * @return {integer} The zero-based cursor row. |
| 1493 | */ |
| 1494 | hterm.Terminal.prototype.getCursorRow = function(row) { |
| 1495 | return this.screen_.cursorPosition.row; |
| 1496 | }; |
| 1497 | |
| 1498 | /** |
| 1499 | * Request that the ScrollPort redraw itself soon. |
| 1500 | * |
| 1501 | * The redraw will happen asynchronously, soon after the call stack winds down. |
| 1502 | * Multiple calls will be coalesced into a single redraw. |
| 1503 | */ |
| 1504 | hterm.Terminal.prototype.scheduleRedraw_ = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1505 | if (this.timeouts_.redraw) |
| 1506 | return; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1507 | |
| 1508 | var self = this; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1509 | this.timeouts_.redraw = setTimeout(function() { |
| 1510 | delete self.timeouts_.redraw; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1511 | self.scrollPort_.redraw_(); |
| 1512 | }, 0); |
| 1513 | }; |
| 1514 | |
| 1515 | /** |
| 1516 | * Request that the ScrollPort be scrolled to the bottom. |
| 1517 | * |
| 1518 | * The scroll will happen asynchronously, soon after the call stack winds down. |
| 1519 | * Multiple calls will be coalesced into a single scroll. |
| 1520 | * |
| 1521 | * This affects the scrollbar position of the ScrollPort, and has nothing to |
| 1522 | * do with the VT scroll commands. |
| 1523 | */ |
| 1524 | hterm.Terminal.prototype.scheduleScrollDown_ = function() { |
| 1525 | if (this.timeouts_.scrollDown) |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1526 | return; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1527 | |
| 1528 | var self = this; |
| 1529 | this.timeouts_.scrollDown = setTimeout(function() { |
| 1530 | delete self.timeouts_.scrollDown; |
| 1531 | self.scrollPort_.scrollRowToBottom(self.getRowCount()); |
| 1532 | }, 10); |
| 1533 | }; |
| 1534 | |
| 1535 | /** |
| 1536 | * Move the cursor up a specified number of rows. |
| 1537 | * |
| 1538 | * @param {integer} count The number of rows to move the cursor. |
| 1539 | */ |
| 1540 | hterm.Terminal.prototype.cursorUp = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1541 | return this.cursorDown(-(count || 1)); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1542 | }; |
| 1543 | |
| 1544 | /** |
| 1545 | * Move the cursor down a specified number of rows. |
| 1546 | * |
| 1547 | * @param {integer} count The number of rows to move the cursor. |
| 1548 | */ |
| 1549 | hterm.Terminal.prototype.cursorDown = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1550 | count = count || 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1551 | var minHeight = (this.options_.originMode ? this.getVTScrollTop() : 0); |
| 1552 | var maxHeight = (this.options_.originMode ? this.getVTScrollBottom() : |
| 1553 | this.screenSize.height - 1); |
| 1554 | |
| 1555 | var row = hterm.clamp(this.screen_.cursorPosition.row + count, |
| 1556 | minHeight, maxHeight); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1557 | this.setAbsoluteCursorRow(row); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1558 | }; |
| 1559 | |
| 1560 | /** |
| 1561 | * Move the cursor left a specified number of columns. |
| 1562 | * |
| 1563 | * @param {integer} count The number of columns to move the cursor. |
| 1564 | */ |
| 1565 | hterm.Terminal.prototype.cursorLeft = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1566 | return this.cursorRight(-(count || 1)); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1567 | }; |
| 1568 | |
| 1569 | /** |
| 1570 | * Move the cursor right a specified number of columns. |
| 1571 | * |
| 1572 | * @param {integer} count The number of columns to move the cursor. |
| 1573 | */ |
| 1574 | hterm.Terminal.prototype.cursorRight = function(count) { |
rginda | 0f5c029 | 2012-01-13 11:00:13 -0800 | [diff] [blame] | 1575 | count = count || 1; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1576 | var column = hterm.clamp(this.screen_.cursorPosition.column + count, |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1577 | 0, this.screenSize.width - 1); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1578 | this.setCursorColumn(column); |
| 1579 | }; |
| 1580 | |
| 1581 | /** |
| 1582 | * Reverse the foreground and background colors of the terminal. |
| 1583 | * |
| 1584 | * This only affects text that was drawn with no attributes. |
| 1585 | * |
| 1586 | * TODO(rginda): Test xterm to see if reverse is respected for text that has |
| 1587 | * been drawn with attributes that happen to coincide with the default |
| 1588 | * 'no-attribute' colors. My guess is probably not. |
| 1589 | */ |
| 1590 | hterm.Terminal.prototype.setReverseVideo = function(state) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1591 | this.options_.reverseVideo = state; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1592 | if (state) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1593 | this.scrollPort_.setForegroundColor(this.prefs_.get('background-color')); |
| 1594 | this.scrollPort_.setBackgroundColor(this.prefs_.get('foreground-color')); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1595 | } else { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1596 | this.scrollPort_.setForegroundColor(this.prefs_.get('foreground-color')); |
| 1597 | this.scrollPort_.setBackgroundColor(this.prefs_.get('background-color')); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1598 | } |
| 1599 | }; |
| 1600 | |
| 1601 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1602 | * Ring the terminal bell. |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1603 | */ |
| 1604 | hterm.Terminal.prototype.ringBell = function() { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1605 | if (this.bellAudio_.getAttribute('src')) |
| 1606 | this.bellAudio_.play(); |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1607 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 1608 | this.cursorNode_.style.backgroundColor = |
| 1609 | this.scrollPort_.getForegroundColor(); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1610 | |
| 1611 | var self = this; |
| 1612 | setTimeout(function() { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1613 | self.cursorNode_.style.backgroundColor = self.prefs_.get('cursor-color'); |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 1614 | }, 200); |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1615 | }; |
| 1616 | |
| 1617 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1618 | * Set the origin mode bit. |
| 1619 | * |
| 1620 | * If origin mode is on, certain VT cursor and scrolling commands measure their |
| 1621 | * row parameter relative to the VT scroll region. Otherwise, row 0 corresponds |
| 1622 | * to the top of the addressable screen. |
| 1623 | * |
| 1624 | * Defaults to off. |
| 1625 | * |
| 1626 | * @param {boolean} state True to set origin mode, false to unset. |
| 1627 | */ |
| 1628 | hterm.Terminal.prototype.setOriginMode = function(state) { |
| 1629 | this.options_.originMode = state; |
rginda | e4d2923 | 2012-01-19 10:47:13 -0800 | [diff] [blame] | 1630 | this.setCursorPosition(0, 0); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1631 | }; |
| 1632 | |
| 1633 | /** |
| 1634 | * Set the insert mode bit. |
| 1635 | * |
| 1636 | * If insert mode is on, existing text beyond the cursor position will be |
| 1637 | * shifted right to make room for new text. Otherwise, new text overwrites |
| 1638 | * any existing text. |
| 1639 | * |
| 1640 | * Defaults to off. |
| 1641 | * |
| 1642 | * @param {boolean} state True to set insert mode, false to unset. |
| 1643 | */ |
| 1644 | hterm.Terminal.prototype.setInsertMode = function(state) { |
| 1645 | this.options_.insertMode = state; |
| 1646 | }; |
| 1647 | |
| 1648 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1649 | * Set the auto carriage return bit. |
| 1650 | * |
| 1651 | * If auto carriage return is on then a formfeed character is interpreted |
| 1652 | * as a newline, otherwise it's the same as a linefeed. The difference boils |
| 1653 | * down to whether or not the cursor column is reset. |
| 1654 | */ |
| 1655 | hterm.Terminal.prototype.setAutoCarriageReturn = function(state) { |
| 1656 | this.options_.autoCarriageReturn = state; |
| 1657 | }; |
| 1658 | |
| 1659 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1660 | * Set the wraparound mode bit. |
| 1661 | * |
| 1662 | * If wraparound mode is on, certain VT commands will allow the cursor to wrap |
| 1663 | * to the start of the following row. Otherwise, the cursor is clamped to the |
| 1664 | * end of the screen and attempts to write past it are ignored. |
| 1665 | * |
| 1666 | * Defaults to on. |
| 1667 | * |
| 1668 | * @param {boolean} state True to set wraparound mode, false to unset. |
| 1669 | */ |
| 1670 | hterm.Terminal.prototype.setWraparound = function(state) { |
| 1671 | this.options_.wraparound = state; |
| 1672 | }; |
| 1673 | |
| 1674 | /** |
| 1675 | * Set the reverse-wraparound mode bit. |
| 1676 | * |
| 1677 | * If wraparound mode is off, certain VT commands will allow the cursor to wrap |
| 1678 | * to the end of the previous row. Otherwise, the cursor is clamped to column |
| 1679 | * 0. |
| 1680 | * |
| 1681 | * Defaults to off. |
| 1682 | * |
| 1683 | * @param {boolean} state True to set reverse-wraparound mode, false to unset. |
| 1684 | */ |
| 1685 | hterm.Terminal.prototype.setReverseWraparound = function(state) { |
| 1686 | this.options_.reverseWraparound = state; |
| 1687 | }; |
| 1688 | |
| 1689 | /** |
| 1690 | * Selects between the primary and alternate screens. |
| 1691 | * |
| 1692 | * If alternate mode is on, the alternate screen is active. Otherwise the |
| 1693 | * primary screen is active. |
| 1694 | * |
| 1695 | * Swapping screens has no effect on the scrollback buffer. |
| 1696 | * |
| 1697 | * Each screen maintains its own cursor position. |
| 1698 | * |
| 1699 | * Defaults to off. |
| 1700 | * |
| 1701 | * @param {boolean} state True to set alternate mode, false to unset. |
| 1702 | */ |
| 1703 | hterm.Terminal.prototype.setAlternateMode = function(state) { |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 1704 | var cursor = this.saveCursor(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1705 | this.screen_ = state ? this.alternateScreen_ : this.primaryScreen_; |
| 1706 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1707 | if (this.screen_.rowsArray.length && |
| 1708 | this.screen_.rowsArray[0].rowIndex != this.scrollbackRows_.length) { |
| 1709 | // If the screen changed sizes while we were away, our rowIndexes may |
| 1710 | // be incorrect. |
| 1711 | var offset = this.scrollbackRows_.length; |
| 1712 | var ary = this.screen_.rowsArray; |
| 1713 | for (i = 0; i < ary.length; i++) { |
| 1714 | ary[i].rowIndex = offset + i; |
| 1715 | } |
| 1716 | } |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1717 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1718 | this.realizeWidth_(this.screenSize.width); |
| 1719 | this.realizeHeight_(this.screenSize.height); |
| 1720 | this.scrollPort_.syncScrollHeight(); |
| 1721 | this.scrollPort_.invalidate(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1722 | |
rginda | 6d39740 | 2012-01-17 10:58:29 -0800 | [diff] [blame] | 1723 | this.restoreCursor(cursor); |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1724 | this.scrollPort_.resize(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1725 | }; |
| 1726 | |
| 1727 | /** |
| 1728 | * Set the cursor-blink mode bit. |
| 1729 | * |
| 1730 | * If cursor-blink is on, the cursor will blink when it is visible. Otherwise |
| 1731 | * a visible cursor does not blink. |
| 1732 | * |
| 1733 | * You should make sure to turn blinking off if you're going to dispose of a |
| 1734 | * terminal, otherwise you'll leak a timeout. |
| 1735 | * |
| 1736 | * Defaults to on. |
| 1737 | * |
| 1738 | * @param {boolean} state True to set cursor-blink mode, false to unset. |
| 1739 | */ |
| 1740 | hterm.Terminal.prototype.setCursorBlink = function(state) { |
| 1741 | this.options_.cursorBlink = state; |
| 1742 | |
| 1743 | if (!state && this.timeouts_.cursorBlink) { |
| 1744 | clearTimeout(this.timeouts_.cursorBlink); |
| 1745 | delete this.timeouts_.cursorBlink; |
| 1746 | } |
| 1747 | |
| 1748 | if (this.options_.cursorVisible) |
| 1749 | this.setCursorVisible(true); |
| 1750 | }; |
| 1751 | |
| 1752 | /** |
| 1753 | * Set the cursor-visible mode bit. |
| 1754 | * |
| 1755 | * If cursor-visible is on, the cursor will be visible. Otherwise it will not. |
| 1756 | * |
| 1757 | * Defaults to on. |
| 1758 | * |
| 1759 | * @param {boolean} state True to set cursor-visible mode, false to unset. |
| 1760 | */ |
| 1761 | hterm.Terminal.prototype.setCursorVisible = function(state) { |
| 1762 | this.options_.cursorVisible = state; |
| 1763 | |
| 1764 | if (!state) { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1765 | this.cursorNode_.style.opacity = '0'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1766 | return; |
| 1767 | } |
| 1768 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1769 | this.syncCursorPosition_(); |
| 1770 | |
| 1771 | this.cursorNode_.style.opacity = '1'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1772 | |
| 1773 | if (this.options_.cursorBlink) { |
| 1774 | if (this.timeouts_.cursorBlink) |
| 1775 | return; |
| 1776 | |
| 1777 | this.timeouts_.cursorBlink = setInterval(this.onCursorBlink_.bind(this), |
| 1778 | 500); |
| 1779 | } else { |
| 1780 | if (this.timeouts_.cursorBlink) { |
| 1781 | clearTimeout(this.timeouts_.cursorBlink); |
| 1782 | delete this.timeouts_.cursorBlink; |
| 1783 | } |
| 1784 | } |
| 1785 | }; |
| 1786 | |
| 1787 | /** |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1788 | * Synchronizes the visible cursor and document selection with the current |
| 1789 | * cursor coordinates. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1790 | */ |
| 1791 | hterm.Terminal.prototype.syncCursorPosition_ = function() { |
| 1792 | var topRowIndex = this.scrollPort_.getTopRowIndex(); |
| 1793 | var bottomRowIndex = this.scrollPort_.getBottomRowIndex(topRowIndex); |
| 1794 | var cursorRowIndex = this.scrollbackRows_.length + |
| 1795 | this.screen_.cursorPosition.row; |
| 1796 | |
| 1797 | if (cursorRowIndex > bottomRowIndex) { |
| 1798 | // Cursor is scrolled off screen, move it outside of the visible area. |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1799 | this.cursorNode_.style.top = -this.scrollPort_.characterSize.height + 'px'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1800 | return; |
| 1801 | } |
| 1802 | |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1803 | this.cursorNode_.style.width = this.scrollPort_.characterSize.width + 'px'; |
| 1804 | this.cursorNode_.style.height = this.scrollPort_.characterSize.height + 'px'; |
| 1805 | |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1806 | this.cursorNode_.style.top = this.scrollPort_.visibleRowTopMargin + |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1807 | this.scrollPort_.characterSize.height * (cursorRowIndex - topRowIndex) + |
| 1808 | 'px'; |
| 1809 | this.cursorNode_.style.left = this.scrollPort_.characterSize.width * |
| 1810 | this.screen_.cursorPosition.column + 'px'; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1811 | |
| 1812 | this.cursorNode_.setAttribute('title', |
| 1813 | '(' + this.screen_.cursorPosition.row + |
| 1814 | ', ' + this.screen_.cursorPosition.column + |
| 1815 | ')'); |
| 1816 | |
| 1817 | // Update the caret for a11y purposes. |
| 1818 | var selection = this.document_.getSelection(); |
| 1819 | if (selection && selection.isCollapsed) |
| 1820 | this.screen_.syncSelectionCaret(selection); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1821 | }; |
| 1822 | |
| 1823 | /** |
| 1824 | * Synchronizes the visible cursor with the current cursor coordinates. |
| 1825 | * |
| 1826 | * The sync will happen asynchronously, soon after the call stack winds down. |
| 1827 | * Multiple calls will be coalesced into a single sync. |
| 1828 | */ |
| 1829 | hterm.Terminal.prototype.scheduleSyncCursorPosition_ = function() { |
| 1830 | if (this.timeouts_.syncCursor) |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1831 | return; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1832 | |
| 1833 | var self = this; |
| 1834 | this.timeouts_.syncCursor = setTimeout(function() { |
| 1835 | self.syncCursorPosition_(); |
| 1836 | delete self.timeouts_.syncCursor; |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1837 | }, 0); |
| 1838 | }; |
| 1839 | |
rginda | cc2996c | 2012-02-24 14:59:31 -0800 | [diff] [blame] | 1840 | /** |
| 1841 | * Show the terminal overlay for a given amount of time. |
| 1842 | * |
| 1843 | * The terminal overlay appears in inverse video in a large font, centered |
| 1844 | * over the terminal. You should probably keep the overlay message brief, |
| 1845 | * since it's in a large font and you probably aren't going to check the size |
| 1846 | * of the terminal first. |
| 1847 | * |
| 1848 | * @param {string} msg The text (not HTML) message to display in the overlay. |
| 1849 | * @param {number} opt_timeout The amount of time to wait before fading out |
| 1850 | * the overlay. Defaults to 1.5 seconds. Pass null to have the overlay |
| 1851 | * stay up forever (or until the next overlay). |
| 1852 | */ |
| 1853 | hterm.Terminal.prototype.showOverlay = function(msg, opt_timeout) { |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1854 | if (!this.overlayNode_) { |
| 1855 | if (!this.div_) |
| 1856 | return; |
| 1857 | |
| 1858 | this.overlayNode_ = this.document_.createElement('div'); |
| 1859 | this.overlayNode_.style.cssText = ( |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1860 | 'border-radius: 15px;' + |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1861 | 'font-size: xx-large;' + |
| 1862 | 'opacity: 0.75;' + |
| 1863 | 'padding: 0.2em 0.5em 0.2em 0.5em;' + |
| 1864 | 'position: absolute;' + |
| 1865 | '-webkit-user-select: none;' + |
| 1866 | '-webkit-transition: opacity 180ms ease-in;'); |
| 1867 | } |
| 1868 | |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1869 | this.overlayNode_.style.color = this.prefs_.get('background-color'); |
| 1870 | this.overlayNode_.style.backgroundColor = this.prefs_.get('foreground-color'); |
| 1871 | this.overlayNode_.style.fontFamily = this.prefs_.get('font-family'); |
| 1872 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1873 | this.overlayNode_.textContent = msg; |
| 1874 | this.overlayNode_.style.opacity = '0.75'; |
| 1875 | |
| 1876 | if (!this.overlayNode_.parentNode) |
| 1877 | this.div_.appendChild(this.overlayNode_); |
| 1878 | |
| 1879 | this.overlayNode_.style.top = ( |
| 1880 | this.div_.clientHeight - this.overlayNode_.clientHeight) / 2; |
| 1881 | this.overlayNode_.style.left = ( |
| 1882 | this.div_.clientWidth - this.overlayNode_.clientWidth - |
| 1883 | this.scrollbarWidthPx) / 2; |
| 1884 | |
| 1885 | var self = this; |
| 1886 | |
| 1887 | if (this.overlayTimeout_) |
| 1888 | clearTimeout(this.overlayTimeout_); |
| 1889 | |
rginda | cc2996c | 2012-02-24 14:59:31 -0800 | [diff] [blame] | 1890 | if (opt_timeout === null) |
| 1891 | return; |
| 1892 | |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1893 | this.overlayTimeout_ = setTimeout(function() { |
| 1894 | self.overlayNode_.style.opacity = '0'; |
| 1895 | setTimeout(function() { |
rginda | 259dcca | 2012-03-14 16:37:11 -0700 | [diff] [blame] | 1896 | if (self.overlayNode_.parentNode) |
| 1897 | self.overlayNode_.parentNode.removeChild(self.overlayNode_); |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1898 | self.overlayTimeout_ = null; |
| 1899 | self.overlayNode_.style.opacity = '0.75'; |
| 1900 | }, 200); |
rginda | cc2996c | 2012-02-24 14:59:31 -0800 | [diff] [blame] | 1901 | }, opt_timeout || 1500); |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1902 | }; |
| 1903 | |
| 1904 | hterm.Terminal.prototype.overlaySize = function() { |
| 1905 | this.showOverlay(this.screenSize.width + 'x' + this.screenSize.height); |
| 1906 | }; |
| 1907 | |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1908 | /** |
| 1909 | * Invoked by hterm.Terminal.Keyboard when a VT keystroke is detected. |
| 1910 | * |
| 1911 | * @param {string} string The VT string representing the keystroke. |
| 1912 | */ |
| 1913 | hterm.Terminal.prototype.onVTKeystroke = function(string) { |
rginda | 9f5222b | 2012-03-05 11:53:28 -0800 | [diff] [blame] | 1914 | if (this.scrollOnKeystroke_) |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1915 | this.scrollPort_.scrollRowToBottom(this.getRowCount()); |
| 1916 | |
| 1917 | this.io.onVTKeystroke(string); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1918 | }; |
| 1919 | |
| 1920 | /** |
| 1921 | * React when the ScrollPort is scrolled. |
| 1922 | */ |
| 1923 | hterm.Terminal.prototype.onScroll_ = function() { |
| 1924 | this.scheduleSyncCursorPosition_(); |
| 1925 | }; |
| 1926 | |
| 1927 | /** |
rginda | 9846e2f | 2012-01-27 13:53:33 -0800 | [diff] [blame] | 1928 | * React when text is pasted into the scrollPort. |
| 1929 | */ |
| 1930 | hterm.Terminal.prototype.onPaste_ = function(e) { |
| 1931 | this.io.onVTKeystroke(e.text); |
| 1932 | }; |
| 1933 | |
| 1934 | /** |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1935 | * React when the ScrollPort is resized. |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1936 | * |
| 1937 | * Note: This function should not directly contain code that alters the internal |
| 1938 | * state of the terminal. That kind of code belongs in realizeWidth or |
| 1939 | * realizeHeight, so that it can be executed synchronously in the case of a |
| 1940 | * programmatic width change. |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1941 | */ |
| 1942 | hterm.Terminal.prototype.onResize_ = function() { |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1943 | var columnCount = Math.floor(this.scrollPort_.getScreenWidth() / |
rginda | 35c456b | 2012-02-09 17:29:05 -0800 | [diff] [blame] | 1944 | this.scrollPort_.characterSize.width); |
| 1945 | var rowCount = Math.floor(this.scrollPort_.getScreenHeight() / |
| 1946 | this.scrollPort_.characterSize.height); |
| 1947 | |
| 1948 | if (!(columnCount || rowCount)) { |
| 1949 | // We avoid these situations since they happen sometimes when the terminal |
| 1950 | // gets removed from the document, and we can't deal with that. |
| 1951 | return; |
| 1952 | } |
| 1953 | |
Dmitry Polukhin | bb2ef71 | 2012-01-19 19:00:37 +0400 | [diff] [blame] | 1954 | this.realizeSize_(columnCount, rowCount); |
rginda | c9bc550 | 2012-01-18 11:48:44 -0800 | [diff] [blame] | 1955 | this.scheduleSyncCursorPosition_(); |
rginda | f0090c9 | 2012-02-10 14:58:52 -0800 | [diff] [blame] | 1956 | this.overlaySize(); |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1957 | }; |
| 1958 | |
| 1959 | /** |
| 1960 | * Service the cursor blink timeout. |
| 1961 | */ |
| 1962 | hterm.Terminal.prototype.onCursorBlink_ = function() { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1963 | if (this.cursorNode_.style.opacity == '0') { |
| 1964 | this.cursorNode_.style.opacity = '1'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1965 | } else { |
rginda | 87b8646 | 2011-12-14 13:48:03 -0800 | [diff] [blame] | 1966 | this.cursorNode_.style.opacity = '0'; |
rginda | 8ba3364 | 2011-12-14 12:31:31 -0800 | [diff] [blame] | 1967 | } |
| 1968 | }; |
David Reveman | 8f55249 | 2012-03-28 12:18:41 -0400 | [diff] [blame] | 1969 | |
| 1970 | /** |
| 1971 | * Set the scrollbar-visible mode bit. |
| 1972 | * |
| 1973 | * If scrollbar-visible is on, the vertical scrollbar will be visible. |
| 1974 | * Otherwise it will not. |
| 1975 | * |
| 1976 | * Defaults to on. |
| 1977 | * |
| 1978 | * @param {boolean} state True to set scrollbar-visible mode, false to unset. |
| 1979 | */ |
| 1980 | hterm.Terminal.prototype.setScrollbarVisible = function(state) { |
| 1981 | this.scrollPort_.setScrollbarVisible(state); |
| 1982 | }; |