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