| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
;(function() { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
'use strict'; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
var window = this |
| 53 |
, document = this.document; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
function EventEmitter() { |
| 60 |
this._events = this._events || {}; |
| 61 |
} |
| 62 |
|
| 63 |
EventEmitter.prototype.addListener = function(type, listener) { |
| 64 |
this._events[type] = this._events[type] || []; |
| 65 |
this._events[type].push(listener); |
| 66 |
}; |
| 67 |
|
| 68 |
EventEmitter.prototype.on = EventEmitter.prototype.addListener; |
| 69 |
|
| 70 |
EventEmitter.prototype.removeListener = function(type, listener) { |
| 71 |
if (!this._events[type]) return; |
| 72 |
|
| 73 |
var obj = this._events[type] |
| 74 |
, i = obj.length; |
| 75 |
|
| 76 |
while (i--) { |
| 77 |
if (obj[i] === listener || obj[i].listener === listener) { |
| 78 |
obj.splice(i, 1); |
| 79 |
return; |
| 80 |
} |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
EventEmitter.prototype.off = EventEmitter.prototype.removeListener; |
| 85 |
|
| 86 |
EventEmitter.prototype.removeAllListeners = function(type) { |
| 87 |
if (this._events[type]) delete this._events[type]; |
| 88 |
}; |
| 89 |
|
| 90 |
EventEmitter.prototype.once = function(type, listener) { |
| 91 |
function on() { |
| 92 |
var args = Array.prototype.slice.call(arguments); |
| 93 |
this.removeListener(type, on); |
| 94 |
return listener.apply(this, args); |
| 95 |
} |
| 96 |
on.listener = listener; |
| 97 |
return this.on(type, on); |
| 98 |
}; |
| 99 |
|
| 100 |
EventEmitter.prototype.emit = function(type) { |
| 101 |
if (!this._events[type]) return; |
| 102 |
|
| 103 |
var args = Array.prototype.slice.call(arguments, 1) |
| 104 |
, obj = this._events[type] |
| 105 |
, l = obj.length |
| 106 |
, i = 0; |
| 107 |
|
| 108 |
for (; i < l; i++) { |
| 109 |
obj[i].apply(this, args); |
| 110 |
} |
| 111 |
}; |
| 112 |
|
| 113 |
EventEmitter.prototype.listeners = function(type) { |
| 114 |
return this._events[type] = this._events[type] || []; |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
function Stream() { |
| 122 |
EventEmitter.call(this); |
| 123 |
} |
| 124 |
|
| 125 |
inherits(Stream, EventEmitter); |
| 126 |
|
| 127 |
Stream.prototype.pipe = function(dest, options) { |
| 128 |
var src = this |
| 129 |
, ondata |
| 130 |
, onerror |
| 131 |
, onend; |
| 132 |
|
| 133 |
function unbind() { |
| 134 |
src.removeListener('data', ondata); |
| 135 |
src.removeListener('error', onerror); |
| 136 |
src.removeListener('end', onend); |
| 137 |
dest.removeListener('error', onerror); |
| 138 |
dest.removeListener('close', unbind); |
| 139 |
} |
| 140 |
|
| 141 |
src.on('data', ondata = function(data) { |
| 142 |
dest.write(data); |
| 143 |
}); |
| 144 |
|
| 145 |
src.on('error', onerror = function(err) { |
| 146 |
unbind(); |
| 147 |
if (!this.listeners('error').length) { |
| 148 |
throw err; |
| 149 |
} |
| 150 |
}); |
| 151 |
|
| 152 |
src.on('end', onend = function() { |
| 153 |
dest.end(); |
| 154 |
unbind(); |
| 155 |
}); |
| 156 |
|
| 157 |
dest.on('error', onerror); |
| 158 |
dest.on('close', unbind); |
| 159 |
|
| 160 |
dest.emit('pipe', src); |
| 161 |
|
| 162 |
return dest; |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
var normal = 0 |
| 170 |
, escaped = 1 |
| 171 |
, csi = 2 |
| 172 |
, osc = 3 |
| 173 |
, charset = 4 |
| 174 |
, dcs = 5 |
| 175 |
, ignore = 6 |
| 176 |
, UDK = { type: 'udk' }; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
function Terminal(options) { |
| 183 |
var self = this; |
| 184 |
|
| 185 |
if (!(this instanceof Terminal)) { |
| 186 |
return new Terminal(arguments[0], arguments[1], arguments[2]); |
| 187 |
} |
| 188 |
|
| 189 |
Stream.call(this); |
| 190 |
|
| 191 |
if (typeof options === 'number') { |
| 192 |
options = { |
| 193 |
cols: arguments[0], |
| 194 |
rows: arguments[1], |
| 195 |
handler: arguments[2] |
| 196 |
}; |
| 197 |
} |
| 198 |
|
| 199 |
options = options || {}; |
| 200 |
|
| 201 |
each(keys(Terminal.defaults), function(key) { |
| 202 |
if (options[key] == null) { |
| 203 |
options[key] = Terminal.options[key]; |
| 204 |
|
| 205 |
if (Terminal[key] !== Terminal.defaults[key]) { |
| 206 |
options[key] = Terminal[key]; |
| 207 |
} |
| 208 |
} |
| 209 |
self[key] = options[key]; |
| 210 |
}); |
| 211 |
|
| 212 |
if (options.colors.length === 8) { |
| 213 |
options.colors = options.colors.concat(Terminal._colors.slice(8)); |
| 214 |
} else if (options.colors.length === 16) { |
| 215 |
options.colors = options.colors.concat(Terminal._colors.slice(16)); |
| 216 |
} else if (options.colors.length === 10) { |
| 217 |
options.colors = options.colors.slice(0, -2).concat( |
| 218 |
Terminal._colors.slice(8, -2), options.colors.slice(-2)); |
| 219 |
} else if (options.colors.length === 18) { |
| 220 |
options.colors = options.colors.slice(0, -2).concat( |
| 221 |
Terminal._colors.slice(16, -2), options.colors.slice(-2)); |
| 222 |
} |
| 223 |
this.colors = options.colors; |
| 224 |
|
| 225 |
this.options = options; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
this.parent = options.body || options.parent |
| 230 |
|| (document ? document.getElementsByTagName('body')[0] : null); |
| 231 |
|
| 232 |
this.cols = options.cols || options.geometry[0]; |
| 233 |
this.rows = options.rows || options.geometry[1]; |
| 234 |
|
| 235 |
|
| 236 |
this.setRawMode; |
| 237 |
this.isTTY = true; |
| 238 |
this.isRaw = true; |
| 239 |
this.columns = this.cols; |
| 240 |
this.rows = this.rows; |
| 241 |
|
| 242 |
if (options.handler) { |
| 243 |
this.on('data', options.handler); |
| 244 |
} |
| 245 |
|
| 246 |
this.ybase = 0; |
| 247 |
this.ydisp = 0; |
| 248 |
this.x = 0; |
| 249 |
this.y = 0; |
| 250 |
this.cursorState = 0; |
| 251 |
this.cursorHidden = false; |
| 252 |
this.convertEol; |
| 253 |
this.state = 0; |
| 254 |
this.queue = ''; |
| 255 |
this.scrollTop = 0; |
| 256 |
this.scrollBottom = this.rows - 1; |
| 257 |
|
| 258 |
|
| 259 |
this.applicationKeypad = false; |
| 260 |
this.applicationCursor = false; |
| 261 |
this.originMode = false; |
| 262 |
this.insertMode = false; |
| 263 |
this.wraparoundMode = false; |
| 264 |
this.normal = null; |
| 265 |
|
| 266 |
|
| 267 |
this.prefixMode = false; |
| 268 |
this.selectMode = false; |
| 269 |
this.visualMode = false; |
| 270 |
this.searchMode = false; |
| 271 |
this.searchDown; |
| 272 |
this.entry = ''; |
| 273 |
this.entryPrefix = 'Search: '; |
| 274 |
this._real; |
| 275 |
this._selected; |
| 276 |
this._textarea; |
| 277 |
|
| 278 |
|
| 279 |
this.charset = null; |
| 280 |
this.gcharset = null; |
| 281 |
this.glevel = 0; |
| 282 |
this.charsets = [null]; |
| 283 |
|
| 284 |
|
| 285 |
this.decLocator; |
| 286 |
this.x10Mouse; |
| 287 |
this.vt200Mouse; |
| 288 |
this.vt300Mouse; |
| 289 |
this.normalMouse; |
| 290 |
this.mouseEvents; |
| 291 |
this.sendFocus; |
| 292 |
this.utfMouse; |
| 293 |
this.sgrMouse; |
| 294 |
this.urxvtMouse; |
| 295 |
|
| 296 |
|
| 297 |
this.element; |
| 298 |
this.children; |
| 299 |
this.refreshStart; |
| 300 |
this.refreshEnd; |
| 301 |
this.savedX; |
| 302 |
this.savedY; |
| 303 |
this.savedCols; |
| 304 |
|
| 305 |
|
| 306 |
this.readable = true; |
| 307 |
this.writable = true; |
| 308 |
|
| 309 |
this.defAttr = (0 << 18) | (257 << 9) | (256 << 0); |
| 310 |
this.curAttr = this.defAttr; |
| 311 |
|
| 312 |
this.params = []; |
| 313 |
this.currentParam = 0; |
| 314 |
this.prefix = ''; |
| 315 |
this.postfix = ''; |
| 316 |
|
| 317 |
this.lines = []; |
| 318 |
var i = this.rows; |
| 319 |
while (i--) { |
| 320 |
this.lines.push(this.blankLine()); |
| 321 |
} |
| 322 |
|
| 323 |
this.tabs; |
| 324 |
this.setupStops(); |
| 325 |
} |
| 326 |
|
| 327 |
inherits(Terminal, Stream); |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
Terminal.tangoColors = [ |
| 335 |
|
| 336 |
'#2e3436', |
| 337 |
'#cc0000', |
| 338 |
'#4e9a06', |
| 339 |
'#c4a000', |
| 340 |
'#3465a4', |
| 341 |
'#75507b', |
| 342 |
'#06989a', |
| 343 |
'#d3d7cf', |
| 344 |
|
| 345 |
'#555753', |
| 346 |
'#ef2929', |
| 347 |
'#8ae234', |
| 348 |
'#fce94f', |
| 349 |
'#729fcf', |
| 350 |
'#ad7fa8', |
| 351 |
'#34e2e2', |
| 352 |
'#eeeeec' |
| 353 |
]; |
| 354 |
|
| 355 |
Terminal.xtermColors = [ |
| 356 |
|
| 357 |
'#000000', |
| 358 |
'#cd0000', |
| 359 |
'#00cd00', |
| 360 |
'#cdcd00', |
| 361 |
'#0000ee', |
| 362 |
'#cd00cd', |
| 363 |
'#00cdcd', |
| 364 |
'#e5e5e5', |
| 365 |
|
| 366 |
'#7f7f7f', |
| 367 |
'#ff0000', |
| 368 |
'#00ff00', |
| 369 |
'#ffff00', |
| 370 |
'#5c5cff', |
| 371 |
'#ff00ff', |
| 372 |
'#00ffff', |
| 373 |
'#ffffff' |
| 374 |
]; |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
Terminal.colors = (function() { |
| 379 |
var colors = Terminal.tangoColors.slice() |
| 380 |
, r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff] |
| 381 |
, i; |
| 382 |
|
| 383 |
|
| 384 |
i = 0; |
| 385 |
for (; i < 216; i++) { |
| 386 |
out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]); |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
i = 0; |
| 391 |
for (; i < 24; i++) { |
| 392 |
r = 8 + i * 10; |
| 393 |
out(r, r, r); |
| 394 |
} |
| 395 |
|
| 396 |
function out(r, g, b) { |
| 397 |
colors.push('#' + hex(r) + hex(g) + hex(b)); |
| 398 |
} |
| 399 |
|
| 400 |
function hex(c) { |
| 401 |
c = c.toString(16); |
| 402 |
return c.length < 2 ? '0' + c : c; |
| 403 |
} |
| 404 |
|
| 405 |
return colors; |
| 406 |
})(); |
| 407 |
|
| 408 |
|
| 409 |
Terminal.colors[256] = '#000000'; |
| 410 |
Terminal.colors[257] = '#f0f0f0'; |
| 411 |
|
| 412 |
Terminal._colors = Terminal.colors.slice(); |
| 413 |
|
| 414 |
Terminal.vcolors = (function() { |
| 415 |
var out = [] |
| 416 |
, colors = Terminal.colors |
| 417 |
, i = 0 |
| 418 |
, color; |
| 419 |
|
| 420 |
for (; i < 256; i++) { |
| 421 |
color = parseInt(colors[i].substring(1), 16); |
| 422 |
out.push([ |
| 423 |
(color >> 16) & 0xff, |
| 424 |
(color >> 8) & 0xff, |
| 425 |
color & 0xff |
| 426 |
]); |
| 427 |
} |
| 428 |
|
| 429 |
return out; |
| 430 |
})(); |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
Terminal.defaults = { |
| 437 |
colors: Terminal.colors, |
| 438 |
convertEol: false, |
| 439 |
termName: 'xterm', |
| 440 |
geometry: [80, 24], |
| 441 |
cursorBlink: true, |
| 442 |
visualBell: false, |
| 443 |
popOnBell: false, |
| 444 |
scrollback: 1000, |
| 445 |
screenKeys: false, |
| 446 |
debug: false, |
| 447 |
useStyle: false |
| 448 |
|
| 449 |
|
| 450 |
}; |
| 451 |
|
| 452 |
Terminal.options = {}; |
| 453 |
|
| 454 |
each(keys(Terminal.defaults), function(key) { |
| 455 |
Terminal[key] = Terminal.defaults[key]; |
| 456 |
Terminal.options[key] = Terminal.defaults[key]; |
| 457 |
}); |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
Terminal.focus = null; |
| 464 |
|
| 465 |
Terminal.prototype.focus = function() { |
| 466 |
if (Terminal.focus === this) return; |
| 467 |
|
| 468 |
if (Terminal.focus) { |
| 469 |
Terminal.focus.blur(); |
| 470 |
} |
| 471 |
|
| 472 |
if (this.sendFocus) this.send('\x1b[I'); |
| 473 |
this.showCursor(); |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
Terminal.focus = this; |
| 484 |
}; |
| 485 |
|
| 486 |
Terminal.prototype.blur = function() { |
| 487 |
if (Terminal.focus !== this) return; |
| 488 |
|
| 489 |
this.cursorState = 0; |
| 490 |
this.refresh(this.y, this.y); |
| 491 |
if (this.sendFocus) this.send('\x1b[O'); |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
Terminal.focus = null; |
| 502 |
}; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
Terminal.prototype.initGlobal = function() { |
| 509 |
var document = this.document; |
| 510 |
|
| 511 |
Terminal._boundDocs = Terminal._boundDocs || []; |
| 512 |
if (~indexOf(Terminal._boundDocs, document)) { |
| 513 |
return; |
| 514 |
} |
| 515 |
Terminal._boundDocs.push(document); |
| 516 |
|
| 517 |
Terminal.bindPaste(document); |
| 518 |
|
| 519 |
Terminal.bindKeys(document); |
| 520 |
|
| 521 |
Terminal.bindCopy(document); |
| 522 |
|
| 523 |
if (this.isMobile) { |
| 524 |
this.fixMobile(document); |
| 525 |
} |
| 526 |
|
| 527 |
if (this.useStyle) { |
| 528 |
Terminal.insertStyle(document, this.colors[256], this.colors[257]); |
| 529 |
} |
| 530 |
}; |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
Terminal.bindPaste = function(document) { |
| 537 |
|
| 538 |
|
| 539 |
var window = document.defaultView; |
| 540 |
on(window, 'paste', function(ev) { |
| 541 |
var term = Terminal.focus; |
| 542 |
if (!term) return; |
| 543 |
if (ev.clipboardData) { |
| 544 |
term.send(ev.clipboardData.getData('text/plain')); |
| 545 |
} else if (term.context.clipboardData) { |
| 546 |
term.send(term.context.clipboardData.getData('Text')); |
| 547 |
} |
| 548 |
|
| 549 |
term.element.contentEditable = 'inherit'; |
| 550 |
return cancel(ev); |
| 551 |
}); |
| 552 |
}; |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
Terminal.bindKeys = function(document) { |
| 559 |
|
| 560 |
|
| 561 |
on(document, 'keydown', function(ev) { |
| 562 |
if (!Terminal.focus) return; |
| 563 |
var target = ev.target || ev.srcElement; |
| 564 |
if (!target) return; |
| 565 |
if (target === Terminal.focus.element |
| 566 |
|| target === Terminal.focus.context |
| 567 |
|| target === Terminal.focus.document |
| 568 |
|| target === Terminal.focus.body |
| 569 |
|| target === Terminal._textarea |
| 570 |
|| target === Terminal.focus.parent) { |
| 571 |
return Terminal.focus.keyDown(ev); |
| 572 |
} |
| 573 |
}, true); |
| 574 |
|
| 575 |
on(document, 'keypress', function(ev) { |
| 576 |
if (!Terminal.focus) return; |
| 577 |
var target = ev.target || ev.srcElement; |
| 578 |
if (!target) return; |
| 579 |
if (target === Terminal.focus.element |
| 580 |
|| target === Terminal.focus.context |
| 581 |
|| target === Terminal.focus.document |
| 582 |
|| target === Terminal.focus.body |
| 583 |
|| target === Terminal._textarea |
| 584 |
|| target === Terminal.focus.parent) { |
| 585 |
return Terminal.focus.keyPress(ev); |
| 586 |
} |
| 587 |
}, true); |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
on(document, 'mousedown', function(ev) { |
| 592 |
if (!Terminal.focus) return; |
| 593 |
|
| 594 |
var el = ev.target || ev.srcElement; |
| 595 |
if (!el) return; |
| 596 |
|
| 597 |
do { |
| 598 |
if (el === Terminal.focus.element) return; |
| 599 |
} while (el = el.parentNode); |
| 600 |
|
| 601 |
Terminal.focus.blur(); |
| 602 |
}); |
| 603 |
}; |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
Terminal.bindCopy = function(document) { |
| 610 |
var window = document.defaultView; |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
on(window, 'copy', function(ev) { |
| 631 |
var term = Terminal.focus; |
| 632 |
if (!term) return; |
| 633 |
if (!term._selected) return; |
| 634 |
var textarea = term.getCopyTextarea(); |
| 635 |
var text = term.grabText( |
| 636 |
term._selected.x1, term._selected.x2, |
| 637 |
term._selected.y1, term._selected.y2); |
| 638 |
term.emit('copy', text); |
| 639 |
textarea.focus(); |
| 640 |
textarea.textContent = text; |
| 641 |
textarea.value = text; |
| 642 |
textarea.setSelectionRange(0, text.length); |
| 643 |
setTimeout(function() { |
| 644 |
term.element.focus(); |
| 645 |
term.focus(); |
| 646 |
}, 1); |
| 647 |
}); |
| 648 |
}; |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
Terminal.prototype.fixMobile = function(document) { |
| 655 |
var self = this; |
| 656 |
|
| 657 |
var textarea = document.createElement('textarea'); |
| 658 |
textarea.style.position = 'absolute'; |
| 659 |
textarea.style.left = '-32000px'; |
| 660 |
textarea.style.top = '-32000px'; |
| 661 |
textarea.style.width = '0px'; |
| 662 |
textarea.style.height = '0px'; |
| 663 |
textarea.style.opacity = '0'; |
| 664 |
textarea.style.backgroundColor = 'transparent'; |
| 665 |
textarea.style.borderStyle = 'none'; |
| 666 |
textarea.style.outlineStyle = 'none'; |
| 667 |
textarea.autocapitalize = 'none'; |
| 668 |
textarea.autocorrect = 'off'; |
| 669 |
|
| 670 |
document.getElementsByTagName('body')[0].appendChild(textarea); |
| 671 |
|
| 672 |
Terminal._textarea = textarea; |
| 673 |
|
| 674 |
setTimeout(function() { |
| 675 |
textarea.focus(); |
| 676 |
}, 1000); |
| 677 |
|
| 678 |
if (this.isAndroid) { |
| 679 |
on(textarea, 'change', function() { |
| 680 |
var value = textarea.textContent || textarea.value; |
| 681 |
textarea.value = ''; |
| 682 |
textarea.textContent = ''; |
| 683 |
self.send(value + '\r'); |
| 684 |
}); |
| 685 |
} |
| 686 |
}; |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
Terminal.insertStyle = function(document, bg, fg) { |
| 693 |
var style = document.getElementById('term-style'); |
| 694 |
if (style) return; |
| 695 |
|
| 696 |
var head = document.getElementsByTagName('head')[0]; |
| 697 |
if (!head) return; |
| 698 |
|
| 699 |
var style = document.createElement('style'); |
| 700 |
style.id = 'term-style'; |
| 701 |
|
| 702 |
|
| 703 |
style.innerHTML = '' |
| 704 |
+ '.terminal {\n' |
| 705 |
+ ' float: left;\n' |
| 706 |
+ ' border: ' + bg + ' solid 5px;\n' |
| 707 |
+ ' font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;\n' |
| 708 |
+ ' font-size: 11px;\n' |
| 709 |
+ ' color: ' + fg + ';\n' |
| 710 |
+ ' background: ' + bg + ';\n' |
| 711 |
+ '}\n' |
| 712 |
+ '\n' |
| 713 |
+ '.terminal-cursor {\n' |
| 714 |
+ ' color: ' + bg + ';\n' |
| 715 |
+ ' background: ' + fg + ';\n' |
| 716 |
+ '}\n'; |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
head.insertBefore(style, head.firstChild); |
| 732 |
}; |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
Terminal.prototype.open = function(parent) { |
| 739 |
var self = this |
| 740 |
, i = 0 |
| 741 |
, div; |
| 742 |
|
| 743 |
this.parent = parent || this.parent; |
| 744 |
|
| 745 |
if (!this.parent) { |
| 746 |
throw new Error('Terminal requires a parent element.'); |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
this.context = this.parent.ownerDocument.defaultView; |
| 751 |
this.document = this.parent.ownerDocument; |
| 752 |
this.body = this.document.getElementsByTagName('body')[0]; |
| 753 |
|
| 754 |
|
| 755 |
if (this.context.navigator && this.context.navigator.userAgent) { |
| 756 |
this.isMac = !!~this.context.navigator.userAgent.indexOf('Mac'); |
| 757 |
this.isIpad = !!~this.context.navigator.userAgent.indexOf('iPad'); |
| 758 |
this.isIphone = !!~this.context.navigator.userAgent.indexOf('iPhone'); |
| 759 |
this.isAndroid = !!~this.context.navigator.userAgent.indexOf('Android'); |
| 760 |
this.isMobile = this.isIpad || this.isIphone || this.isAndroid; |
| 761 |
this.isMSIE = !!~this.context.navigator.userAgent.indexOf('MSIE'); |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
this.element = this.document.createElement('div'); |
| 766 |
this.element.className = 'terminal'; |
| 767 |
this.element.style.outline = 'none'; |
| 768 |
this.element.setAttribute('tabindex', 0); |
| 769 |
this.element.setAttribute('spellcheck', 'false'); |
| 770 |
this.element.style.backgroundColor = this.colors[256]; |
| 771 |
this.element.style.color = this.colors[257]; |
| 772 |
|
| 773 |
|
| 774 |
this.children = []; |
| 775 |
for (; i < this.rows; i++) { |
| 776 |
div = this.document.createElement('div'); |
| 777 |
this.element.appendChild(div); |
| 778 |
this.children.push(div); |
| 779 |
} |
| 780 |
this.parent.appendChild(this.element); |
| 781 |
|
| 782 |
|
| 783 |
this.refresh(0, this.rows - 1); |
| 784 |
|
| 785 |
if (!('useEvents' in this.options) || this.options.useEvents) { |
| 786 |
|
| 787 |
|
| 788 |
this.initGlobal(); |
| 789 |
} |
| 790 |
|
| 791 |
if (!('useFocus' in this.options) || this.options.useFocus) { |
| 792 |
|
| 793 |
this.focus(); |
| 794 |
|
| 795 |
|
| 796 |
this.startBlink(); |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
on(this.element, 'focus', function() { |
| 801 |
self.focus(); |
| 802 |
if (self.isMobile) { |
| 803 |
Terminal._textarea.focus(); |
| 804 |
} |
| 805 |
}); |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
on(this.element, 'mousedown', function() { |
| 813 |
self.focus(); |
| 814 |
}); |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
on(this.element, 'mousedown', function(ev) { |
| 821 |
var button = ev.button != null |
| 822 |
? +ev.button |
| 823 |
: ev.which != null |
| 824 |
? ev.which - 1 |
| 825 |
: null; |
| 826 |
|
| 827 |
|
| 828 |
if (self.isMSIE) { |
| 829 |
button = button === 1 ? 0 : button === 4 ? 1 : button; |
| 830 |
} |
| 831 |
|
| 832 |
if (button !== 2) return; |
| 833 |
|
| 834 |
self.element.contentEditable = 'true'; |
| 835 |
setTimeout(function() { |
| 836 |
self.element.contentEditable = 'inherit'; |
| 837 |
}, 1); |
| 838 |
}, true); |
| 839 |
} |
| 840 |
|
| 841 |
if (!('useMouse' in this.options) || this.options.useMouse) { |
| 842 |
|
| 843 |
|
| 844 |
this.bindMouse(); |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
if (!('useFocus' in this.options) || this.options.useFocus) { |
| 850 |
|
| 851 |
|
| 852 |
setTimeout(function() { |
| 853 |
self.element.focus(); |
| 854 |
}, 100); |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
if (Terminal.brokenBold == null) { |
| 860 |
Terminal.brokenBold = isBoldBroken(this.document); |
| 861 |
} |
| 862 |
|
| 863 |
this.emit('open'); |
| 864 |
}; |
| 865 |
|
| 866 |
Terminal.prototype.setRawMode = function(value) { |
| 867 |
this.isRaw = !!value; |
| 868 |
}; |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
Terminal.prototype.bindMouse = function() { |
| 879 |
var el = this.element |
| 880 |
, self = this |
| 881 |
, pressed = 32; |
| 882 |
|
| 883 |
var wheelEvent = 'onmousewheel' in this.context |
| 884 |
? 'mousewheel' |
| 885 |
: 'DOMMouseScroll'; |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
function sendButton(ev) { |
| 891 |
var button |
| 892 |
, pos; |
| 893 |
|
| 894 |
|
| 895 |
button = getButton(ev); |
| 896 |
|
| 897 |
|
| 898 |
pos = getCoords(ev); |
| 899 |
if (!pos) return; |
| 900 |
|
| 901 |
sendEvent(button, pos); |
| 902 |
|
| 903 |
switch (ev.type) { |
| 904 |
case 'mousedown': |
| 905 |
pressed = button; |
| 906 |
break; |
| 907 |
case 'mouseup': |
| 908 |
|
| 909 |
|
| 910 |
pressed = 32; |
| 911 |
break; |
| 912 |
case wheelEvent: |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
break; |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
function sendMove(ev) { |
| 923 |
var button = pressed |
| 924 |
, pos; |
| 925 |
|
| 926 |
pos = getCoords(ev); |
| 927 |
if (!pos) return; |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
button += 32; |
| 932 |
|
| 933 |
sendEvent(button, pos); |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
function encode(data, ch) { |
| 939 |
if (!self.utfMouse) { |
| 940 |
if (ch === 255) return data.push(0); |
| 941 |
if (ch > 127) ch = 127; |
| 942 |
data.push(ch); |
| 943 |
} else { |
| 944 |
if (ch === 2047) return data.push(0); |
| 945 |
if (ch < 127) { |
| 946 |
data.push(ch); |
| 947 |
} else { |
| 948 |
if (ch > 2047) ch = 2047; |
| 949 |
data.push(0xC0 | (ch >> 6)); |
| 950 |
data.push(0x80 | (ch & 0x3F)); |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
function sendEvent(button, pos) { |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
if (self.vt300Mouse) { |
| 969 |
|
| 970 |
|
| 971 |
button &= 3; |
| 972 |
pos.x -= 32; |
| 973 |
pos.y -= 32; |
| 974 |
var data = '\x1b[24'; |
| 975 |
if (button === 0) data += '1'; |
| 976 |
else if (button === 1) data += '3'; |
| 977 |
else if (button === 2) data += '5'; |
| 978 |
else if (button === 3) return; |
| 979 |
else data += '0'; |
| 980 |
data += '~[' + pos.x + ',' + pos.y + ']\r'; |
| 981 |
self.send(data); |
| 982 |
return; |
| 983 |
} |
| 984 |
|
| 985 |
if (self.decLocator) { |
| 986 |
|
| 987 |
button &= 3; |
| 988 |
pos.x -= 32; |
| 989 |
pos.y -= 32; |
| 990 |
if (button === 0) button = 2; |
| 991 |
else if (button === 1) button = 4; |
| 992 |
else if (button === 2) button = 6; |
| 993 |
else if (button === 3) button = 3; |
| 994 |
self.send('\x1b[' |
| 995 |
+ button |
| 996 |
+ ';' |
| 997 |
+ (button === 3 ? 4 : 0) |
| 998 |
+ ';' |
| 999 |
+ pos.y |
| 1000 |
+ ';' |
| 1001 |
+ pos.x |
| 1002 |
+ ';' |
| 1003 |
+ (pos.page || 0) |
| 1004 |
+ '&w'); |
| 1005 |
return; |
| 1006 |
} |
| 1007 |
|
| 1008 |
if (self.urxvtMouse) { |
| 1009 |
pos.x -= 32; |
| 1010 |
pos.y -= 32; |
| 1011 |
pos.x++; |
| 1012 |
pos.y++; |
| 1013 |
self.send('\x1b[' + button + ';' + pos.x + ';' + pos.y + 'M'); |
| 1014 |
return; |
| 1015 |
} |
| 1016 |
|
| 1017 |
if (self.sgrMouse) { |
| 1018 |
pos.x -= 32; |
| 1019 |
pos.y -= 32; |
| 1020 |
self.send('\x1b[<' |
| 1021 |
+ ((button & 3) === 3 ? button & ~3 : button) |
| 1022 |
+ ';' |
| 1023 |
+ pos.x |
| 1024 |
+ ';' |
| 1025 |
+ pos.y |
| 1026 |
+ ((button & 3) === 3 ? 'm' : 'M')); |
| 1027 |
return; |
| 1028 |
} |
| 1029 |
|
| 1030 |
var data = []; |
| 1031 |
|
| 1032 |
encode(data, button); |
| 1033 |
encode(data, pos.x); |
| 1034 |
encode(data, pos.y); |
| 1035 |
|
| 1036 |
self.send('\x1b[M' + String.fromCharCode.apply(String, data)); |
| 1037 |
} |
| 1038 |
|
| 1039 |
function getButton(ev) { |
| 1040 |
var button |
| 1041 |
, shift |
| 1042 |
, meta |
| 1043 |
, ctrl |
| 1044 |
, mod; |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
switch (ev.type) { |
| 1054 |
case 'mousedown': |
| 1055 |
button = ev.button != null |
| 1056 |
? +ev.button |
| 1057 |
: ev.which != null |
| 1058 |
? ev.which - 1 |
| 1059 |
: null; |
| 1060 |
|
| 1061 |
if (self.isMSIE) { |
| 1062 |
button = button === 1 ? 0 : button === 4 ? 1 : button; |
| 1063 |
} |
| 1064 |
break; |
| 1065 |
case 'mouseup': |
| 1066 |
button = 3; |
| 1067 |
break; |
| 1068 |
case 'DOMMouseScroll': |
| 1069 |
button = ev.detail < 0 |
| 1070 |
? 64 |
| 1071 |
: 65; |
| 1072 |
break; |
| 1073 |
case 'mousewheel': |
| 1074 |
button = ev.wheelDeltaY > 0 |
| 1075 |
? 64 |
| 1076 |
: 65; |
| 1077 |
break; |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
shift = ev.shiftKey ? 4 : 0; |
| 1083 |
meta = ev.metaKey ? 8 : 0; |
| 1084 |
ctrl = ev.ctrlKey ? 16 : 0; |
| 1085 |
mod = shift | meta | ctrl; |
| 1086 |
|
| 1087 |
|
| 1088 |
if (self.vt200Mouse) { |
| 1089 |
|
| 1090 |
mod &= ctrl; |
| 1091 |
} else if (!self.normalMouse) { |
| 1092 |
mod = 0; |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
button = (32 + (mod << 2)) + button; |
| 1097 |
|
| 1098 |
return button; |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
function getCoords(ev) { |
| 1103 |
var x, y, w, h, el; |
| 1104 |
|
| 1105 |
|
| 1106 |
if (ev.pageX == null) return; |
| 1107 |
|
| 1108 |
x = ev.pageX; |
| 1109 |
y = ev.pageY; |
| 1110 |
el = self.element; |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
while (el && el !== self.document.documentElement) { |
| 1115 |
x -= el.offsetLeft; |
| 1116 |
y -= el.offsetTop; |
| 1117 |
el = 'offsetParent' in el |
| 1118 |
? el.offsetParent |
| 1119 |
: el.parentNode; |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
w = self.element.clientWidth; |
| 1124 |
h = self.element.clientHeight; |
| 1125 |
x = Math.round((x / w) * self.cols); |
| 1126 |
y = Math.round((y / h) * self.rows); |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
if (x < 0) x = 0; |
| 1131 |
if (x > self.cols) x = self.cols; |
| 1132 |
if (y < 0) y = 0; |
| 1133 |
if (y > self.rows) y = self.rows; |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
x += 32; |
| 1138 |
y += 32; |
| 1139 |
|
| 1140 |
return { |
| 1141 |
x: x, |
| 1142 |
y: y, |
| 1143 |
type: ev.type === wheelEvent |
| 1144 |
? 'mousewheel' |
| 1145 |
: ev.type |
| 1146 |
}; |
| 1147 |
} |
| 1148 |
|
| 1149 |
on(el, 'mousedown', function(ev) { |
| 1150 |
if (!self.mouseEvents) return; |
| 1151 |
|
| 1152 |
|
| 1153 |
sendButton(ev); |
| 1154 |
|
| 1155 |
|
| 1156 |
self.focus(); |
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if (self.normalMouse) on(self.document, 'mousemove', sendMove); |
| 1168 |
|
| 1169 |
|
| 1170 |
if (!self.x10Mouse) { |
| 1171 |
on(self.document, 'mouseup', function up(ev) { |
| 1172 |
sendButton(ev); |
| 1173 |
if (self.normalMouse) off(self.document, 'mousemove', sendMove); |
| 1174 |
off(self.document, 'mouseup', up); |
| 1175 |
return cancel(ev); |
| 1176 |
}); |
| 1177 |
} |
| 1178 |
|
| 1179 |
return cancel(ev); |
| 1180 |
}); |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
on(el, wheelEvent, function(ev) { |
| 1187 |
if (!self.mouseEvents) return; |
| 1188 |
if (self.x10Mouse |
| 1189 |
|| self.vt300Mouse |
| 1190 |
|| self.decLocator) return; |
| 1191 |
sendButton(ev); |
| 1192 |
return cancel(ev); |
| 1193 |
}); |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
on(el, wheelEvent, function(ev) { |
| 1198 |
if (self.mouseEvents) return; |
| 1199 |
if (self.applicationKeypad) return; |
| 1200 |
if (ev.type === 'DOMMouseScroll') { |
| 1201 |
self.scrollDisp(ev.detail < 0 ? -5 : 5); |
| 1202 |
} else { |
| 1203 |
self.scrollDisp(ev.wheelDeltaY > 0 ? -5 : 5); |
| 1204 |
} |
| 1205 |
return cancel(ev); |
| 1206 |
}); |
| 1207 |
}; |
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
Terminal.prototype.close = |
| 1214 |
Terminal.prototype.destroySoon = |
| 1215 |
Terminal.prototype.destroy = function() { |
| 1216 |
if (this.destroyed) { |
| 1217 |
return; |
| 1218 |
} |
| 1219 |
|
| 1220 |
if (this._blink) { |
| 1221 |
clearInterval(this._blink); |
| 1222 |
delete this._blink; |
| 1223 |
} |
| 1224 |
|
| 1225 |
this.readable = false; |
| 1226 |
this.writable = false; |
| 1227 |
this.destroyed = true; |
| 1228 |
this._events = {}; |
| 1229 |
|
| 1230 |
this.handler = function() {}; |
| 1231 |
this.write = function() {}; |
| 1232 |
this.end = function() {}; |
| 1233 |
|
| 1234 |
if (this.element.parentNode) { |
| 1235 |
this.element.parentNode.removeChild(this.element); |
| 1236 |
} |
| 1237 |
|
| 1238 |
this.emit('end'); |
| 1239 |
this.emit('close'); |
| 1240 |
this.emit('finish'); |
| 1241 |
this.emit('destroy'); |
| 1242 |
}; |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
Terminal.prototype.refresh = function(start, end) { |
| 1259 |
var x |
| 1260 |
, y |
| 1261 |
, i |
| 1262 |
, line |
| 1263 |
, out |
| 1264 |
, ch |
| 1265 |
, width |
| 1266 |
, data |
| 1267 |
, attr |
| 1268 |
, bg |
| 1269 |
, fg |
| 1270 |
, flags |
| 1271 |
, row |
| 1272 |
, parent; |
| 1273 |
|
| 1274 |
if (end - start >= this.rows / 2) { |
| 1275 |
parent = this.element.parentNode; |
| 1276 |
if (parent) parent.removeChild(this.element); |
| 1277 |
} |
| 1278 |
|
| 1279 |
width = this.cols; |
| 1280 |
y = start; |
| 1281 |
|
| 1282 |
if (end >= this.lines.length) { |
| 1283 |
this.log('`end` is too large. Most likely a bad CSR.'); |
| 1284 |
end = this.lines.length - 1; |
| 1285 |
} |
| 1286 |
|
| 1287 |
for (; y <= end; y++) { |
| 1288 |
row = y + this.ydisp; |
| 1289 |
|
| 1290 |
line = this.lines[row]; |
| 1291 |
out = ''; |
| 1292 |
|
| 1293 |
if (y === this.y |
| 1294 |
&& this.cursorState |
| 1295 |
&& (this.ydisp === this.ybase || this.selectMode) |
| 1296 |
&& !this.cursorHidden) { |
| 1297 |
x = this.x; |
| 1298 |
} else { |
| 1299 |
x = -1; |
| 1300 |
} |
| 1301 |
|
| 1302 |
attr = this.defAttr; |
| 1303 |
i = 0; |
| 1304 |
|
| 1305 |
for (; i < width; i++) { |
| 1306 |
data = line[i][0]; |
| 1307 |
ch = line[i][1]; |
| 1308 |
|
| 1309 |
if (i === x) data = -1; |
| 1310 |
|
| 1311 |
if (data !== attr) { |
| 1312 |
if (attr !== this.defAttr) { |
| 1313 |
out += '</span>'; |
| 1314 |
} |
| 1315 |
if (data !== this.defAttr) { |
| 1316 |
if (data === -1) { |
| 1317 |
out += '<span class="reverse-video terminal-cursor">'; |
| 1318 |
} else { |
| 1319 |
out += '<span style="'; |
| 1320 |
|
| 1321 |
bg = data & 0x1ff; |
| 1322 |
fg = (data >> 9) & 0x1ff; |
| 1323 |
flags = data >> 18; |
| 1324 |
|
| 1325 |
|
| 1326 |
if (flags & 1) { |
| 1327 |
if (!Terminal.brokenBold) { |
| 1328 |
out += 'font-weight:bold;'; |
| 1329 |
} |
| 1330 |
|
| 1331 |
if (fg < 8) fg += 8; |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
if (flags & 2) { |
| 1336 |
out += 'text-decoration:underline;'; |
| 1337 |
} |
| 1338 |
|
| 1339 |
|
| 1340 |
if (flags & 4) { |
| 1341 |
if (flags & 2) { |
| 1342 |
out = out.slice(0, -1); |
| 1343 |
out += ' blink;'; |
| 1344 |
} else { |
| 1345 |
out += 'text-decoration:blink;'; |
| 1346 |
} |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
if (flags & 8) { |
| 1351 |
bg = (data >> 9) & 0x1ff; |
| 1352 |
fg = data & 0x1ff; |
| 1353 |
|
| 1354 |
|
| 1355 |
if ((flags & 1) && fg < 8) fg += 8; |
| 1356 |
} |
| 1357 |
|
| 1358 |
|
| 1359 |
if (flags & 16) { |
| 1360 |
out += 'visibility:hidden;'; |
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
if (bg !== 256) { |
| 1370 |
out += 'background-color:' |
| 1371 |
+ this.colors[bg] |
| 1372 |
+ ';'; |
| 1373 |
} |
| 1374 |
|
| 1375 |
if (fg !== 257) { |
| 1376 |
out += 'color:' |
| 1377 |
+ this.colors[fg] |
| 1378 |
+ ';'; |
| 1379 |
} |
| 1380 |
|
| 1381 |
out += '">'; |
| 1382 |
} |
| 1383 |
} |
| 1384 |
} |
| 1385 |
|
| 1386 |
switch (ch) { |
| 1387 |
case '&': |
| 1388 |
out += '&'; |
| 1389 |
break; |
| 1390 |
case '<': |
| 1391 |
out += '<'; |
| 1392 |
break; |
| 1393 |
case '>': |
| 1394 |
out += '>'; |
| 1395 |
break; |
| 1396 |
default: |
| 1397 |
if (ch <= ' ') { |
| 1398 |
out += ' '; |
| 1399 |
} else { |
| 1400 |
if (isWide(ch)) i++; |
| 1401 |
out += ch; |
| 1402 |
} |
| 1403 |
break; |
| 1404 |
} |
| 1405 |
|
| 1406 |
attr = data; |
| 1407 |
} |
| 1408 |
|
| 1409 |
if (attr !== this.defAttr) { |
| 1410 |
out += '</span>'; |
| 1411 |
} |
| 1412 |
|
| 1413 |
this.children[y].innerHTML = out; |
| 1414 |
} |
| 1415 |
|
| 1416 |
if (parent) parent.appendChild(this.element); |
| 1417 |
}; |
| 1418 |
|
| 1419 |
Terminal.prototype._cursorBlink = function() { |
| 1420 |
if (Terminal.focus !== this) return; |
| 1421 |
this.cursorState ^= 1; |
| 1422 |
this.refresh(this.y, this.y); |
| 1423 |
}; |
| 1424 |
|
| 1425 |
Terminal.prototype.showCursor = function() { |
| 1426 |
if (!this.cursorState) { |
| 1427 |
this.cursorState = 1; |
| 1428 |
this.refresh(this.y, this.y); |
| 1429 |
} else { |
| 1430 |
|
| 1431 |
|
| 1432 |
} |
| 1433 |
}; |
| 1434 |
|
| 1435 |
Terminal.prototype.startBlink = function() { |
| 1436 |
if (!this.cursorBlink) return; |
| 1437 |
var self = this; |
| 1438 |
this._blinker = function() { |
| 1439 |
self._cursorBlink(); |
| 1440 |
}; |
| 1441 |
this._blink = setInterval(this._blinker, 500); |
| 1442 |
}; |
| 1443 |
|
| 1444 |
Terminal.prototype.refreshBlink = function() { |
| 1445 |
if (!this.cursorBlink || !this._blink) return; |
| 1446 |
clearInterval(this._blink); |
| 1447 |
this._blink = setInterval(this._blinker, 500); |
| 1448 |
}; |
| 1449 |
|
| 1450 |
Terminal.prototype.scroll = function() { |
| 1451 |
var row; |
| 1452 |
|
| 1453 |
if (++this.ybase === this.scrollback) { |
| 1454 |
this.ybase = this.ybase / 2 | 0; |
| 1455 |
this.lines = this.lines.slice(-(this.ybase + this.rows) + 1); |
| 1456 |
} |
| 1457 |
|
| 1458 |
this.ydisp = this.ybase; |
| 1459 |
|
| 1460 |
|
| 1461 |
row = this.ybase + this.rows - 1; |
| 1462 |
|
| 1463 |
|
| 1464 |
row -= this.rows - 1 - this.scrollBottom; |
| 1465 |
|
| 1466 |
if (row === this.lines.length) { |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
this.lines.push(this.blankLine()); |
| 1472 |
} else { |
| 1473 |
|
| 1474 |
this.lines.splice(row, 0, this.blankLine()); |
| 1475 |
} |
| 1476 |
|
| 1477 |
if (this.scrollTop !== 0) { |
| 1478 |
if (this.ybase !== 0) { |
| 1479 |
this.ybase--; |
| 1480 |
this.ydisp = this.ybase; |
| 1481 |
} |
| 1482 |
this.lines.splice(this.ybase + this.scrollTop, 1); |
| 1483 |
} |
| 1484 |
|
| 1485 |
|
| 1486 |
this.updateRange(this.scrollTop); |
| 1487 |
this.updateRange(this.scrollBottom); |
| 1488 |
}; |
| 1489 |
|
| 1490 |
Terminal.prototype.scrollDisp = function(disp) { |
| 1491 |
this.ydisp += disp; |
| 1492 |
|
| 1493 |
if (this.ydisp > this.ybase) { |
| 1494 |
this.ydisp = this.ybase; |
| 1495 |
} else if (this.ydisp < 0) { |
| 1496 |
this.ydisp = 0; |
| 1497 |
} |
| 1498 |
|
| 1499 |
this.refresh(0, this.rows - 1); |
| 1500 |
}; |
| 1501 |
|
| 1502 |
Terminal.prototype.write = function(data) { |
| 1503 |
var l = data.length |
| 1504 |
, i = 0 |
| 1505 |
, j |
| 1506 |
, cs |
| 1507 |
, ch; |
| 1508 |
|
| 1509 |
this.refreshStart = this.y; |
| 1510 |
this.refreshEnd = this.y; |
| 1511 |
|
| 1512 |
if (this.ybase !== this.ydisp) { |
| 1513 |
this.ydisp = this.ybase; |
| 1514 |
this.maxRange(); |
| 1515 |
} |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
for (; i < l; i++, this.lch = ch) { |
| 1520 |
ch = data[i]; |
| 1521 |
switch (this.state) { |
| 1522 |
case normal: |
| 1523 |
switch (ch) { |
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
case '\x07': |
| 1531 |
this.bell(); |
| 1532 |
break; |
| 1533 |
|
| 1534 |
|
| 1535 |
case '\n': |
| 1536 |
case '\x0b': |
| 1537 |
case '\x0c': |
| 1538 |
if (this.convertEol) { |
| 1539 |
this.x = 0; |
| 1540 |
} |
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
this.y++; |
| 1545 |
if (this.y > this.scrollBottom) { |
| 1546 |
this.y--; |
| 1547 |
this.scroll(); |
| 1548 |
} |
| 1549 |
break; |
| 1550 |
|
| 1551 |
|
| 1552 |
case '\r': |
| 1553 |
this.x = 0; |
| 1554 |
break; |
| 1555 |
|
| 1556 |
|
| 1557 |
case '\x08': |
| 1558 |
if (this.x > 0) { |
| 1559 |
this.x--; |
| 1560 |
} |
| 1561 |
break; |
| 1562 |
|
| 1563 |
|
| 1564 |
case '\t': |
| 1565 |
this.x = this.nextStop(); |
| 1566 |
break; |
| 1567 |
|
| 1568 |
|
| 1569 |
case '\x0e': |
| 1570 |
this.setgLevel(1); |
| 1571 |
break; |
| 1572 |
|
| 1573 |
|
| 1574 |
case '\x0f': |
| 1575 |
this.setgLevel(0); |
| 1576 |
break; |
| 1577 |
|
| 1578 |
|
| 1579 |
case '\x1b': |
| 1580 |
this.state = escaped; |
| 1581 |
break; |
| 1582 |
|
| 1583 |
default: |
| 1584 |
|
| 1585 |
if (ch >= ' ') { |
| 1586 |
if (this.charset && this.charset[ch]) { |
| 1587 |
ch = this.charset[ch]; |
| 1588 |
} |
| 1589 |
|
| 1590 |
if (this.x >= this.cols) { |
| 1591 |
this.x = 0; |
| 1592 |
this.y++; |
| 1593 |
if (this.y > this.scrollBottom) { |
| 1594 |
this.y--; |
| 1595 |
this.scroll(); |
| 1596 |
} |
| 1597 |
} |
| 1598 |
|
| 1599 |
this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch]; |
| 1600 |
this.x++; |
| 1601 |
this.updateRange(this.y); |
| 1602 |
|
| 1603 |
if (isWide(ch)) { |
| 1604 |
j = this.y + this.ybase; |
| 1605 |
if (this.cols < 2 || this.x >= this.cols) { |
| 1606 |
this.lines[j][this.x - 1] = [this.curAttr, ' ']; |
| 1607 |
break; |
| 1608 |
} |
| 1609 |
this.lines[j][this.x] = [this.curAttr, ' ']; |
| 1610 |
this.x++; |
| 1611 |
} |
| 1612 |
} |
| 1613 |
break; |
| 1614 |
} |
| 1615 |
break; |
| 1616 |
case escaped: |
| 1617 |
switch (ch) { |
| 1618 |
|
| 1619 |
case '[': |
| 1620 |
this.params = []; |
| 1621 |
this.currentParam = 0; |
| 1622 |
this.state = csi; |
| 1623 |
break; |
| 1624 |
|
| 1625 |
|
| 1626 |
case ']': |
| 1627 |
this.params = []; |
| 1628 |
this.currentParam = 0; |
| 1629 |
this.state = osc; |
| 1630 |
break; |
| 1631 |
|
| 1632 |
|
| 1633 |
case 'P': |
| 1634 |
this.params = []; |
| 1635 |
this.prefix = ''; |
| 1636 |
this.currentParam = ''; |
| 1637 |
this.state = dcs; |
| 1638 |
break; |
| 1639 |
|
| 1640 |
|
| 1641 |
case '_': |
| 1642 |
this.state = ignore; |
| 1643 |
break; |
| 1644 |
|
| 1645 |
|
| 1646 |
case '^': |
| 1647 |
this.state = ignore; |
| 1648 |
break; |
| 1649 |
|
| 1650 |
|
| 1651 |
case 'c': |
| 1652 |
this.reset(); |
| 1653 |
break; |
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
case 'E': |
| 1658 |
this.x = 0; |
| 1659 |
; |
| 1660 |
case 'D': |
| 1661 |
this.index(); |
| 1662 |
break; |
| 1663 |
|
| 1664 |
|
| 1665 |
case 'M': |
| 1666 |
this.reverseIndex(); |
| 1667 |
break; |
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
case '%': |
| 1672 |
|
| 1673 |
this.setgLevel(0); |
| 1674 |
this.setgCharset(0, Terminal.charsets.US); |
| 1675 |
this.state = normal; |
| 1676 |
i++; |
| 1677 |
break; |
| 1678 |
|
| 1679 |
|
| 1680 |
case '(': |
| 1681 |
case ')': |
| 1682 |
case '*': |
| 1683 |
case '+': |
| 1684 |
case '-': |
| 1685 |
case '.': |
| 1686 |
switch (ch) { |
| 1687 |
case '(': |
| 1688 |
this.gcharset = 0; |
| 1689 |
break; |
| 1690 |
case ')': |
| 1691 |
this.gcharset = 1; |
| 1692 |
break; |
| 1693 |
case '*': |
| 1694 |
this.gcharset = 2; |
| 1695 |
break; |
| 1696 |
case '+': |
| 1697 |
this.gcharset = 3; |
| 1698 |
break; |
| 1699 |
case '-': |
| 1700 |
this.gcharset = 1; |
| 1701 |
break; |
| 1702 |
case '.': |
| 1703 |
this.gcharset = 2; |
| 1704 |
break; |
| 1705 |
} |
| 1706 |
this.state = charset; |
| 1707 |
break; |
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
case '/': |
| 1713 |
this.gcharset = 3; |
| 1714 |
this.state = charset; |
| 1715 |
i--; |
| 1716 |
break; |
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
case 'N': |
| 1722 |
break; |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
case 'O': |
| 1727 |
break; |
| 1728 |
|
| 1729 |
|
| 1730 |
case 'n': |
| 1731 |
this.setgLevel(2); |
| 1732 |
break; |
| 1733 |
|
| 1734 |
|
| 1735 |
case 'o': |
| 1736 |
this.setgLevel(3); |
| 1737 |
break; |
| 1738 |
|
| 1739 |
|
| 1740 |
case '|': |
| 1741 |
this.setgLevel(3); |
| 1742 |
break; |
| 1743 |
|
| 1744 |
|
| 1745 |
case '}': |
| 1746 |
this.setgLevel(2); |
| 1747 |
break; |
| 1748 |
|
| 1749 |
|
| 1750 |
case '~': |
| 1751 |
this.setgLevel(1); |
| 1752 |
break; |
| 1753 |
|
| 1754 |
|
| 1755 |
case '7': |
| 1756 |
this.saveCursor(); |
| 1757 |
this.state = normal; |
| 1758 |
break; |
| 1759 |
|
| 1760 |
|
| 1761 |
case '8': |
| 1762 |
this.restoreCursor(); |
| 1763 |
this.state = normal; |
| 1764 |
break; |
| 1765 |
|
| 1766 |
|
| 1767 |
case '#': |
| 1768 |
this.state = normal; |
| 1769 |
i++; |
| 1770 |
break; |
| 1771 |
|
| 1772 |
|
| 1773 |
case 'H': |
| 1774 |
this.tabSet(); |
| 1775 |
break; |
| 1776 |
|
| 1777 |
|
| 1778 |
case '=': |
| 1779 |
this.log('Serial port requested application keypad.'); |
| 1780 |
this.applicationKeypad = true; |
| 1781 |
this.state = normal; |
| 1782 |
break; |
| 1783 |
|
| 1784 |
|
| 1785 |
case '>': |
| 1786 |
this.log('Switching back to normal keypad.'); |
| 1787 |
this.applicationKeypad = false; |
| 1788 |
this.state = normal; |
| 1789 |
break; |
| 1790 |
|
| 1791 |
default: |
| 1792 |
this.state = normal; |
| 1793 |
this.error('Unknown ESC control: %s.', ch); |
| 1794 |
break; |
| 1795 |
} |
| 1796 |
break; |
| 1797 |
|
| 1798 |
case charset: |
| 1799 |
switch (ch) { |
| 1800 |
case '0': |
| 1801 |
cs = Terminal.charsets.SCLD; |
| 1802 |
break; |
| 1803 |
case 'A': |
| 1804 |
cs = Terminal.charsets.UK; |
| 1805 |
break; |
| 1806 |
case 'B': |
| 1807 |
cs = Terminal.charsets.US; |
| 1808 |
break; |
| 1809 |
case '4': |
| 1810 |
cs = Terminal.charsets.Dutch; |
| 1811 |
break; |
| 1812 |
case 'C': |
| 1813 |
case '5': |
| 1814 |
cs = Terminal.charsets.Finnish; |
| 1815 |
break; |
| 1816 |
case 'R': |
| 1817 |
cs = Terminal.charsets.French; |
| 1818 |
break; |
| 1819 |
case 'Q': |
| 1820 |
cs = Terminal.charsets.FrenchCanadian; |
| 1821 |
break; |
| 1822 |
case 'K': |
| 1823 |
cs = Terminal.charsets.German; |
| 1824 |
break; |
| 1825 |
case 'Y': |
| 1826 |
cs = Terminal.charsets.Italian; |
| 1827 |
break; |
| 1828 |
case 'E': |
| 1829 |
case '6': |
| 1830 |
cs = Terminal.charsets.NorwegianDanish; |
| 1831 |
break; |
| 1832 |
case 'Z': |
| 1833 |
cs = Terminal.charsets.Spanish; |
| 1834 |
break; |
| 1835 |
case 'H': |
| 1836 |
case '7': |
| 1837 |
cs = Terminal.charsets.Swedish; |
| 1838 |
break; |
| 1839 |
case '=': |
| 1840 |
cs = Terminal.charsets.Swiss; |
| 1841 |
break; |
| 1842 |
case '/': |
| 1843 |
cs = Terminal.charsets.ISOLatin; |
| 1844 |
i++; |
| 1845 |
break; |
| 1846 |
default: |
| 1847 |
cs = Terminal.charsets.US; |
| 1848 |
break; |
| 1849 |
} |
| 1850 |
this.setgCharset(this.gcharset, cs); |
| 1851 |
this.gcharset = null; |
| 1852 |
this.state = normal; |
| 1853 |
break; |
| 1854 |
|
| 1855 |
case osc: |
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
if ((this.lch === '\x1b' && ch === '\\') || ch === '\x07') { |
| 1860 |
if (this.lch === '\x1b') { |
| 1861 |
if (typeof this.currentParam === 'string') { |
| 1862 |
this.currentParam = this.currentParam.slice(0, -1); |
| 1863 |
} else if (typeof this.currentParam == 'number') { |
| 1864 |
this.currentParam = (this.currentParam - ('\x1b'.charCodeAt(0) - 48)) / 10; |
| 1865 |
} |
| 1866 |
} |
| 1867 |
|
| 1868 |
this.params.push(this.currentParam); |
| 1869 |
|
| 1870 |
switch (this.params[0]) { |
| 1871 |
case 0: |
| 1872 |
case 1: |
| 1873 |
case 2: |
| 1874 |
if (this.params[1]) { |
| 1875 |
this.title = this.params[1]; |
| 1876 |
this.handleTitle(this.title); |
| 1877 |
} |
| 1878 |
break; |
| 1879 |
case 3: |
| 1880 |
|
| 1881 |
break; |
| 1882 |
case 4: |
| 1883 |
case 5: |
| 1884 |
|
| 1885 |
break; |
| 1886 |
case 10: |
| 1887 |
case 11: |
| 1888 |
case 12: |
| 1889 |
case 13: |
| 1890 |
case 14: |
| 1891 |
case 15: |
| 1892 |
case 16: |
| 1893 |
case 17: |
| 1894 |
case 18: |
| 1895 |
case 19: |
| 1896 |
|
| 1897 |
break; |
| 1898 |
case 46: |
| 1899 |
|
| 1900 |
break; |
| 1901 |
case 50: |
| 1902 |
|
| 1903 |
break; |
| 1904 |
case 51: |
| 1905 |
|
| 1906 |
break; |
| 1907 |
case 52: |
| 1908 |
|
| 1909 |
break; |
| 1910 |
case 104: |
| 1911 |
case 105: |
| 1912 |
case 110: |
| 1913 |
case 111: |
| 1914 |
case 112: |
| 1915 |
case 113: |
| 1916 |
case 114: |
| 1917 |
case 115: |
| 1918 |
case 116: |
| 1919 |
case 117: |
| 1920 |
case 118: |
| 1921 |
|
| 1922 |
break; |
| 1923 |
} |
| 1924 |
|
| 1925 |
this.params = []; |
| 1926 |
this.currentParam = 0; |
| 1927 |
this.state = normal; |
| 1928 |
} else { |
| 1929 |
if (!this.params.length) { |
| 1930 |
if (ch >= '0' && ch <= '9') { |
| 1931 |
this.currentParam = |
| 1932 |
this.currentParam * 10 + ch.charCodeAt(0) - 48; |
| 1933 |
} else if (ch === ';') { |
| 1934 |
this.params.push(this.currentParam); |
| 1935 |
this.currentParam = ''; |
| 1936 |
} |
| 1937 |
} else { |
| 1938 |
this.currentParam += ch; |
| 1939 |
} |
| 1940 |
} |
| 1941 |
break; |
| 1942 |
|
| 1943 |
case csi: |
| 1944 |
|
| 1945 |
if (ch === '?' || ch === '>' || ch === '!') { |
| 1946 |
this.prefix = ch; |
| 1947 |
break; |
| 1948 |
} |
| 1949 |
|
| 1950 |
|
| 1951 |
if (ch >= '0' && ch <= '9') { |
| 1952 |
this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48; |
| 1953 |
break; |
| 1954 |
} |
| 1955 |
|
| 1956 |
|
| 1957 |
if (ch === '$' || ch === '"' || ch === ' ' || ch === '\'') { |
| 1958 |
this.postfix = ch; |
| 1959 |
break; |
| 1960 |
} |
| 1961 |
|
| 1962 |
this.params.push(this.currentParam); |
| 1963 |
this.currentParam = 0; |
| 1964 |
|
| 1965 |
|
| 1966 |
if (ch === ';') break; |
| 1967 |
|
| 1968 |
this.state = normal; |
| 1969 |
|
| 1970 |
switch (ch) { |
| 1971 |
|
| 1972 |
|
| 1973 |
case 'A': |
| 1974 |
this.cursorUp(this.params); |
| 1975 |
break; |
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
case 'B': |
| 1980 |
this.cursorDown(this.params); |
| 1981 |
break; |
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
case 'C': |
| 1986 |
this.cursorForward(this.params); |
| 1987 |
break; |
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
case 'D': |
| 1992 |
this.cursorBackward(this.params); |
| 1993 |
break; |
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
case 'H': |
| 1998 |
this.cursorPos(this.params); |
| 1999 |
break; |
| 2000 |
|
| 2001 |
|
| 2002 |
case 'J': |
| 2003 |
this.eraseInDisplay(this.params); |
| 2004 |
break; |
| 2005 |
|
| 2006 |
|
| 2007 |
case 'K': |
| 2008 |
this.eraseInLine(this.params); |
| 2009 |
break; |
| 2010 |
|
| 2011 |
|
| 2012 |
case 'm': |
| 2013 |
if (!this.prefix) { |
| 2014 |
this.charAttributes(this.params); |
| 2015 |
} |
| 2016 |
break; |
| 2017 |
|
| 2018 |
|
| 2019 |
case 'n': |
| 2020 |
if (!this.prefix) { |
| 2021 |
this.deviceStatus(this.params); |
| 2022 |
} |
| 2023 |
break; |
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
case '@': |
| 2032 |
this.insertChars(this.params); |
| 2033 |
break; |
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
case 'E': |
| 2038 |
this.cursorNextLine(this.params); |
| 2039 |
break; |
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
case 'F': |
| 2044 |
this.cursorPrecedingLine(this.params); |
| 2045 |
break; |
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
case 'G': |
| 2050 |
this.cursorCharAbsolute(this.params); |
| 2051 |
break; |
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
case 'L': |
| 2056 |
this.insertLines(this.params); |
| 2057 |
break; |
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
case 'M': |
| 2062 |
this.deleteLines(this.params); |
| 2063 |
break; |
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
case 'P': |
| 2068 |
this.deleteChars(this.params); |
| 2069 |
break; |
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
case 'X': |
| 2074 |
this.eraseChars(this.params); |
| 2075 |
break; |
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
case '`': |
| 2080 |
this.charPosAbsolute(this.params); |
| 2081 |
break; |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
case 'a': |
| 2086 |
this.HPositionRelative(this.params); |
| 2087 |
break; |
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
case 'c': |
| 2094 |
this.sendDeviceAttributes(this.params); |
| 2095 |
break; |
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
case 'd': |
| 2100 |
this.linePosAbsolute(this.params); |
| 2101 |
break; |
| 2102 |
|
| 2103 |
|
| 2104 |
case 'e': |
| 2105 |
this.VPositionRelative(this.params); |
| 2106 |
break; |
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
case 'f': |
| 2112 |
this.HVPosition(this.params); |
| 2113 |
break; |
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
case 'h': |
| 2118 |
this.setMode(this.params); |
| 2119 |
break; |
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
case 'l': |
| 2124 |
this.resetMode(this.params); |
| 2125 |
break; |
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
case 'r': |
| 2132 |
this.setScrollRegion(this.params); |
| 2133 |
break; |
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
case 's': |
| 2138 |
this.saveCursor(this.params); |
| 2139 |
break; |
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
case 'u': |
| 2144 |
this.restoreCursor(this.params); |
| 2145 |
break; |
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
case 'I': |
| 2154 |
this.cursorForwardTab(this.params); |
| 2155 |
break; |
| 2156 |
|
| 2157 |
|
| 2158 |
case 'S': |
| 2159 |
this.scrollUp(this.params); |
| 2160 |
break; |
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
case 'T': |
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
if (this.params.length < 2 && !this.prefix) { |
| 2175 |
this.scrollDown(this.params); |
| 2176 |
} |
| 2177 |
break; |
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
case 'Z': |
| 2182 |
this.cursorBackwardTab(this.params); |
| 2183 |
break; |
| 2184 |
|
| 2185 |
|
| 2186 |
case 'b': |
| 2187 |
this.repeatPrecedingCharacter(this.params); |
| 2188 |
break; |
| 2189 |
|
| 2190 |
|
| 2191 |
case 'g': |
| 2192 |
this.tabClear(this.params); |
| 2193 |
break; |
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
case 'p': |
| 2229 |
switch (this.prefix) { |
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
case '!': |
| 2234 |
this.softReset(this.params); |
| 2235 |
break; |
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
} |
| 2249 |
break; |
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
default: |
| 2389 |
this.error('Unknown CSI code: %s.', ch); |
| 2390 |
break; |
| 2391 |
} |
| 2392 |
|
| 2393 |
this.prefix = ''; |
| 2394 |
this.postfix = ''; |
| 2395 |
break; |
| 2396 |
|
| 2397 |
case dcs: |
| 2398 |
if ((this.lch === '\x1b' && ch === '\\') || ch === '\x07') { |
| 2399 |
|
| 2400 |
if (this.prefix === 'tmux;\x1b') { |
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
if (ch === '\x07') { |
| 2409 |
this.currentParam += ch; |
| 2410 |
continue; |
| 2411 |
} |
| 2412 |
} |
| 2413 |
|
| 2414 |
if (this.lch === '\x1b') { |
| 2415 |
if (typeof this.currentParam === 'string') { |
| 2416 |
this.currentParam = this.currentParam.slice(0, -1); |
| 2417 |
} else if (typeof this.currentParam == 'number') { |
| 2418 |
this.currentParam = (this.currentParam - ('\x1b'.charCodeAt(0) - 48)) / 10; |
| 2419 |
} |
| 2420 |
} |
| 2421 |
|
| 2422 |
this.params.push(this.currentParam); |
| 2423 |
|
| 2424 |
var pt = this.params[this.params.length - 1]; |
| 2425 |
|
| 2426 |
switch (this.prefix) { |
| 2427 |
|
| 2428 |
|
| 2429 |
case UDK: |
| 2430 |
this.emit('udk', { |
| 2431 |
clearAll: this.params[0] === 0, |
| 2432 |
eraseBelow: this.params[0] === 1, |
| 2433 |
lockKeys: this.params[1] === 0, |
| 2434 |
dontLockKeys: this.params[1] === 1, |
| 2435 |
keyList: (this.params[2] + '').split(';').map(function(part) { |
| 2436 |
part = part.split('/'); |
| 2437 |
return { |
| 2438 |
keyCode: part[0], |
| 2439 |
hexKeyValue: part[1] |
| 2440 |
}; |
| 2441 |
}) |
| 2442 |
}); |
| 2443 |
break; |
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
case '$q': |
| 2449 |
var valid = 0; |
| 2450 |
|
| 2451 |
switch (pt) { |
| 2452 |
|
| 2453 |
|
| 2454 |
case '"q': |
| 2455 |
pt = '0"q'; |
| 2456 |
valid = 1; |
| 2457 |
break; |
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
case '"p': |
| 2462 |
pt = '61;0"p'; |
| 2463 |
valid = 1; |
| 2464 |
break; |
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
case 'r': |
| 2469 |
pt = '' |
| 2470 |
+ (this.scrollTop + 1) |
| 2471 |
+ ';' |
| 2472 |
+ (this.scrollBottom + 1) |
| 2473 |
+ 'r'; |
| 2474 |
valid = 1; |
| 2475 |
break; |
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
case 'm': |
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
valid = 0; |
| 2484 |
break; |
| 2485 |
|
| 2486 |
default: |
| 2487 |
this.error('Unknown DCS Pt: %s.', pt); |
| 2488 |
valid = 0; |
| 2489 |
break; |
| 2490 |
} |
| 2491 |
|
| 2492 |
this.send('\x1bP' + valid + '$r' + pt + '\x1b\\'); |
| 2493 |
break; |
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
case '+p': |
| 2498 |
this.emit('set terminfo', { |
| 2499 |
name: this.params[0] |
| 2500 |
}); |
| 2501 |
break; |
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
case '+q': |
| 2509 |
var valid = false; |
| 2510 |
this.send('\x1bP' + +valid + '+r' + pt + '\x1b\\'); |
| 2511 |
break; |
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
case 'tmux;\x1b': |
| 2517 |
this.emit('passthrough', pt); |
| 2518 |
break; |
| 2519 |
|
| 2520 |
default: |
| 2521 |
this.error('Unknown DCS prefix: %s.', pt); |
| 2522 |
break; |
| 2523 |
} |
| 2524 |
|
| 2525 |
this.currentParam = 0; |
| 2526 |
this.prefix = ''; |
| 2527 |
this.state = normal; |
| 2528 |
} else { |
| 2529 |
this.currentParam += ch; |
| 2530 |
if (!this.prefix) { |
| 2531 |
if (/^\d*;\d*\|/.test(this.currentParam)) { |
| 2532 |
this.prefix = UDK; |
| 2533 |
this.params = this.currentParam.split(/[;|]/).map(function(n) { |
| 2534 |
if (!n.length) return 0; |
| 2535 |
return +n; |
| 2536 |
}).slice(0, -1); |
| 2537 |
this.currentParam = ''; |
| 2538 |
} else if (/^[$+][a-zA-Z]/.test(this.currentParam) |
| 2539 |
|| /^\w+;\x1b/.test(this.currentParam)) { |
| 2540 |
this.prefix = this.currentParam; |
| 2541 |
this.currentParam = ''; |
| 2542 |
} |
| 2543 |
} |
| 2544 |
} |
| 2545 |
break; |
| 2546 |
|
| 2547 |
case ignore: |
| 2548 |
|
| 2549 |
if ((this.lch === '\x1b' && ch === '\\') || ch === '\x07') { |
| 2550 |
this.state = normal; |
| 2551 |
} |
| 2552 |
break; |
| 2553 |
} |
| 2554 |
} |
| 2555 |
|
| 2556 |
this.updateRange(this.y); |
| 2557 |
this.refresh(this.refreshStart, this.refreshEnd); |
| 2558 |
|
| 2559 |
return true; |
| 2560 |
}; |
| 2561 |
|
| 2562 |
Terminal.prototype.writeln = function(data) { |
| 2563 |
return this.write(data + '\r\n'); |
| 2564 |
}; |
| 2565 |
|
| 2566 |
Terminal.prototype.end = function(data) { |
| 2567 |
var ret = true; |
| 2568 |
if (data) { |
| 2569 |
ret = this.write(data); |
| 2570 |
} |
| 2571 |
this.destroySoon(); |
| 2572 |
return ret; |
| 2573 |
}; |
| 2574 |
|
| 2575 |
Terminal.prototype.resume = function() { |
| 2576 |
; |
| 2577 |
}; |
| 2578 |
|
| 2579 |
Terminal.prototype.pause = function() { |
| 2580 |
; |
| 2581 |
}; |
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
Terminal.prototype.keyDown = function(ev) { |
| 2586 |
var self = this |
| 2587 |
, key; |
| 2588 |
|
| 2589 |
switch (ev.keyCode) { |
| 2590 |
|
| 2591 |
case 8: |
| 2592 |
if (ev.altKey) { |
| 2593 |
key = '\x17'; |
| 2594 |
break; |
| 2595 |
} |
| 2596 |
if (ev.shiftKey) { |
| 2597 |
key = '\x08'; |
| 2598 |
break; |
| 2599 |
} |
| 2600 |
key = '\x7f'; |
| 2601 |
break; |
| 2602 |
|
| 2603 |
case 9: |
| 2604 |
if (ev.shiftKey) { |
| 2605 |
key = '\x1b[Z'; |
| 2606 |
break; |
| 2607 |
} |
| 2608 |
key = '\t'; |
| 2609 |
break; |
| 2610 |
|
| 2611 |
case 13: |
| 2612 |
key = '\r'; |
| 2613 |
break; |
| 2614 |
|
| 2615 |
case 27: |
| 2616 |
key = '\x1b'; |
| 2617 |
break; |
| 2618 |
|
| 2619 |
case 37: |
| 2620 |
if (this.applicationCursor) { |
| 2621 |
key = '\x1bOD'; |
| 2622 |
|
| 2623 |
break; |
| 2624 |
} |
| 2625 |
if (ev.ctrlKey) { |
| 2626 |
key = '\x1b[5D'; |
| 2627 |
break; |
| 2628 |
} |
| 2629 |
key = '\x1b[D'; |
| 2630 |
break; |
| 2631 |
|
| 2632 |
case 39: |
| 2633 |
if (this.applicationCursor) { |
| 2634 |
key = '\x1bOC'; |
| 2635 |
break; |
| 2636 |
} |
| 2637 |
if (ev.ctrlKey) { |
| 2638 |
key = '\x1b[5C'; |
| 2639 |
break; |
| 2640 |
} |
| 2641 |
key = '\x1b[C'; |
| 2642 |
break; |
| 2643 |
|
| 2644 |
case 38: |
| 2645 |
if (this.applicationCursor) { |
| 2646 |
key = '\x1bOA'; |
| 2647 |
break; |
| 2648 |
} |
| 2649 |
if (ev.ctrlKey) { |
| 2650 |
this.scrollDisp(-1); |
| 2651 |
return cancel(ev); |
| 2652 |
} else { |
| 2653 |
key = '\x1b[A'; |
| 2654 |
} |
| 2655 |
break; |
| 2656 |
|
| 2657 |
case 40: |
| 2658 |
if (this.applicationCursor) { |
| 2659 |
key = '\x1bOB'; |
| 2660 |
break; |
| 2661 |
} |
| 2662 |
if (ev.ctrlKey) { |
| 2663 |
this.scrollDisp(1); |
| 2664 |
return cancel(ev); |
| 2665 |
} else { |
| 2666 |
key = '\x1b[B'; |
| 2667 |
} |
| 2668 |
break; |
| 2669 |
|
| 2670 |
case 46: |
| 2671 |
key = '\x1b[3~'; |
| 2672 |
break; |
| 2673 |
|
| 2674 |
case 45: |
| 2675 |
key = '\x1b[2~'; |
| 2676 |
break; |
| 2677 |
|
| 2678 |
case 36: |
| 2679 |
if (this.applicationKeypad) { |
| 2680 |
key = '\x1bOH'; |
| 2681 |
break; |
| 2682 |
} |
| 2683 |
key = '\x1bOH'; |
| 2684 |
break; |
| 2685 |
|
| 2686 |
case 35: |
| 2687 |
if (this.applicationKeypad) { |
| 2688 |
key = '\x1bOF'; |
| 2689 |
break; |
| 2690 |
} |
| 2691 |
key = '\x1bOF'; |
| 2692 |
break; |
| 2693 |
|
| 2694 |
case 33: |
| 2695 |
if (ev.shiftKey) { |
| 2696 |
this.scrollDisp(-(this.rows - 1)); |
| 2697 |
return cancel(ev); |
| 2698 |
} else { |
| 2699 |
key = '\x1b[5~'; |
| 2700 |
} |
| 2701 |
break; |
| 2702 |
|
| 2703 |
case 34: |
| 2704 |
if (ev.shiftKey) { |
| 2705 |
this.scrollDisp(this.rows - 1); |
| 2706 |
return cancel(ev); |
| 2707 |
} else { |
| 2708 |
key = '\x1b[6~'; |
| 2709 |
} |
| 2710 |
break; |
| 2711 |
|
| 2712 |
case 112: |
| 2713 |
key = '\x1bOP'; |
| 2714 |
break; |
| 2715 |
|
| 2716 |
case 113: |
| 2717 |
key = '\x1bOQ'; |
| 2718 |
break; |
| 2719 |
|
| 2720 |
case 114: |
| 2721 |
key = '\x1bOR'; |
| 2722 |
break; |
| 2723 |
|
| 2724 |
case 115: |
| 2725 |
key = '\x1bOS'; |
| 2726 |
break; |
| 2727 |
|
| 2728 |
case 116: |
| 2729 |
key = '\x1b[15~'; |
| 2730 |
break; |
| 2731 |
|
| 2732 |
case 117: |
| 2733 |
key = '\x1b[17~'; |
| 2734 |
break; |
| 2735 |
|
| 2736 |
case 118: |
| 2737 |
key = '\x1b[18~'; |
| 2738 |
break; |
| 2739 |
|
| 2740 |
case 119: |
| 2741 |
key = '\x1b[19~'; |
| 2742 |
break; |
| 2743 |
|
| 2744 |
case 120: |
| 2745 |
key = '\x1b[20~'; |
| 2746 |
break; |
| 2747 |
|
| 2748 |
case 121: |
| 2749 |
key = '\x1b[21~'; |
| 2750 |
break; |
| 2751 |
|
| 2752 |
case 122: |
| 2753 |
key = '\x1b[23~'; |
| 2754 |
break; |
| 2755 |
|
| 2756 |
case 123: |
| 2757 |
key = '\x1b[24~'; |
| 2758 |
break; |
| 2759 |
default: |
| 2760 |
|
| 2761 |
if (ev.ctrlKey) { |
| 2762 |
if (ev.keyCode >= 65 && ev.keyCode <= 90) { |
| 2763 |
|
| 2764 |
if (this.screenKeys) { |
| 2765 |
if (!this.prefixMode && !this.selectMode && ev.keyCode === 65) { |
| 2766 |
this.enterPrefix(); |
| 2767 |
return cancel(ev); |
| 2768 |
} |
| 2769 |
} |
| 2770 |
|
| 2771 |
if (this.prefixMode && ev.keyCode === 86) { |
| 2772 |
this.leavePrefix(); |
| 2773 |
return; |
| 2774 |
} |
| 2775 |
|
| 2776 |
if ((this.prefixMode || this.selectMode) && ev.keyCode === 67) { |
| 2777 |
if (this.visualMode) { |
| 2778 |
setTimeout(function() { |
| 2779 |
self.leaveVisual(); |
| 2780 |
}, 1); |
| 2781 |
} |
| 2782 |
return; |
| 2783 |
} |
| 2784 |
key = String.fromCharCode(ev.keyCode - 64); |
| 2785 |
} else if (ev.keyCode === 32) { |
| 2786 |
|
| 2787 |
key = String.fromCharCode(0); |
| 2788 |
} else if (ev.keyCode >= 51 && ev.keyCode <= 55) { |
| 2789 |
|
| 2790 |
key = String.fromCharCode(ev.keyCode - 51 + 27); |
| 2791 |
} else if (ev.keyCode === 56) { |
| 2792 |
|
| 2793 |
key = String.fromCharCode(127); |
| 2794 |
} else if (ev.keyCode === 219) { |
| 2795 |
|
| 2796 |
key = String.fromCharCode(27); |
| 2797 |
} else if (ev.keyCode === 221) { |
| 2798 |
|
| 2799 |
key = String.fromCharCode(29); |
| 2800 |
} |
| 2801 |
} else if (ev.altKey) { |
| 2802 |
if (ev.keyCode >= 65 && ev.keyCode <= 90) { |
| 2803 |
key = '\x1b' + String.fromCharCode(ev.keyCode + 32); |
| 2804 |
} else if (ev.keyCode === 192) { |
| 2805 |
key = '\x1b`'; |
| 2806 |
} else if (ev.keyCode >= 48 && ev.keyCode <= 57) { |
| 2807 |
key = '\x1b' + (ev.keyCode - 48); |
| 2808 |
} |
| 2809 |
} |
| 2810 |
break; |
| 2811 |
} |
| 2812 |
|
| 2813 |
if (!key) return true; |
| 2814 |
|
| 2815 |
if (this.prefixMode) { |
| 2816 |
this.leavePrefix(); |
| 2817 |
return cancel(ev); |
| 2818 |
} |
| 2819 |
|
| 2820 |
if (this.selectMode) { |
| 2821 |
this.keySelect(ev, key); |
| 2822 |
return cancel(ev); |
| 2823 |
} |
| 2824 |
|
| 2825 |
this.emit('keydown', ev); |
| 2826 |
this.emit('key', key, ev); |
| 2827 |
|
| 2828 |
this.showCursor(); |
| 2829 |
this.handler(key); |
| 2830 |
|
| 2831 |
return cancel(ev); |
| 2832 |
}; |
| 2833 |
|
| 2834 |
Terminal.prototype.setgLevel = function(g) { |
| 2835 |
this.glevel = g; |
| 2836 |
this.charset = this.charsets[g]; |
| 2837 |
}; |
| 2838 |
|
| 2839 |
Terminal.prototype.setgCharset = function(g, charset) { |
| 2840 |
this.charsets[g] = charset; |
| 2841 |
if (this.glevel === g) { |
| 2842 |
this.charset = charset; |
| 2843 |
} |
| 2844 |
}; |
| 2845 |
|
| 2846 |
Terminal.prototype.keyPress = function(ev) { |
| 2847 |
var key; |
| 2848 |
|
| 2849 |
cancel(ev); |
| 2850 |
|
| 2851 |
if (ev.charCode) { |
| 2852 |
key = ev.charCode; |
| 2853 |
} else if (ev.which == null) { |
| 2854 |
key = ev.keyCode; |
| 2855 |
} else if (ev.which !== 0 && ev.charCode !== 0) { |
| 2856 |
key = ev.which; |
| 2857 |
} else { |
| 2858 |
return false; |
| 2859 |
} |
| 2860 |
|
| 2861 |
if (!key || ev.ctrlKey || ev.altKey || ev.metaKey) return false; |
| 2862 |
|
| 2863 |
key = String.fromCharCode(key); |
| 2864 |
|
| 2865 |
if (this.prefixMode) { |
| 2866 |
this.leavePrefix(); |
| 2867 |
this.keyPrefix(ev, key); |
| 2868 |
return false; |
| 2869 |
} |
| 2870 |
|
| 2871 |
if (this.selectMode) { |
| 2872 |
this.keySelect(ev, key); |
| 2873 |
return false; |
| 2874 |
} |
| 2875 |
|
| 2876 |
this.emit('keypress', key, ev); |
| 2877 |
this.emit('key', key, ev); |
| 2878 |
|
| 2879 |
this.showCursor(); |
| 2880 |
this.handler(key); |
| 2881 |
|
| 2882 |
return false; |
| 2883 |
}; |
| 2884 |
|
| 2885 |
Terminal.prototype.send = function(data) { |
| 2886 |
var self = this; |
| 2887 |
|
| 2888 |
if (!this.queue) { |
| 2889 |
setTimeout(function() { |
| 2890 |
self.handler(self.queue); |
| 2891 |
self.queue = ''; |
| 2892 |
}, 1); |
| 2893 |
} |
| 2894 |
|
| 2895 |
this.queue += data; |
| 2896 |
}; |
| 2897 |
|
| 2898 |
Terminal.prototype.bell = function() { |
| 2899 |
this.emit('bell'); |
| 2900 |
if (!this.visualBell) return; |
| 2901 |
var self = this; |
| 2902 |
this.element.style.borderColor = 'white'; |
| 2903 |
setTimeout(function() { |
| 2904 |
self.element.style.borderColor = ''; |
| 2905 |
}, 10); |
| 2906 |
if (this.popOnBell) this.focus(); |
| 2907 |
}; |
| 2908 |
|
| 2909 |
Terminal.prototype.log = function() { |
| 2910 |
if (!this.debug) return; |
| 2911 |
if (!this.context.console || !this.context.console.log) return; |
| 2912 |
var args = Array.prototype.slice.call(arguments); |
| 2913 |
this.context.console.log.apply(this.context.console, args); |
| 2914 |
}; |
| 2915 |
|
| 2916 |
Terminal.prototype.error = function() { |
| 2917 |
if (!this.debug) return; |
| 2918 |
if (!this.context.console || !this.context.console.error) return; |
| 2919 |
var args = Array.prototype.slice.call(arguments); |
| 2920 |
this.context.console.error.apply(this.context.console, args); |
| 2921 |
}; |
| 2922 |
|
| 2923 |
Terminal.prototype.resize = function(x, y) { |
| 2924 |
var line |
| 2925 |
, el |
| 2926 |
, i |
| 2927 |
, j |
| 2928 |
, ch; |
| 2929 |
|
| 2930 |
if (x < 1) x = 1; |
| 2931 |
if (y < 1) y = 1; |
| 2932 |
|
| 2933 |
|
| 2934 |
j = this.cols; |
| 2935 |
if (j < x) { |
| 2936 |
ch = [this.defAttr, ' ']; |
| 2937 |
i = this.lines.length; |
| 2938 |
while (i--) { |
| 2939 |
while (this.lines[i].length < x) { |
| 2940 |
this.lines[i].push(ch); |
| 2941 |
} |
| 2942 |
} |
| 2943 |
} else if (j > x) { |
| 2944 |
i = this.lines.length; |
| 2945 |
while (i--) { |
| 2946 |
while (this.lines[i].length > x) { |
| 2947 |
this.lines[i].pop(); |
| 2948 |
} |
| 2949 |
} |
| 2950 |
} |
| 2951 |
this.setupStops(j); |
| 2952 |
this.cols = x; |
| 2953 |
this.columns = x; |
| 2954 |
|
| 2955 |
|
| 2956 |
j = this.rows; |
| 2957 |
if (j < y) { |
| 2958 |
el = this.element; |
| 2959 |
while (j++ < y) { |
| 2960 |
if (this.lines.length < y + this.ybase) { |
| 2961 |
this.lines.push(this.blankLine()); |
| 2962 |
} |
| 2963 |
if (this.children.length < y) { |
| 2964 |
line = this.document.createElement('div'); |
| 2965 |
el.appendChild(line); |
| 2966 |
this.children.push(line); |
| 2967 |
} |
| 2968 |
} |
| 2969 |
} else if (j > y) { |
| 2970 |
while (j-- > y) { |
| 2971 |
if (this.lines.length > y + this.ybase) { |
| 2972 |
this.lines.pop(); |
| 2973 |
} |
| 2974 |
if (this.children.length > y) { |
| 2975 |
el = this.children.pop(); |
| 2976 |
if (!el) continue; |
| 2977 |
el.parentNode.removeChild(el); |
| 2978 |
} |
| 2979 |
} |
| 2980 |
} |
| 2981 |
this.rows = y; |
| 2982 |
|
| 2983 |
|
| 2984 |
if (this.y >= y) this.y = y - 1; |
| 2985 |
if (this.x >= x) this.x = x - 1; |
| 2986 |
|
| 2987 |
this.scrollTop = 0; |
| 2988 |
this.scrollBottom = y - 1; |
| 2989 |
|
| 2990 |
this.refresh(0, this.rows - 1); |
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
|
| 2996 |
this.normal = null; |
| 2997 |
|
| 2998 |
|
| 2999 |
this.emit('resize'); |
| 3000 |
}; |
| 3001 |
|
| 3002 |
Terminal.prototype.updateRange = function(y) { |
| 3003 |
if (y < this.refreshStart) this.refreshStart = y; |
| 3004 |
if (y > this.refreshEnd) this.refreshEnd = y; |
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
}; |
| 3012 |
|
| 3013 |
Terminal.prototype.maxRange = function() { |
| 3014 |
this.refreshStart = 0; |
| 3015 |
this.refreshEnd = this.rows - 1; |
| 3016 |
}; |
| 3017 |
|
| 3018 |
Terminal.prototype.setupStops = function(i) { |
| 3019 |
if (i != null) { |
| 3020 |
if (!this.tabs[i]) { |
| 3021 |
i = this.prevStop(i); |
| 3022 |
} |
| 3023 |
} else { |
| 3024 |
this.tabs = {}; |
| 3025 |
i = 0; |
| 3026 |
} |
| 3027 |
|
| 3028 |
for (; i < this.cols; i += 8) { |
| 3029 |
this.tabs[i] = true; |
| 3030 |
} |
| 3031 |
}; |
| 3032 |
|
| 3033 |
Terminal.prototype.prevStop = function(x) { |
| 3034 |
if (x == null) x = this.x; |
| 3035 |
while (!this.tabs[--x] && x > 0); |
| 3036 |
return x >= this.cols |
| 3037 |
? this.cols - 1 |
| 3038 |
: x < 0 ? 0 : x; |
| 3039 |
}; |
| 3040 |
|
| 3041 |
Terminal.prototype.nextStop = function(x) { |
| 3042 |
if (x == null) x = this.x; |
| 3043 |
while (!this.tabs[++x] && x < this.cols); |
| 3044 |
return x >= this.cols |
| 3045 |
? this.cols - 1 |
| 3046 |
: x < 0 ? 0 : x; |
| 3047 |
}; |
| 3048 |
|
| 3049 |
|
| 3050 |
Terminal.prototype.eraseAttr = function() { |
| 3051 |
|
| 3052 |
return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff); |
| 3053 |
}; |
| 3054 |
|
| 3055 |
Terminal.prototype.eraseRight = function(x, y) { |
| 3056 |
var line = this.lines[this.ybase + y] |
| 3057 |
, ch = [this.eraseAttr(), ' ']; |
| 3058 |
|
| 3059 |
|
| 3060 |
for (; x < this.cols; x++) { |
| 3061 |
line[x] = ch; |
| 3062 |
} |
| 3063 |
|
| 3064 |
this.updateRange(y); |
| 3065 |
}; |
| 3066 |
|
| 3067 |
Terminal.prototype.eraseLeft = function(x, y) { |
| 3068 |
var line = this.lines[this.ybase + y] |
| 3069 |
, ch = [this.eraseAttr(), ' ']; |
| 3070 |
|
| 3071 |
x++; |
| 3072 |
while (x--) line[x] = ch; |
| 3073 |
|
| 3074 |
this.updateRange(y); |
| 3075 |
}; |
| 3076 |
|
| 3077 |
Terminal.prototype.eraseLine = function(y) { |
| 3078 |
this.eraseRight(0, y); |
| 3079 |
}; |
| 3080 |
|
| 3081 |
Terminal.prototype.blankLine = function(cur) { |
| 3082 |
var attr = cur |
| 3083 |
? this.eraseAttr() |
| 3084 |
: this.defAttr; |
| 3085 |
|
| 3086 |
var ch = [attr, ' '] |
| 3087 |
, line = [] |
| 3088 |
, i = 0; |
| 3089 |
|
| 3090 |
for (; i < this.cols; i++) { |
| 3091 |
line[i] = ch; |
| 3092 |
} |
| 3093 |
|
| 3094 |
return line; |
| 3095 |
}; |
| 3096 |
|
| 3097 |
Terminal.prototype.ch = function(cur) { |
| 3098 |
return cur |
| 3099 |
? [this.eraseAttr(), ' '] |
| 3100 |
: [this.defAttr, ' ']; |
| 3101 |
}; |
| 3102 |
|
| 3103 |
Terminal.prototype.is = function(term) { |
| 3104 |
var name = this.termName; |
| 3105 |
return (name + '').indexOf(term) === 0; |
| 3106 |
}; |
| 3107 |
|
| 3108 |
Terminal.prototype.handler = function(data) { |
| 3109 |
this.emit('data', data); |
| 3110 |
}; |
| 3111 |
|
| 3112 |
Terminal.prototype.handleTitle = function(title) { |
| 3113 |
this.emit('title', title); |
| 3114 |
}; |
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
Terminal.prototype.index = function() { |
| 3122 |
this.y++; |
| 3123 |
if (this.y > this.scrollBottom) { |
| 3124 |
this.y--; |
| 3125 |
this.scroll(); |
| 3126 |
} |
| 3127 |
this.state = normal; |
| 3128 |
}; |
| 3129 |
|
| 3130 |
|
| 3131 |
Terminal.prototype.reverseIndex = function() { |
| 3132 |
var j; |
| 3133 |
this.y--; |
| 3134 |
if (this.y < this.scrollTop) { |
| 3135 |
this.y++; |
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
this.lines.splice(this.y + this.ybase, 0, this.blankLine(true)); |
| 3140 |
j = this.rows - 1 - this.scrollBottom; |
| 3141 |
this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1); |
| 3142 |
|
| 3143 |
this.updateRange(this.scrollTop); |
| 3144 |
this.updateRange(this.scrollBottom); |
| 3145 |
} |
| 3146 |
this.state = normal; |
| 3147 |
}; |
| 3148 |
|
| 3149 |
|
| 3150 |
Terminal.prototype.reset = function() { |
| 3151 |
this.options.rows = this.rows; |
| 3152 |
this.options.cols = this.cols; |
| 3153 |
Terminal.call(this, this.options); |
| 3154 |
this.refresh(0, this.rows - 1); |
| 3155 |
}; |
| 3156 |
|
| 3157 |
|
| 3158 |
Terminal.prototype.tabSet = function() { |
| 3159 |
this.tabs[this.x] = true; |
| 3160 |
this.state = normal; |
| 3161 |
}; |
| 3162 |
|
| 3163 |
|
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
Terminal.prototype.cursorUp = function(params) { |
| 3170 |
var param = params[0]; |
| 3171 |
if (param < 1) param = 1; |
| 3172 |
this.y -= param; |
| 3173 |
if (this.y < 0) this.y = 0; |
| 3174 |
}; |
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
Terminal.prototype.cursorDown = function(params) { |
| 3179 |
var param = params[0]; |
| 3180 |
if (param < 1) param = 1; |
| 3181 |
this.y += param; |
| 3182 |
if (this.y >= this.rows) { |
| 3183 |
this.y = this.rows - 1; |
| 3184 |
} |
| 3185 |
}; |
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
Terminal.prototype.cursorForward = function(params) { |
| 3190 |
var param = params[0]; |
| 3191 |
if (param < 1) param = 1; |
| 3192 |
this.x += param; |
| 3193 |
if (this.x >= this.cols) { |
| 3194 |
this.x = this.cols - 1; |
| 3195 |
} |
| 3196 |
}; |
| 3197 |
|
| 3198 |
|
| 3199 |
|
| 3200 |
Terminal.prototype.cursorBackward = function(params) { |
| 3201 |
var param = params[0]; |
| 3202 |
if (param < 1) param = 1; |
| 3203 |
this.x -= param; |
| 3204 |
if (this.x < 0) this.x = 0; |
| 3205 |
}; |
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
Terminal.prototype.cursorPos = function(params) { |
| 3210 |
var row, col; |
| 3211 |
|
| 3212 |
row = params[0] - 1; |
| 3213 |
|
| 3214 |
if (params.length >= 2) { |
| 3215 |
col = params[1] - 1; |
| 3216 |
} else { |
| 3217 |
col = 0; |
| 3218 |
} |
| 3219 |
|
| 3220 |
if (row < 0) { |
| 3221 |
row = 0; |
| 3222 |
} else if (row >= this.rows) { |
| 3223 |
row = this.rows - 1; |
| 3224 |
} |
| 3225 |
|
| 3226 |
if (col < 0) { |
| 3227 |
col = 0; |
| 3228 |
} else if (col >= this.cols) { |
| 3229 |
col = this.cols - 1; |
| 3230 |
} |
| 3231 |
|
| 3232 |
this.x = col; |
| 3233 |
this.y = row; |
| 3234 |
}; |
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
Terminal.prototype.eraseInDisplay = function(params) { |
| 3247 |
var j; |
| 3248 |
switch (params[0]) { |
| 3249 |
case 0: |
| 3250 |
this.eraseRight(this.x, this.y); |
| 3251 |
j = this.y + 1; |
| 3252 |
for (; j < this.rows; j++) { |
| 3253 |
this.eraseLine(j); |
| 3254 |
} |
| 3255 |
break; |
| 3256 |
case 1: |
| 3257 |
this.eraseLeft(this.x, this.y); |
| 3258 |
j = this.y; |
| 3259 |
while (j--) { |
| 3260 |
this.eraseLine(j); |
| 3261 |
} |
| 3262 |
break; |
| 3263 |
case 2: |
| 3264 |
j = this.rows; |
| 3265 |
while (j--) this.eraseLine(j); |
| 3266 |
break; |
| 3267 |
case 3: |
| 3268 |
; |
| 3269 |
break; |
| 3270 |
} |
| 3271 |
}; |
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
Terminal.prototype.eraseInLine = function(params) { |
| 3283 |
switch (params[0]) { |
| 3284 |
case 0: |
| 3285 |
this.eraseRight(this.x, this.y); |
| 3286 |
break; |
| 3287 |
case 1: |
| 3288 |
this.eraseLeft(this.x, this.y); |
| 3289 |
break; |
| 3290 |
case 2: |
| 3291 |
this.eraseLine(this.y); |
| 3292 |
break; |
| 3293 |
} |
| 3294 |
}; |
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
Terminal.prototype.charAttributes = function(params) { |
| 3359 |
|
| 3360 |
if (params.length === 1 && params[0] === 0) { |
| 3361 |
this.curAttr = this.defAttr; |
| 3362 |
return; |
| 3363 |
} |
| 3364 |
|
| 3365 |
var l = params.length |
| 3366 |
, i = 0 |
| 3367 |
, flags = this.curAttr >> 18 |
| 3368 |
, fg = (this.curAttr >> 9) & 0x1ff |
| 3369 |
, bg = this.curAttr & 0x1ff |
| 3370 |
, p; |
| 3371 |
|
| 3372 |
for (; i < l; i++) { |
| 3373 |
p = params[i]; |
| 3374 |
if (p >= 30 && p <= 37) { |
| 3375 |
|
| 3376 |
fg = p - 30; |
| 3377 |
} else if (p >= 40 && p <= 47) { |
| 3378 |
|
| 3379 |
bg = p - 40; |
| 3380 |
} else if (p >= 90 && p <= 97) { |
| 3381 |
|
| 3382 |
p += 8; |
| 3383 |
fg = p - 90; |
| 3384 |
} else if (p >= 100 && p <= 107) { |
| 3385 |
|
| 3386 |
p += 8; |
| 3387 |
bg = p - 100; |
| 3388 |
} else if (p === 0) { |
| 3389 |
|
| 3390 |
flags = this.defAttr >> 18; |
| 3391 |
fg = (this.defAttr >> 9) & 0x1ff; |
| 3392 |
bg = this.defAttr & 0x1ff; |
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
} else if (p === 1) { |
| 3397 |
|
| 3398 |
flags |= 1; |
| 3399 |
} else if (p === 4) { |
| 3400 |
|
| 3401 |
flags |= 2; |
| 3402 |
} else if (p === 5) { |
| 3403 |
|
| 3404 |
flags |= 4; |
| 3405 |
} else if (p === 7) { |
| 3406 |
|
| 3407 |
|
| 3408 |
flags |= 8; |
| 3409 |
} else if (p === 8) { |
| 3410 |
|
| 3411 |
flags |= 16; |
| 3412 |
} else if (p === 22) { |
| 3413 |
|
| 3414 |
flags &= ~1; |
| 3415 |
} else if (p === 24) { |
| 3416 |
|
| 3417 |
flags &= ~2; |
| 3418 |
} else if (p === 25) { |
| 3419 |
|
| 3420 |
flags &= ~4; |
| 3421 |
} else if (p === 27) { |
| 3422 |
|
| 3423 |
flags &= ~8; |
| 3424 |
} else if (p === 28) { |
| 3425 |
|
| 3426 |
flags &= ~16; |
| 3427 |
} else if (p === 39) { |
| 3428 |
|
| 3429 |
fg = (this.defAttr >> 9) & 0x1ff; |
| 3430 |
} else if (p === 49) { |
| 3431 |
|
| 3432 |
bg = this.defAttr & 0x1ff; |
| 3433 |
} else if (p === 38) { |
| 3434 |
|
| 3435 |
if (params[i + 1] === 2) { |
| 3436 |
i += 2; |
| 3437 |
fg = matchColor( |
| 3438 |
params[i] & 0xff, |
| 3439 |
params[i + 1] & 0xff, |
| 3440 |
params[i + 2] & 0xff); |
| 3441 |
if (fg === -1) fg = 0x1ff; |
| 3442 |
i += 2; |
| 3443 |
} else if (params[i + 1] === 5) { |
| 3444 |
i += 2; |
| 3445 |
p = params[i] & 0xff; |
| 3446 |
fg = p; |
| 3447 |
} |
| 3448 |
} else if (p === 48) { |
| 3449 |
|
| 3450 |
if (params[i + 1] === 2) { |
| 3451 |
i += 2; |
| 3452 |
bg = matchColor( |
| 3453 |
params[i] & 0xff, |
| 3454 |
params[i + 1] & 0xff, |
| 3455 |
params[i + 2] & 0xff); |
| 3456 |
if (bg === -1) bg = 0x1ff; |
| 3457 |
i += 2; |
| 3458 |
} else if (params[i + 1] === 5) { |
| 3459 |
i += 2; |
| 3460 |
p = params[i] & 0xff; |
| 3461 |
bg = p; |
| 3462 |
} |
| 3463 |
} else if (p === 100) { |
| 3464 |
|
| 3465 |
fg = (this.defAttr >> 9) & 0x1ff; |
| 3466 |
bg = this.defAttr & 0x1ff; |
| 3467 |
} else { |
| 3468 |
this.error('Unknown SGR attribute: %d.', p); |
| 3469 |
} |
| 3470 |
} |
| 3471 |
|
| 3472 |
this.curAttr = (flags << 18) | (fg << 9) | bg; |
| 3473 |
}; |
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
Terminal.prototype.deviceStatus = function(params) { |
| 3497 |
if (!this.prefix) { |
| 3498 |
switch (params[0]) { |
| 3499 |
case 5: |
| 3500 |
|
| 3501 |
this.send('\x1b[0n'); |
| 3502 |
break; |
| 3503 |
case 6: |
| 3504 |
|
| 3505 |
this.send('\x1b[' |
| 3506 |
+ (this.y + 1) |
| 3507 |
+ ';' |
| 3508 |
+ (this.x + 1) |
| 3509 |
+ 'R'); |
| 3510 |
break; |
| 3511 |
} |
| 3512 |
} else if (this.prefix === '?') { |
| 3513 |
|
| 3514 |
|
| 3515 |
switch (params[0]) { |
| 3516 |
case 6: |
| 3517 |
|
| 3518 |
this.send('\x1b[?' |
| 3519 |
+ (this.y + 1) |
| 3520 |
+ ';' |
| 3521 |
+ (this.x + 1) |
| 3522 |
+ 'R'); |
| 3523 |
break; |
| 3524 |
case 15: |
| 3525 |
|
| 3526 |
|
| 3527 |
break; |
| 3528 |
case 25: |
| 3529 |
|
| 3530 |
|
| 3531 |
break; |
| 3532 |
case 26: |
| 3533 |
|
| 3534 |
|
| 3535 |
break; |
| 3536 |
case 53: |
| 3537 |
|
| 3538 |
|
| 3539 |
break; |
| 3540 |
} |
| 3541 |
} |
| 3542 |
}; |
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
|
| 3550 |
Terminal.prototype.insertChars = function(params) { |
| 3551 |
var param, row, j, ch; |
| 3552 |
|
| 3553 |
param = params[0]; |
| 3554 |
if (param < 1) param = 1; |
| 3555 |
|
| 3556 |
row = this.y + this.ybase; |
| 3557 |
j = this.x; |
| 3558 |
ch = [this.eraseAttr(), ' ']; |
| 3559 |
|
| 3560 |
while (param-- && j < this.cols) { |
| 3561 |
this.lines[row].splice(j++, 0, ch); |
| 3562 |
this.lines[row].pop(); |
| 3563 |
} |
| 3564 |
}; |
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
Terminal.prototype.cursorNextLine = function(params) { |
| 3570 |
var param = params[0]; |
| 3571 |
if (param < 1) param = 1; |
| 3572 |
this.y += param; |
| 3573 |
if (this.y >= this.rows) { |
| 3574 |
this.y = this.rows - 1; |
| 3575 |
} |
| 3576 |
this.x = 0; |
| 3577 |
}; |
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
|
| 3582 |
Terminal.prototype.cursorPrecedingLine = function(params) { |
| 3583 |
var param = params[0]; |
| 3584 |
if (param < 1) param = 1; |
| 3585 |
this.y -= param; |
| 3586 |
if (this.y < 0) this.y = 0; |
| 3587 |
this.x = 0; |
| 3588 |
}; |
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
Terminal.prototype.cursorCharAbsolute = function(params) { |
| 3593 |
var param = params[0]; |
| 3594 |
if (param < 1) param = 1; |
| 3595 |
this.x = param - 1; |
| 3596 |
}; |
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
Terminal.prototype.insertLines = function(params) { |
| 3601 |
var param, row, j; |
| 3602 |
|
| 3603 |
param = params[0]; |
| 3604 |
if (param < 1) param = 1; |
| 3605 |
row = this.y + this.ybase; |
| 3606 |
|
| 3607 |
j = this.rows - 1 - this.scrollBottom; |
| 3608 |
j = this.rows - 1 + this.ybase - j + 1; |
| 3609 |
|
| 3610 |
while (param--) { |
| 3611 |
|
| 3612 |
|
| 3613 |
this.lines.splice(row, 0, this.blankLine(true)); |
| 3614 |
this.lines.splice(j, 1); |
| 3615 |
} |
| 3616 |
|
| 3617 |
|
| 3618 |
this.updateRange(this.y); |
| 3619 |
this.updateRange(this.scrollBottom); |
| 3620 |
}; |
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
Terminal.prototype.deleteLines = function(params) { |
| 3625 |
var param, row, j; |
| 3626 |
|
| 3627 |
param = params[0]; |
| 3628 |
if (param < 1) param = 1; |
| 3629 |
row = this.y + this.ybase; |
| 3630 |
|
| 3631 |
j = this.rows - 1 - this.scrollBottom; |
| 3632 |
j = this.rows - 1 + this.ybase - j; |
| 3633 |
|
| 3634 |
while (param--) { |
| 3635 |
|
| 3636 |
|
| 3637 |
this.lines.splice(j + 1, 0, this.blankLine(true)); |
| 3638 |
this.lines.splice(row, 1); |
| 3639 |
} |
| 3640 |
|
| 3641 |
|
| 3642 |
this.updateRange(this.y); |
| 3643 |
this.updateRange(this.scrollBottom); |
| 3644 |
}; |
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
Terminal.prototype.deleteChars = function(params) { |
| 3649 |
var param, row, ch; |
| 3650 |
|
| 3651 |
param = params[0]; |
| 3652 |
if (param < 1) param = 1; |
| 3653 |
|
| 3654 |
row = this.y + this.ybase; |
| 3655 |
ch = [this.eraseAttr(), ' ']; |
| 3656 |
|
| 3657 |
while (param--) { |
| 3658 |
this.lines[row].splice(this.x, 1); |
| 3659 |
this.lines[row].push(ch); |
| 3660 |
} |
| 3661 |
}; |
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
Terminal.prototype.eraseChars = function(params) { |
| 3666 |
var param, row, j, ch; |
| 3667 |
|
| 3668 |
param = params[0]; |
| 3669 |
if (param < 1) param = 1; |
| 3670 |
|
| 3671 |
row = this.y + this.ybase; |
| 3672 |
j = this.x; |
| 3673 |
ch = [this.eraseAttr(), ' ']; |
| 3674 |
|
| 3675 |
while (param-- && j < this.cols) { |
| 3676 |
this.lines[row][j++] = ch; |
| 3677 |
} |
| 3678 |
}; |
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
Terminal.prototype.charPosAbsolute = function(params) { |
| 3683 |
var param = params[0]; |
| 3684 |
if (param < 1) param = 1; |
| 3685 |
this.x = param - 1; |
| 3686 |
if (this.x >= this.cols) { |
| 3687 |
this.x = this.cols - 1; |
| 3688 |
} |
| 3689 |
}; |
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
Terminal.prototype.HPositionRelative = function(params) { |
| 3695 |
var param = params[0]; |
| 3696 |
if (param < 1) param = 1; |
| 3697 |
this.x += param; |
| 3698 |
if (this.x >= this.cols) { |
| 3699 |
this.x = this.cols - 1; |
| 3700 |
} |
| 3701 |
}; |
| 3702 |
|
| 3703 |
|
| 3704 |
|
| 3705 |
|
| 3706 |
|
| 3707 |
|
| 3708 |
|
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
|
| 3713 |
|
| 3714 |
|
| 3715 |
|
| 3716 |
|
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
Terminal.prototype.sendDeviceAttributes = function(params) { |
| 3739 |
if (params[0] > 0) return; |
| 3740 |
|
| 3741 |
if (!this.prefix) { |
| 3742 |
if (this.is('xterm') |
| 3743 |
|| this.is('rxvt-unicode') |
| 3744 |
|| this.is('screen')) { |
| 3745 |
this.send('\x1b[?1;2c'); |
| 3746 |
} else if (this.is('linux')) { |
| 3747 |
this.send('\x1b[?6c'); |
| 3748 |
} |
| 3749 |
} else if (this.prefix === '>') { |
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
if (this.is('xterm')) { |
| 3754 |
this.send('\x1b[>0;276;0c'); |
| 3755 |
} else if (this.is('rxvt-unicode')) { |
| 3756 |
this.send('\x1b[>85;95;0c'); |
| 3757 |
} else if (this.is('linux')) { |
| 3758 |
|
| 3759 |
|
| 3760 |
this.send(params[0] + 'c'); |
| 3761 |
} else if (this.is('screen')) { |
| 3762 |
this.send('\x1b[>83;40003;0c'); |
| 3763 |
} |
| 3764 |
} |
| 3765 |
}; |
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
Terminal.prototype.linePosAbsolute = function(params) { |
| 3770 |
var param = params[0]; |
| 3771 |
if (param < 1) param = 1; |
| 3772 |
this.y = param - 1; |
| 3773 |
if (this.y >= this.rows) { |
| 3774 |
this.y = this.rows - 1; |
| 3775 |
} |
| 3776 |
}; |
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
Terminal.prototype.VPositionRelative = function(params) { |
| 3781 |
var param = params[0]; |
| 3782 |
if (param < 1) param = 1; |
| 3783 |
this.y += param; |
| 3784 |
if (this.y >= this.rows) { |
| 3785 |
this.y = this.rows - 1; |
| 3786 |
} |
| 3787 |
}; |
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
Terminal.prototype.HVPosition = function(params) { |
| 3793 |
if (params[0] < 1) params[0] = 1; |
| 3794 |
if (params[1] < 1) params[1] = 1; |
| 3795 |
|
| 3796 |
this.y = params[0] - 1; |
| 3797 |
if (this.y >= this.rows) { |
| 3798 |
this.y = this.rows - 1; |
| 3799 |
} |
| 3800 |
|
| 3801 |
this.x = params[1] - 1; |
| 3802 |
if (this.x >= this.cols) { |
| 3803 |
this.x = this.cols - 1; |
| 3804 |
} |
| 3805 |
}; |
| 3806 |
|
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
|
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
|
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
|
| 3891 |
Terminal.prototype.setMode = function(params) { |
| 3892 |
if (typeof params === 'object') { |
| 3893 |
var l = params.length |
| 3894 |
, i = 0; |
| 3895 |
|
| 3896 |
for (; i < l; i++) { |
| 3897 |
this.setMode(params[i]); |
| 3898 |
} |
| 3899 |
|
| 3900 |
return; |
| 3901 |
} |
| 3902 |
|
| 3903 |
if (!this.prefix) { |
| 3904 |
switch (params) { |
| 3905 |
case 4: |
| 3906 |
this.insertMode = true; |
| 3907 |
break; |
| 3908 |
case 20: |
| 3909 |
|
| 3910 |
break; |
| 3911 |
} |
| 3912 |
} else if (this.prefix === '?') { |
| 3913 |
switch (params) { |
| 3914 |
case 1: |
| 3915 |
this.applicationCursor = true; |
| 3916 |
break; |
| 3917 |
case 2: |
| 3918 |
this.setgCharset(0, Terminal.charsets.US); |
| 3919 |
this.setgCharset(1, Terminal.charsets.US); |
| 3920 |
this.setgCharset(2, Terminal.charsets.US); |
| 3921 |
this.setgCharset(3, Terminal.charsets.US); |
| 3922 |
|
| 3923 |
break; |
| 3924 |
case 3: |
| 3925 |
this.savedCols = this.cols; |
| 3926 |
this.resize(132, this.rows); |
| 3927 |
break; |
| 3928 |
case 6: |
| 3929 |
this.originMode = true; |
| 3930 |
break; |
| 3931 |
case 7: |
| 3932 |
this.wraparoundMode = true; |
| 3933 |
break; |
| 3934 |
case 12: |
| 3935 |
|
| 3936 |
break; |
| 3937 |
case 66: |
| 3938 |
this.log('Serial port requested application keypad.'); |
| 3939 |
this.applicationKeypad = true; |
| 3940 |
break; |
| 3941 |
case 9: |
| 3942 |
|
| 3943 |
case 1000: |
| 3944 |
|
| 3945 |
|
| 3946 |
case 1002: |
| 3947 |
case 1003: |
| 3948 |
|
| 3949 |
|
| 3950 |
this.x10Mouse = params === 9; |
| 3951 |
this.vt200Mouse = params === 1000; |
| 3952 |
this.normalMouse = params > 1000; |
| 3953 |
this.mouseEvents = true; |
| 3954 |
this.element.style.cursor = 'default'; |
| 3955 |
this.log('Binding to mouse events.'); |
| 3956 |
break; |
| 3957 |
case 1004: |
| 3958 |
|
| 3959 |
|
| 3960 |
this.sendFocus = true; |
| 3961 |
break; |
| 3962 |
case 1005: |
| 3963 |
this.utfMouse = true; |
| 3964 |
|
| 3965 |
|
| 3966 |
break; |
| 3967 |
case 1006: |
| 3968 |
this.sgrMouse = true; |
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
break; |
| 3974 |
case 1015: |
| 3975 |
this.urxvtMouse = true; |
| 3976 |
|
| 3977 |
|
| 3978 |
|
| 3979 |
|
| 3980 |
break; |
| 3981 |
case 25: |
| 3982 |
this.cursorHidden = false; |
| 3983 |
break; |
| 3984 |
case 1049: |
| 3985 |
|
| 3986 |
; |
| 3987 |
case 47: |
| 3988 |
case 1047: |
| 3989 |
if (!this.normal) { |
| 3990 |
var normal = { |
| 3991 |
lines: this.lines, |
| 3992 |
ybase: this.ybase, |
| 3993 |
ydisp: this.ydisp, |
| 3994 |
x: this.x, |
| 3995 |
y: this.y, |
| 3996 |
scrollTop: this.scrollTop, |
| 3997 |
scrollBottom: this.scrollBottom, |
| 3998 |
tabs: this.tabs |
| 3999 |
|
| 4000 |
|
| 4001 |
|
| 4002 |
|
| 4003 |
}; |
| 4004 |
this.reset(); |
| 4005 |
this.normal = normal; |
| 4006 |
this.showCursor(); |
| 4007 |
} |
| 4008 |
break; |
| 4009 |
} |
| 4010 |
} |
| 4011 |
}; |
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
|
| 4034 |
|
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
Terminal.prototype.resetMode = function(params) { |
| 4094 |
if (typeof params === 'object') { |
| 4095 |
var l = params.length |
| 4096 |
, i = 0; |
| 4097 |
|
| 4098 |
for (; i < l; i++) { |
| 4099 |
this.resetMode(params[i]); |
| 4100 |
} |
| 4101 |
|
| 4102 |
return; |
| 4103 |
} |
| 4104 |
|
| 4105 |
if (!this.prefix) { |
| 4106 |
switch (params) { |
| 4107 |
case 4: |
| 4108 |
this.insertMode = false; |
| 4109 |
break; |
| 4110 |
case 20: |
| 4111 |
|
| 4112 |
break; |
| 4113 |
} |
| 4114 |
} else if (this.prefix === '?') { |
| 4115 |
switch (params) { |
| 4116 |
case 1: |
| 4117 |
this.applicationCursor = false; |
| 4118 |
break; |
| 4119 |
case 3: |
| 4120 |
if (this.cols === 132 && this.savedCols) { |
| 4121 |
this.resize(this.savedCols, this.rows); |
| 4122 |
} |
| 4123 |
delete this.savedCols; |
| 4124 |
break; |
| 4125 |
case 6: |
| 4126 |
this.originMode = false; |
| 4127 |
break; |
| 4128 |
case 7: |
| 4129 |
this.wraparoundMode = false; |
| 4130 |
break; |
| 4131 |
case 12: |
| 4132 |
|
| 4133 |
break; |
| 4134 |
case 66: |
| 4135 |
this.log('Switching back to normal keypad.'); |
| 4136 |
this.applicationKeypad = false; |
| 4137 |
break; |
| 4138 |
case 9: |
| 4139 |
case 1000: |
| 4140 |
case 1002: |
| 4141 |
case 1003: |
| 4142 |
this.x10Mouse = false; |
| 4143 |
this.vt200Mouse = false; |
| 4144 |
this.normalMouse = false; |
| 4145 |
this.mouseEvents = false; |
| 4146 |
this.element.style.cursor = ''; |
| 4147 |
break; |
| 4148 |
case 1004: |
| 4149 |
this.sendFocus = false; |
| 4150 |
break; |
| 4151 |
case 1005: |
| 4152 |
this.utfMouse = false; |
| 4153 |
break; |
| 4154 |
case 1006: |
| 4155 |
this.sgrMouse = false; |
| 4156 |
break; |
| 4157 |
case 1015: |
| 4158 |
this.urxvtMouse = false; |
| 4159 |
break; |
| 4160 |
case 25: |
| 4161 |
this.cursorHidden = true; |
| 4162 |
break; |
| 4163 |
case 1049: |
| 4164 |
; |
| 4165 |
case 47: |
| 4166 |
case 1047: |
| 4167 |
if (this.normal) { |
| 4168 |
this.lines = this.normal.lines; |
| 4169 |
this.ybase = this.normal.ybase; |
| 4170 |
this.ydisp = this.normal.ydisp; |
| 4171 |
this.x = this.normal.x; |
| 4172 |
this.y = this.normal.y; |
| 4173 |
this.scrollTop = this.normal.scrollTop; |
| 4174 |
this.scrollBottom = this.normal.scrollBottom; |
| 4175 |
this.tabs = this.normal.tabs; |
| 4176 |
this.normal = null; |
| 4177 |
|
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
this.refresh(0, this.rows - 1); |
| 4182 |
this.showCursor(); |
| 4183 |
} |
| 4184 |
break; |
| 4185 |
} |
| 4186 |
} |
| 4187 |
}; |
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
Terminal.prototype.setScrollRegion = function(params) { |
| 4194 |
if (this.prefix) return; |
| 4195 |
this.scrollTop = (params[0] || 1) - 1; |
| 4196 |
this.scrollBottom = (params[1] || this.rows) - 1; |
| 4197 |
this.x = 0; |
| 4198 |
this.y = 0; |
| 4199 |
}; |
| 4200 |
|
| 4201 |
|
| 4202 |
|
| 4203 |
Terminal.prototype.saveCursor = function(params) { |
| 4204 |
this.savedX = this.x; |
| 4205 |
this.savedY = this.y; |
| 4206 |
}; |
| 4207 |
|
| 4208 |
|
| 4209 |
|
| 4210 |
Terminal.prototype.restoreCursor = function(params) { |
| 4211 |
this.x = this.savedX || 0; |
| 4212 |
this.y = this.savedY || 0; |
| 4213 |
}; |
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
Terminal.prototype.cursorForwardTab = function(params) { |
| 4222 |
var param = params[0] || 1; |
| 4223 |
while (param--) { |
| 4224 |
this.x = this.nextStop(); |
| 4225 |
} |
| 4226 |
}; |
| 4227 |
|
| 4228 |
|
| 4229 |
Terminal.prototype.scrollUp = function(params) { |
| 4230 |
var param = params[0] || 1; |
| 4231 |
while (param--) { |
| 4232 |
this.lines.splice(this.ybase + this.scrollTop, 1); |
| 4233 |
this.lines.splice(this.ybase + this.scrollBottom, 0, this.blankLine()); |
| 4234 |
} |
| 4235 |
|
| 4236 |
this.updateRange(this.scrollTop); |
| 4237 |
this.updateRange(this.scrollBottom); |
| 4238 |
}; |
| 4239 |
|
| 4240 |
|
| 4241 |
Terminal.prototype.scrollDown = function(params) { |
| 4242 |
var param = params[0] || 1; |
| 4243 |
while (param--) { |
| 4244 |
this.lines.splice(this.ybase + this.scrollBottom, 1); |
| 4245 |
this.lines.splice(this.ybase + this.scrollTop, 0, this.blankLine()); |
| 4246 |
} |
| 4247 |
|
| 4248 |
this.updateRange(this.scrollTop); |
| 4249 |
this.updateRange(this.scrollBottom); |
| 4250 |
}; |
| 4251 |
|
| 4252 |
|
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
Terminal.prototype.initMouseTracking = function(params) { |
| 4257 |
|
| 4258 |
}; |
| 4259 |
|
| 4260 |
|
| 4261 |
|
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
Terminal.prototype.resetTitleModes = function(params) { |
| 4272 |
; |
| 4273 |
}; |
| 4274 |
|
| 4275 |
|
| 4276 |
Terminal.prototype.cursorBackwardTab = function(params) { |
| 4277 |
var param = params[0] || 1; |
| 4278 |
while (param--) { |
| 4279 |
this.x = this.prevStop(); |
| 4280 |
} |
| 4281 |
}; |
| 4282 |
|
| 4283 |
|
| 4284 |
Terminal.prototype.repeatPrecedingCharacter = function(params) { |
| 4285 |
var param = params[0] || 1 |
| 4286 |
, line = this.lines[this.ybase + this.y] |
| 4287 |
, ch = line[this.x - 1] || [this.defAttr, ' ']; |
| 4288 |
|
| 4289 |
while (param--) line[this.x++] = ch; |
| 4290 |
}; |
| 4291 |
|
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
Terminal.prototype.tabClear = function(params) { |
| 4299 |
var param = params[0]; |
| 4300 |
if (param <= 0) { |
| 4301 |
delete this.tabs[this.x]; |
| 4302 |
} else if (param === 3) { |
| 4303 |
this.tabs = {}; |
| 4304 |
} |
| 4305 |
}; |
| 4306 |
|
| 4307 |
|
| 4308 |
|
| 4309 |
|
| 4310 |
|
| 4311 |
|
| 4312 |
|
| 4313 |
|
| 4314 |
|
| 4315 |
|
| 4316 |
|
| 4317 |
|
| 4318 |
Terminal.prototype.mediaCopy = function(params) { |
| 4319 |
; |
| 4320 |
}; |
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
|
| 4325 |
|
| 4326 |
|
| 4327 |
|
| 4328 |
|
| 4329 |
|
| 4330 |
|
| 4331 |
|
| 4332 |
|
| 4333 |
|
| 4334 |
Terminal.prototype.setResources = function(params) { |
| 4335 |
; |
| 4336 |
}; |
| 4337 |
|
| 4338 |
|
| 4339 |
|
| 4340 |
|
| 4341 |
|
| 4342 |
|
| 4343 |
|
| 4344 |
|
| 4345 |
|
| 4346 |
|
| 4347 |
|
| 4348 |
|
| 4349 |
|
| 4350 |
|
| 4351 |
Terminal.prototype.disableModifiers = function(params) { |
| 4352 |
; |
| 4353 |
}; |
| 4354 |
|
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
|
| 4361 |
|
| 4362 |
|
| 4363 |
Terminal.prototype.setPointerMode = function(params) { |
| 4364 |
; |
| 4365 |
}; |
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
Terminal.prototype.softReset = function(params) { |
| 4370 |
this.cursorHidden = false; |
| 4371 |
this.insertMode = false; |
| 4372 |
this.originMode = false; |
| 4373 |
this.wraparoundMode = false; |
| 4374 |
this.applicationKeypad = false; |
| 4375 |
this.applicationCursor = false; |
| 4376 |
this.scrollTop = 0; |
| 4377 |
this.scrollBottom = this.rows - 1; |
| 4378 |
this.curAttr = this.defAttr; |
| 4379 |
this.x = this.y = 0; |
| 4380 |
this.charset = null; |
| 4381 |
this.glevel = 0; |
| 4382 |
this.charsets = [null]; |
| 4383 |
}; |
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
|
| 4389 |
|
| 4390 |
|
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
Terminal.prototype.requestAnsiMode = function(params) { |
| 4396 |
; |
| 4397 |
}; |
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
Terminal.prototype.requestPrivateMode = function(params) { |
| 4405 |
; |
| 4406 |
}; |
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
Terminal.prototype.setConformanceLevel = function(params) { |
| 4419 |
; |
| 4420 |
}; |
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
|
| 4430 |
Terminal.prototype.loadLEDs = function(params) { |
| 4431 |
; |
| 4432 |
}; |
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
Terminal.prototype.setCursorStyle = function(params) { |
| 4442 |
; |
| 4443 |
}; |
| 4444 |
|
| 4445 |
|
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
Terminal.prototype.setCharProtectionAttr = function(params) { |
| 4452 |
; |
| 4453 |
}; |
| 4454 |
|
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
Terminal.prototype.restorePrivateValues = function(params) { |
| 4459 |
; |
| 4460 |
}; |
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
|
| 4465 |
|
| 4466 |
|
| 4467 |
Terminal.prototype.setAttrInRectangle = function(params) { |
| 4468 |
var t = params[0] |
| 4469 |
, l = params[1] |
| 4470 |
, b = params[2] |
| 4471 |
, r = params[3] |
| 4472 |
, attr = params[4]; |
| 4473 |
|
| 4474 |
var line |
| 4475 |
, i; |
| 4476 |
|
| 4477 |
for (; t < b + 1; t++) { |
| 4478 |
line = this.lines[this.ybase + t]; |
| 4479 |
for (i = l; i < r; i++) { |
| 4480 |
line[i] = [attr, line[i][1]]; |
| 4481 |
} |
| 4482 |
} |
| 4483 |
|
| 4484 |
|
| 4485 |
this.updateRange(params[0]); |
| 4486 |
this.updateRange(params[2]); |
| 4487 |
}; |
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
Terminal.prototype.savePrivateValues = function(params) { |
| 4493 |
; |
| 4494 |
}; |
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
|
| 4504 |
|
| 4505 |
|
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
|
| 4515 |
|
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
|
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
|
| 4526 |
|
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
|
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
|
| 4540 |
|
| 4541 |
|
| 4542 |
Terminal.prototype.manipulateWindow = function(params) { |
| 4543 |
; |
| 4544 |
}; |
| 4545 |
|
| 4546 |
|
| 4547 |
|
| 4548 |
|
| 4549 |
|
| 4550 |
|
| 4551 |
|
| 4552 |
Terminal.prototype.reverseAttrInRectangle = function(params) { |
| 4553 |
; |
| 4554 |
}; |
| 4555 |
|
| 4556 |
|
| 4557 |
|
| 4558 |
|
| 4559 |
|
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
Terminal.prototype.setTitleModeFeature = function(params) { |
| 4565 |
; |
| 4566 |
}; |
| 4567 |
|
| 4568 |
|
| 4569 |
|
| 4570 |
|
| 4571 |
|
| 4572 |
|
| 4573 |
Terminal.prototype.setWarningBellVolume = function(params) { |
| 4574 |
; |
| 4575 |
}; |
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
Terminal.prototype.setMarginBellVolume = function(params) { |
| 4583 |
; |
| 4584 |
}; |
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
Terminal.prototype.copyRectangle = function(params) { |
| 4594 |
; |
| 4595 |
}; |
| 4596 |
|
| 4597 |
|
| 4598 |
|
| 4599 |
|
| 4600 |
|
| 4601 |
|
| 4602 |
|
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
Terminal.prototype.enableFilterRectangle = function(params) { |
| 4609 |
; |
| 4610 |
}; |
| 4611 |
|
| 4612 |
|
| 4613 |
|
| 4614 |
|
| 4615 |
|
| 4616 |
|
| 4617 |
|
| 4618 |
|
| 4619 |
|
| 4620 |
|
| 4621 |
|
| 4622 |
|
| 4623 |
Terminal.prototype.requestParameters = function(params) { |
| 4624 |
; |
| 4625 |
}; |
| 4626 |
|
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
Terminal.prototype.selectChangeExtent = function(params) { |
| 4632 |
; |
| 4633 |
}; |
| 4634 |
|
| 4635 |
|
| 4636 |
|
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
Terminal.prototype.fillRectangle = function(params) { |
| 4641 |
var ch = params[0] |
| 4642 |
, t = params[1] |
| 4643 |
, l = params[2] |
| 4644 |
, b = params[3] |
| 4645 |
, r = params[4]; |
| 4646 |
|
| 4647 |
var line |
| 4648 |
, i; |
| 4649 |
|
| 4650 |
for (; t < b + 1; t++) { |
| 4651 |
line = this.lines[this.ybase + t]; |
| 4652 |
for (i = l; i < r; i++) { |
| 4653 |
line[i] = [line[i][0], String.fromCharCode(ch)]; |
| 4654 |
} |
| 4655 |
} |
| 4656 |
|
| 4657 |
|
| 4658 |
this.updateRange(params[1]); |
| 4659 |
this.updateRange(params[3]); |
| 4660 |
}; |
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
|
| 4665 |
|
| 4666 |
|
| 4667 |
|
| 4668 |
|
| 4669 |
|
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
Terminal.prototype.enableLocatorReporting = function(params) { |
| 4675 |
var val = params[0] > 0; |
| 4676 |
|
| 4677 |
|
| 4678 |
}; |
| 4679 |
|
| 4680 |
|
| 4681 |
|
| 4682 |
|
| 4683 |
|
| 4684 |
Terminal.prototype.eraseRectangle = function(params) { |
| 4685 |
var t = params[0] |
| 4686 |
, l = params[1] |
| 4687 |
, b = params[2] |
| 4688 |
, r = params[3]; |
| 4689 |
|
| 4690 |
var line |
| 4691 |
, i |
| 4692 |
, ch; |
| 4693 |
|
| 4694 |
ch = [this.eraseAttr(), ' ']; |
| 4695 |
|
| 4696 |
for (; t < b + 1; t++) { |
| 4697 |
line = this.lines[this.ybase + t]; |
| 4698 |
for (i = l; i < r; i++) { |
| 4699 |
line[i] = ch; |
| 4700 |
} |
| 4701 |
} |
| 4702 |
|
| 4703 |
|
| 4704 |
this.updateRange(params[0]); |
| 4705 |
this.updateRange(params[2]); |
| 4706 |
}; |
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
Terminal.prototype.setLocatorEvents = function(params) { |
| 4720 |
; |
| 4721 |
}; |
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
Terminal.prototype.selectiveEraseRectangle = function(params) { |
| 4727 |
; |
| 4728 |
}; |
| 4729 |
|
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
|
| 4735 |
|
| 4736 |
|
| 4737 |
|
| 4738 |
|
| 4739 |
|
| 4740 |
|
| 4741 |
|
| 4742 |
|
| 4743 |
|
| 4744 |
|
| 4745 |
|
| 4746 |
|
| 4747 |
|
| 4748 |
|
| 4749 |
|
| 4750 |
|
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
|
| 4757 |
|
| 4758 |
|
| 4759 |
|
| 4760 |
|
| 4761 |
|
| 4762 |
|
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
|
| 4768 |
|
| 4769 |
|
| 4770 |
Terminal.prototype.requestLocatorPosition = function(params) { |
| 4771 |
; |
| 4772 |
}; |
| 4773 |
|
| 4774 |
|
| 4775 |
|
| 4776 |
|
| 4777 |
Terminal.prototype.insertColumns = function() { |
| 4778 |
var param = params[0] |
| 4779 |
, l = this.ybase + this.rows |
| 4780 |
, ch = [this.eraseAttr(), ' '] |
| 4781 |
, i; |
| 4782 |
|
| 4783 |
while (param--) { |
| 4784 |
for (i = this.ybase; i < l; i++) { |
| 4785 |
this.lines[i].splice(this.x + 1, 0, ch); |
| 4786 |
this.lines[i].pop(); |
| 4787 |
} |
| 4788 |
} |
| 4789 |
|
| 4790 |
this.maxRange(); |
| 4791 |
}; |
| 4792 |
|
| 4793 |
|
| 4794 |
|
| 4795 |
|
| 4796 |
Terminal.prototype.deleteColumns = function() { |
| 4797 |
var param = params[0] |
| 4798 |
, l = this.ybase + this.rows |
| 4799 |
, ch = [this.eraseAttr(), ' '] |
| 4800 |
, i; |
| 4801 |
|
| 4802 |
while (param--) { |
| 4803 |
for (i = this.ybase; i < l; i++) { |
| 4804 |
this.lines[i].splice(this.x, 1); |
| 4805 |
this.lines[i].push(ch); |
| 4806 |
} |
| 4807 |
} |
| 4808 |
|
| 4809 |
this.maxRange(); |
| 4810 |
}; |
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
Terminal.prototype.enterPrefix = function() { |
| 4817 |
this.prefixMode = true; |
| 4818 |
}; |
| 4819 |
|
| 4820 |
Terminal.prototype.leavePrefix = function() { |
| 4821 |
this.prefixMode = false; |
| 4822 |
}; |
| 4823 |
|
| 4824 |
Terminal.prototype.enterSelect = function() { |
| 4825 |
this._real = { |
| 4826 |
x: this.x, |
| 4827 |
y: this.y, |
| 4828 |
ydisp: this.ydisp, |
| 4829 |
ybase: this.ybase, |
| 4830 |
cursorHidden: this.cursorHidden, |
| 4831 |
lines: this.copyBuffer(this.lines), |
| 4832 |
write: this.write |
| 4833 |
}; |
| 4834 |
this.write = function() {}; |
| 4835 |
this.selectMode = true; |
| 4836 |
this.visualMode = false; |
| 4837 |
this.cursorHidden = false; |
| 4838 |
this.refresh(this.y, this.y); |
| 4839 |
}; |
| 4840 |
|
| 4841 |
Terminal.prototype.leaveSelect = function() { |
| 4842 |
this.x = this._real.x; |
| 4843 |
this.y = this._real.y; |
| 4844 |
this.ydisp = this._real.ydisp; |
| 4845 |
this.ybase = this._real.ybase; |
| 4846 |
this.cursorHidden = this._real.cursorHidden; |
| 4847 |
this.lines = this._real.lines; |
| 4848 |
this.write = this._real.write; |
| 4849 |
delete this._real; |
| 4850 |
this.selectMode = false; |
| 4851 |
this.visualMode = false; |
| 4852 |
this.refresh(0, this.rows - 1); |
| 4853 |
}; |
| 4854 |
|
| 4855 |
Terminal.prototype.enterVisual = function() { |
| 4856 |
this._real.preVisual = this.copyBuffer(this.lines); |
| 4857 |
this.selectText(this.x, this.x, this.ydisp + this.y, this.ydisp + this.y); |
| 4858 |
this.visualMode = true; |
| 4859 |
}; |
| 4860 |
|
| 4861 |
Terminal.prototype.leaveVisual = function() { |
| 4862 |
this.lines = this._real.preVisual; |
| 4863 |
delete this._real.preVisual; |
| 4864 |
delete this._selected; |
| 4865 |
this.visualMode = false; |
| 4866 |
this.refresh(0, this.rows - 1); |
| 4867 |
}; |
| 4868 |
|
| 4869 |
Terminal.prototype.enterSearch = function(down) { |
| 4870 |
this.entry = ''; |
| 4871 |
this.searchMode = true; |
| 4872 |
this.searchDown = down; |
| 4873 |
this._real.preSearch = this.copyBuffer(this.lines); |
| 4874 |
this._real.preSearchX = this.x; |
| 4875 |
this._real.preSearchY = this.y; |
| 4876 |
|
| 4877 |
var bottom = this.ydisp + this.rows - 1; |
| 4878 |
for (var i = 0; i < this.entryPrefix.length; i++) { |
| 4879 |
|
| 4880 |
|
| 4881 |
this.lines[bottom][i] = [ |
| 4882 |
(this.defAttr & ~0x1ff) | 4, |
| 4883 |
this.entryPrefix[i] |
| 4884 |
]; |
| 4885 |
} |
| 4886 |
|
| 4887 |
this.y = this.rows - 1; |
| 4888 |
this.x = this.entryPrefix.length; |
| 4889 |
|
| 4890 |
this.refresh(this.rows - 1, this.rows - 1); |
| 4891 |
}; |
| 4892 |
|
| 4893 |
Terminal.prototype.leaveSearch = function() { |
| 4894 |
this.searchMode = false; |
| 4895 |
|
| 4896 |
if (this._real.preSearch) { |
| 4897 |
this.lines = this._real.preSearch; |
| 4898 |
this.x = this._real.preSearchX; |
| 4899 |
this.y = this._real.preSearchY; |
| 4900 |
delete this._real.preSearch; |
| 4901 |
delete this._real.preSearchX; |
| 4902 |
delete this._real.preSearchY; |
| 4903 |
} |
| 4904 |
|
| 4905 |
this.refresh(this.rows - 1, this.rows - 1); |
| 4906 |
}; |
| 4907 |
|
| 4908 |
Terminal.prototype.copyBuffer = function(lines) { |
| 4909 |
var lines = lines || this.lines |
| 4910 |
, out = []; |
| 4911 |
|
| 4912 |
for (var y = 0; y < lines.length; y++) { |
| 4913 |
out[y] = []; |
| 4914 |
for (var x = 0; x < lines[y].length; x++) { |
| 4915 |
out[y][x] = [lines[y][x][0], lines[y][x][1]]; |
| 4916 |
} |
| 4917 |
} |
| 4918 |
|
| 4919 |
return out; |
| 4920 |
}; |
| 4921 |
|
| 4922 |
Terminal.prototype.getCopyTextarea = function(text) { |
| 4923 |
var textarea = this._copyTextarea |
| 4924 |
, document = this.document; |
| 4925 |
|
| 4926 |
if (!textarea) { |
| 4927 |
textarea = document.createElement('textarea'); |
| 4928 |
textarea.style.position = 'absolute'; |
| 4929 |
textarea.style.left = '-32000px'; |
| 4930 |
textarea.style.top = '-32000px'; |
| 4931 |
textarea.style.width = '0px'; |
| 4932 |
textarea.style.height = '0px'; |
| 4933 |
textarea.style.opacity = '0'; |
| 4934 |
textarea.style.backgroundColor = 'transparent'; |
| 4935 |
textarea.style.borderStyle = 'none'; |
| 4936 |
textarea.style.outlineStyle = 'none'; |
| 4937 |
|
| 4938 |
document.getElementsByTagName('body')[0].appendChild(textarea); |
| 4939 |
|
| 4940 |
this._copyTextarea = textarea; |
| 4941 |
} |
| 4942 |
|
| 4943 |
return textarea; |
| 4944 |
}; |
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
Terminal.prototype.copyText = function(text) { |
| 4949 |
var self = this |
| 4950 |
, textarea = this.getCopyTextarea(); |
| 4951 |
|
| 4952 |
this.emit('copy', text); |
| 4953 |
|
| 4954 |
textarea.focus(); |
| 4955 |
textarea.textContent = text; |
| 4956 |
textarea.value = text; |
| 4957 |
textarea.setSelectionRange(0, text.length); |
| 4958 |
|
| 4959 |
setTimeout(function() { |
| 4960 |
self.element.focus(); |
| 4961 |
self.focus(); |
| 4962 |
}, 1); |
| 4963 |
}; |
| 4964 |
|
| 4965 |
Terminal.prototype.selectText = function(x1, x2, y1, y2) { |
| 4966 |
var ox1 |
| 4967 |
, ox2 |
| 4968 |
, oy1 |
| 4969 |
, oy2 |
| 4970 |
, tmp |
| 4971 |
, x |
| 4972 |
, y |
| 4973 |
, xl |
| 4974 |
, attr; |
| 4975 |
|
| 4976 |
if (this._selected) { |
| 4977 |
ox1 = this._selected.x1; |
| 4978 |
ox2 = this._selected.x2; |
| 4979 |
oy1 = this._selected.y1; |
| 4980 |
oy2 = this._selected.y2; |
| 4981 |
|
| 4982 |
if (oy2 < oy1) { |
| 4983 |
tmp = ox2; |
| 4984 |
ox2 = ox1; |
| 4985 |
ox1 = tmp; |
| 4986 |
tmp = oy2; |
| 4987 |
oy2 = oy1; |
| 4988 |
oy1 = tmp; |
| 4989 |
} |
| 4990 |
|
| 4991 |
if (ox2 < ox1 && oy1 === oy2) { |
| 4992 |
tmp = ox2; |
| 4993 |
ox2 = ox1; |
| 4994 |
ox1 = tmp; |
| 4995 |
} |
| 4996 |
|
| 4997 |
for (y = oy1; y <= oy2; y++) { |
| 4998 |
x = 0; |
| 4999 |
xl = this.cols - 1; |
| 5000 |
if (y === oy1) { |
| 5001 |
x = ox1; |
| 5002 |
} |
| 5003 |
if (y === oy2) { |
| 5004 |
xl = ox2; |
| 5005 |
} |
| 5006 |
for (; x <= xl; x++) { |
| 5007 |
if (this.lines[y][x].old != null) { |
| 5008 |
|
| 5009 |
|
| 5010 |
attr = this.lines[y][x].old; |
| 5011 |
delete this.lines[y][x].old; |
| 5012 |
this.lines[y][x] = [attr, this.lines[y][x][1]]; |
| 5013 |
} |
| 5014 |
} |
| 5015 |
} |
| 5016 |
|
| 5017 |
y1 = this._selected.y1; |
| 5018 |
x1 = this._selected.x1; |
| 5019 |
} |
| 5020 |
|
| 5021 |
y1 = Math.max(y1, 0); |
| 5022 |
y1 = Math.min(y1, this.ydisp + this.rows - 1); |
| 5023 |
|
| 5024 |
y2 = Math.max(y2, 0); |
| 5025 |
y2 = Math.min(y2, this.ydisp + this.rows - 1); |
| 5026 |
|
| 5027 |
this._selected = { x1: x1, x2: x2, y1: y1, y2: y2 }; |
| 5028 |
|
| 5029 |
if (y2 < y1) { |
| 5030 |
tmp = x2; |
| 5031 |
x2 = x1; |
| 5032 |
x1 = tmp; |
| 5033 |
tmp = y2; |
| 5034 |
y2 = y1; |
| 5035 |
y1 = tmp; |
| 5036 |
} |
| 5037 |
|
| 5038 |
if (x2 < x1 && y1 === y2) { |
| 5039 |
tmp = x2; |
| 5040 |
x2 = x1; |
| 5041 |
x1 = tmp; |
| 5042 |
} |
| 5043 |
|
| 5044 |
for (y = y1; y <= y2; y++) { |
| 5045 |
x = 0; |
| 5046 |
xl = this.cols - 1; |
| 5047 |
if (y === y1) { |
| 5048 |
x = x1; |
| 5049 |
} |
| 5050 |
if (y === y2) { |
| 5051 |
xl = x2; |
| 5052 |
} |
| 5053 |
for (; x <= xl; x++) { |
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
attr = this.lines[y][x][0]; |
| 5058 |
this.lines[y][x] = [ |
| 5059 |
(attr & ~0x1ff) | ((0x1ff << 9) | 4), |
| 5060 |
this.lines[y][x][1] |
| 5061 |
]; |
| 5062 |
this.lines[y][x].old = attr; |
| 5063 |
} |
| 5064 |
} |
| 5065 |
|
| 5066 |
y1 = y1 - this.ydisp; |
| 5067 |
y2 = y2 - this.ydisp; |
| 5068 |
|
| 5069 |
y1 = Math.max(y1, 0); |
| 5070 |
y1 = Math.min(y1, this.rows - 1); |
| 5071 |
|
| 5072 |
y2 = Math.max(y2, 0); |
| 5073 |
y2 = Math.min(y2, this.rows - 1); |
| 5074 |
|
| 5075 |
|
| 5076 |
this.refresh(0, this.rows - 1); |
| 5077 |
}; |
| 5078 |
|
| 5079 |
Terminal.prototype.grabText = function(x1, x2, y1, y2) { |
| 5080 |
var out = '' |
| 5081 |
, buf = '' |
| 5082 |
, ch |
| 5083 |
, x |
| 5084 |
, y |
| 5085 |
, xl |
| 5086 |
, tmp; |
| 5087 |
|
| 5088 |
if (y2 < y1) { |
| 5089 |
tmp = x2; |
| 5090 |
x2 = x1; |
| 5091 |
x1 = tmp; |
| 5092 |
tmp = y2; |
| 5093 |
y2 = y1; |
| 5094 |
y1 = tmp; |
| 5095 |
} |
| 5096 |
|
| 5097 |
if (x2 < x1 && y1 === y2) { |
| 5098 |
tmp = x2; |
| 5099 |
x2 = x1; |
| 5100 |
x1 = tmp; |
| 5101 |
} |
| 5102 |
|
| 5103 |
for (y = y1; y <= y2; y++) { |
| 5104 |
x = 0; |
| 5105 |
xl = this.cols - 1; |
| 5106 |
if (y === y1) { |
| 5107 |
x = x1; |
| 5108 |
} |
| 5109 |
if (y === y2) { |
| 5110 |
xl = x2; |
| 5111 |
} |
| 5112 |
for (; x <= xl; x++) { |
| 5113 |
ch = this.lines[y][x][1]; |
| 5114 |
if (ch === ' ') { |
| 5115 |
buf += ch; |
| 5116 |
continue; |
| 5117 |
} |
| 5118 |
if (buf) { |
| 5119 |
out += buf; |
| 5120 |
buf = ''; |
| 5121 |
} |
| 5122 |
out += ch; |
| 5123 |
if (isWide(ch)) x++; |
| 5124 |
} |
| 5125 |
buf = ''; |
| 5126 |
out += '\n'; |
| 5127 |
} |
| 5128 |
|
| 5129 |
|
| 5130 |
|
| 5131 |
for (x = x2, y = y2; x < this.cols; x++) { |
| 5132 |
if (this.lines[y][x][1] !== ' ') { |
| 5133 |
out = out.slice(0, -1); |
| 5134 |
break; |
| 5135 |
} |
| 5136 |
} |
| 5137 |
|
| 5138 |
return out; |
| 5139 |
}; |
| 5140 |
|
| 5141 |
Terminal.prototype.keyPrefix = function(ev, key) { |
| 5142 |
if (key === 'k' || key === '&') { |
| 5143 |
this.destroy(); |
| 5144 |
} else if (key === 'p' || key === ']') { |
| 5145 |
this.emit('request paste'); |
| 5146 |
} else if (key === 'c') { |
| 5147 |
this.emit('request create'); |
| 5148 |
} else if (key >= '0' && key <= '9') { |
| 5149 |
key = +key - 1; |
| 5150 |
if (!~key) key = 9; |
| 5151 |
this.emit('request term', key); |
| 5152 |
} else if (key === 'n') { |
| 5153 |
this.emit('request term next'); |
| 5154 |
} else if (key === 'P') { |
| 5155 |
this.emit('request term previous'); |
| 5156 |
} else if (key === ':') { |
| 5157 |
this.emit('request command mode'); |
| 5158 |
} else if (key === '[') { |
| 5159 |
this.enterSelect(); |
| 5160 |
} |
| 5161 |
}; |
| 5162 |
|
| 5163 |
Terminal.prototype.keySelect = function(ev, key) { |
| 5164 |
this.showCursor(); |
| 5165 |
|
| 5166 |
if (this.searchMode || key === 'n' || key === 'N') { |
| 5167 |
return this.keySearch(ev, key); |
| 5168 |
} |
| 5169 |
|
| 5170 |
if (key === '\x04') { |
| 5171 |
var y = this.ydisp + this.y; |
| 5172 |
if (this.ydisp === this.ybase) { |
| 5173 |
|
| 5174 |
this.y = Math.min(this.y + (this.rows - 1) / 2 | 0, this.rows - 1); |
| 5175 |
this.refresh(0, this.rows - 1); |
| 5176 |
} else { |
| 5177 |
this.scrollDisp((this.rows - 1) / 2 | 0); |
| 5178 |
} |
| 5179 |
if (this.visualMode) { |
| 5180 |
this.selectText(this.x, this.x, y, this.ydisp + this.y); |
| 5181 |
} |
| 5182 |
return; |
| 5183 |
} |
| 5184 |
|
| 5185 |
if (key === '\x15') { |
| 5186 |
var y = this.ydisp + this.y; |
| 5187 |
if (this.ydisp === 0) { |
| 5188 |
|
| 5189 |
this.y = Math.max(this.y - (this.rows - 1) / 2 | 0, 0); |
| 5190 |
this.refresh(0, this.rows - 1); |
| 5191 |
} else { |
| 5192 |
this.scrollDisp(-(this.rows - 1) / 2 | 0); |
| 5193 |
} |
| 5194 |
if (this.visualMode) { |
| 5195 |
this.selectText(this.x, this.x, y, this.ydisp + this.y); |
| 5196 |
} |
| 5197 |
return; |
| 5198 |
} |
| 5199 |
|
| 5200 |
if (key === '\x06') { |
| 5201 |
var y = this.ydisp + this.y; |
| 5202 |
this.scrollDisp(this.rows - 1); |
| 5203 |
if (this.visualMode) { |
| 5204 |
this.selectText(this.x, this.x, y, this.ydisp + this.y); |
| 5205 |
} |
| 5206 |
return; |
| 5207 |
} |
| 5208 |
|
| 5209 |
if (key === '\x02') { |
| 5210 |
var y = this.ydisp + this.y; |
| 5211 |
this.scrollDisp(-(this.rows - 1)); |
| 5212 |
if (this.visualMode) { |
| 5213 |
this.selectText(this.x, this.x, y, this.ydisp + this.y); |
| 5214 |
} |
| 5215 |
return; |
| 5216 |
} |
| 5217 |
|
| 5218 |
if (key === 'k' || key === '\x1b[A') { |
| 5219 |
var y = this.ydisp + this.y; |
| 5220 |
this.y--; |
| 5221 |
if (this.y < 0) { |
| 5222 |
this.y = 0; |
| 5223 |
this.scrollDisp(-1); |
| 5224 |
} |
| 5225 |
if (this.visualMode) { |
| 5226 |
this.selectText(this.x, this.x, y, this.ydisp + this.y); |
| 5227 |
} else { |
| 5228 |
this.refresh(this.y, this.y + 1); |
| 5229 |
} |
| 5230 |
return; |
| 5231 |
} |
| 5232 |
|
| 5233 |
if (key === 'j' || key === '\x1b[B') { |
| 5234 |
var y = this.ydisp + this.y; |
| 5235 |
this.y++; |
| 5236 |
if (this.y >= this.rows) { |
| 5237 |
this.y = this.rows - 1; |
| 5238 |
this.scrollDisp(1); |
| 5239 |
} |
| 5240 |
if (this.visualMode) { |
| 5241 |
this.selectText(this.x, this.x, y, this.ydisp + this.y); |
| 5242 |
} else { |
| 5243 |
this.refresh(this.y - 1, this.y); |
| 5244 |
} |
| 5245 |
return; |
| 5246 |
} |
| 5247 |
|
| 5248 |
if (key === 'h' || key === '\x1b[D') { |
| 5249 |
var x = this.x; |
| 5250 |
this.x--; |
| 5251 |
if (this.x < 0) { |
| 5252 |
this.x = 0; |
| 5253 |
} |
| 5254 |
if (this.visualMode) { |
| 5255 |
this.selectText(x, this.x, this.ydisp + this.y, this.ydisp + this.y); |
| 5256 |
} else { |
| 5257 |
this.refresh(this.y, this.y); |
| 5258 |
} |
| 5259 |
return; |
| 5260 |
} |
| 5261 |
|
| 5262 |
if (key === 'l' || key === '\x1b[C') { |
| 5263 |
var x = this.x; |
| 5264 |
this.x++; |
| 5265 |
if (this.x >= this.cols) { |
| 5266 |
this.x = this.cols - 1; |
| 5267 |
} |
| 5268 |
if (this.visualMode) { |
| 5269 |
this.selectText(x, this.x, this.ydisp + this.y, this.ydisp + this.y); |
| 5270 |
} else { |
| 5271 |
this.refresh(this.y, this.y); |
| 5272 |
} |
| 5273 |
return; |
| 5274 |
} |
| 5275 |
|
| 5276 |
if (key === 'v' || key === ' ') { |
| 5277 |
if (!this.visualMode) { |
| 5278 |
this.enterVisual(); |
| 5279 |
} else { |
| 5280 |
this.leaveVisual(); |
| 5281 |
} |
| 5282 |
return; |
| 5283 |
} |
| 5284 |
|
| 5285 |
if (key === 'y') { |
| 5286 |
if (this.visualMode) { |
| 5287 |
var text = this.grabText( |
| 5288 |
this._selected.x1, this._selected.x2, |
| 5289 |
this._selected.y1, this._selected.y2); |
| 5290 |
this.copyText(text); |
| 5291 |
this.leaveVisual(); |
| 5292 |
|
| 5293 |
} |
| 5294 |
return; |
| 5295 |
} |
| 5296 |
|
| 5297 |
if (key === 'q' || key === '\x1b') { |
| 5298 |
if (this.visualMode) { |
| 5299 |
this.leaveVisual(); |
| 5300 |
} else { |
| 5301 |
this.leaveSelect(); |
| 5302 |
} |
| 5303 |
return; |
| 5304 |
} |
| 5305 |
|
| 5306 |
if (key === 'w' || key === 'W') { |
| 5307 |
var ox = this.x; |
| 5308 |
var oy = this.y; |
| 5309 |
var oyd = this.ydisp; |
| 5310 |
|
| 5311 |
var x = this.x; |
| 5312 |
var y = this.y; |
| 5313 |
var yb = this.ydisp; |
| 5314 |
var saw_space = false; |
| 5315 |
|
| 5316 |
for (;;) { |
| 5317 |
var line = this.lines[yb + y]; |
| 5318 |
while (x < this.cols) { |
| 5319 |
if (line[x][1] <= ' ') { |
| 5320 |
saw_space = true; |
| 5321 |
} else if (saw_space) { |
| 5322 |
break; |
| 5323 |
} |
| 5324 |
x++; |
| 5325 |
} |
| 5326 |
if (x >= this.cols) x = this.cols - 1; |
| 5327 |
if (x === this.cols - 1 && line[x][1] <= ' ') { |
| 5328 |
x = 0; |
| 5329 |
if (++y >= this.rows) { |
| 5330 |
y--; |
| 5331 |
if (++yb > this.ybase) { |
| 5332 |
yb = this.ybase; |
| 5333 |
x = this.x; |
| 5334 |
break; |
| 5335 |
} |
| 5336 |
} |
| 5337 |
continue; |
| 5338 |
} |
| 5339 |
break; |
| 5340 |
} |
| 5341 |
|
| 5342 |
this.x = x, this.y = y; |
| 5343 |
this.scrollDisp(-this.ydisp + yb); |
| 5344 |
|
| 5345 |
if (this.visualMode) { |
| 5346 |
this.selectText(ox, this.x, oy + oyd, this.ydisp + this.y); |
| 5347 |
} |
| 5348 |
return; |
| 5349 |
} |
| 5350 |
|
| 5351 |
if (key === 'b' || key === 'B') { |
| 5352 |
var ox = this.x; |
| 5353 |
var oy = this.y; |
| 5354 |
var oyd = this.ydisp; |
| 5355 |
|
| 5356 |
var x = this.x; |
| 5357 |
var y = this.y; |
| 5358 |
var yb = this.ydisp; |
| 5359 |
|
| 5360 |
for (;;) { |
| 5361 |
var line = this.lines[yb + y]; |
| 5362 |
var saw_space = x > 0 && line[x][1] > ' ' && line[x - 1][1] > ' '; |
| 5363 |
while (x >= 0) { |
| 5364 |
if (line[x][1] <= ' ') { |
| 5365 |
if (saw_space && (x + 1 < this.cols && line[x + 1][1] > ' ')) { |
| 5366 |
x++; |
| 5367 |
break; |
| 5368 |
} else { |
| 5369 |
saw_space = true; |
| 5370 |
} |
| 5371 |
} |
| 5372 |
x--; |
| 5373 |
} |
| 5374 |
if (x < 0) x = 0; |
| 5375 |
if (x === 0 && (line[x][1] <= ' ' || !saw_space)) { |
| 5376 |
x = this.cols - 1; |
| 5377 |
if (--y < 0) { |
| 5378 |
y++; |
| 5379 |
if (--yb < 0) { |
| 5380 |
yb++; |
| 5381 |
x = 0; |
| 5382 |
break; |
| 5383 |
} |
| 5384 |
} |
| 5385 |
continue; |
| 5386 |
} |
| 5387 |
break; |
| 5388 |
} |
| 5389 |
|
| 5390 |
this.x = x, this.y = y; |
| 5391 |
this.scrollDisp(-this.ydisp + yb); |
| 5392 |
|
| 5393 |
if (this.visualMode) { |
| 5394 |
this.selectText(ox, this.x, oy + oyd, this.ydisp + this.y); |
| 5395 |
} |
| 5396 |
return; |
| 5397 |
} |
| 5398 |
|
| 5399 |
if (key === 'e' || key === 'E') { |
| 5400 |
var x = this.x + 1; |
| 5401 |
var y = this.y; |
| 5402 |
var yb = this.ydisp; |
| 5403 |
if (x >= this.cols) x--; |
| 5404 |
|
| 5405 |
for (;;) { |
| 5406 |
var line = this.lines[yb + y]; |
| 5407 |
while (x < this.cols) { |
| 5408 |
if (line[x][1] <= ' ') { |
| 5409 |
x++; |
| 5410 |
} else { |
| 5411 |
break; |
| 5412 |
} |
| 5413 |
} |
| 5414 |
while (x < this.cols) { |
| 5415 |
if (line[x][1] <= ' ') { |
| 5416 |
if (x - 1 >= 0 && line[x - 1][1] > ' ') { |
| 5417 |
x--; |
| 5418 |
break; |
| 5419 |
} |
| 5420 |
} |
| 5421 |
x++; |
| 5422 |
} |
| 5423 |
if (x >= this.cols) x = this.cols - 1; |
| 5424 |
if (x === this.cols - 1 && line[x][1] <= ' ') { |
| 5425 |
x = 0; |
| 5426 |
if (++y >= this.rows) { |
| 5427 |
y--; |
| 5428 |
if (++yb > this.ybase) { |
| 5429 |
yb = this.ybase; |
| 5430 |
break; |
| 5431 |
} |
| 5432 |
} |
| 5433 |
continue; |
| 5434 |
} |
| 5435 |
break; |
| 5436 |
} |
| 5437 |
|
| 5438 |
this.x = x, this.y = y; |
| 5439 |
this.scrollDisp(-this.ydisp + yb); |
| 5440 |
|
| 5441 |
if (this.visualMode) { |
| 5442 |
this.selectText(ox, this.x, oy + oyd, this.ydisp + this.y); |
| 5443 |
} |
| 5444 |
return; |
| 5445 |
} |
| 5446 |
|
| 5447 |
if (key === '^' || key === '0') { |
| 5448 |
var ox = this.x; |
| 5449 |
|
| 5450 |
if (key === '0') { |
| 5451 |
this.x = 0; |
| 5452 |
} else if (key === '^') { |
| 5453 |
var line = this.lines[this.ydisp + this.y]; |
| 5454 |
var x = 0; |
| 5455 |
while (x < this.cols) { |
| 5456 |
if (line[x][1] > ' ') { |
| 5457 |
break; |
| 5458 |
} |
| 5459 |
x++; |
| 5460 |
} |
| 5461 |
if (x >= this.cols) x = this.cols - 1; |
| 5462 |
this.x = x; |
| 5463 |
} |
| 5464 |
|
| 5465 |
if (this.visualMode) { |
| 5466 |
this.selectText(ox, this.x, this.ydisp + this.y, this.ydisp + this.y); |
| 5467 |
} else { |
| 5468 |
this.refresh(this.y, this.y); |
| 5469 |
} |
| 5470 |
return; |
| 5471 |
} |
| 5472 |
|
| 5473 |
if (key === '$') { |
| 5474 |
var ox = this.x; |
| 5475 |
var line = this.lines[this.ydisp + this.y]; |
| 5476 |
var x = this.cols - 1; |
| 5477 |
while (x >= 0) { |
| 5478 |
if (line[x][1] > ' ') { |
| 5479 |
if (this.visualMode && x < this.cols - 1) x++; |
| 5480 |
break; |
| 5481 |
} |
| 5482 |
x--; |
| 5483 |
} |
| 5484 |
if (x < 0) x = 0; |
| 5485 |
this.x = x; |
| 5486 |
if (this.visualMode) { |
| 5487 |
this.selectText(ox, this.x, this.ydisp + this.y, this.ydisp + this.y); |
| 5488 |
} else { |
| 5489 |
this.refresh(this.y, this.y); |
| 5490 |
} |
| 5491 |
return; |
| 5492 |
} |
| 5493 |
|
| 5494 |
if (key === 'g' || key === 'G') { |
| 5495 |
var ox = this.x; |
| 5496 |
var oy = this.y; |
| 5497 |
var oyd = this.ydisp; |
| 5498 |
if (key === 'g') { |
| 5499 |
this.x = 0, this.y = 0; |
| 5500 |
this.scrollDisp(-this.ydisp); |
| 5501 |
} else if (key === 'G') { |
| 5502 |
this.x = 0, this.y = this.rows - 1; |
| 5503 |
this.scrollDisp(this.ybase); |
| 5504 |
} |
| 5505 |
if (this.visualMode) { |
| 5506 |
this.selectText(ox, this.x, oy + oyd, this.ydisp + this.y); |
| 5507 |
} |
| 5508 |
return; |
| 5509 |
} |
| 5510 |
|
| 5511 |
if (key === 'H' || key === 'M' || key === 'L') { |
| 5512 |
var ox = this.x; |
| 5513 |
var oy = this.y; |
| 5514 |
if (key === 'H') { |
| 5515 |
this.x = 0, this.y = 0; |
| 5516 |
} else if (key === 'M') { |
| 5517 |
this.x = 0, this.y = this.rows / 2 | 0; |
| 5518 |
} else if (key === 'L') { |
| 5519 |
this.x = 0, this.y = this.rows - 1; |
| 5520 |
} |
| 5521 |
if (this.visualMode) { |
| 5522 |
this.selectText(ox, this.x, this.ydisp + oy, this.ydisp + this.y); |
| 5523 |
} else { |
| 5524 |
this.refresh(oy, oy); |
| 5525 |
this.refresh(this.y, this.y); |
| 5526 |
} |
| 5527 |
return; |
| 5528 |
} |
| 5529 |
|
| 5530 |
if (key === '{' || key === '}') { |
| 5531 |
var ox = this.x; |
| 5532 |
var oy = this.y; |
| 5533 |
var oyd = this.ydisp; |
| 5534 |
|
| 5535 |
var line; |
| 5536 |
var saw_full = false; |
| 5537 |
var found = false; |
| 5538 |
var first_is_space = -1; |
| 5539 |
var y = this.y + (key === '{' ? -1 : 1); |
| 5540 |
var yb = this.ydisp; |
| 5541 |
var i; |
| 5542 |
|
| 5543 |
if (key === '{') { |
| 5544 |
if (y < 0) { |
| 5545 |
y++; |
| 5546 |
if (yb > 0) yb--; |
| 5547 |
} |
| 5548 |
} else if (key === '}') { |
| 5549 |
if (y >= this.rows) { |
| 5550 |
y--; |
| 5551 |
if (yb < this.ybase) yb++; |
| 5552 |
} |
| 5553 |
} |
| 5554 |
|
| 5555 |
for (;;) { |
| 5556 |
line = this.lines[yb + y]; |
| 5557 |
|
| 5558 |
for (i = 0; i < this.cols; i++) { |
| 5559 |
if (line[i][1] > ' ') { |
| 5560 |
if (first_is_space === -1) { |
| 5561 |
first_is_space = 0; |
| 5562 |
} |
| 5563 |
saw_full = true; |
| 5564 |
break; |
| 5565 |
} else if (i === this.cols - 1) { |
| 5566 |
if (first_is_space === -1) { |
| 5567 |
first_is_space = 1; |
| 5568 |
} else if (first_is_space === 0) { |
| 5569 |
found = true; |
| 5570 |
} else if (first_is_space === 1) { |
| 5571 |
if (saw_full) found = true; |
| 5572 |
} |
| 5573 |
break; |
| 5574 |
} |
| 5575 |
} |
| 5576 |
|
| 5577 |
if (found) break; |
| 5578 |
|
| 5579 |
if (key === '{') { |
| 5580 |
y--; |
| 5581 |
if (y < 0) { |
| 5582 |
y++; |
| 5583 |
if (yb > 0) yb--; |
| 5584 |
else break; |
| 5585 |
} |
| 5586 |
} else if (key === '}') { |
| 5587 |
y++; |
| 5588 |
if (y >= this.rows) { |
| 5589 |
y--; |
| 5590 |
if (yb < this.ybase) yb++; |
| 5591 |
else break; |
| 5592 |
} |
| 5593 |
} |
| 5594 |
} |
| 5595 |
|
| 5596 |
if (!found) { |
| 5597 |
if (key === '{') { |
| 5598 |
y = 0; |
| 5599 |
yb = 0; |
| 5600 |
} else if (key === '}') { |
| 5601 |
y = this.rows - 1; |
| 5602 |
yb = this.ybase; |
| 5603 |
} |
| 5604 |
} |
| 5605 |
|
| 5606 |
this.x = 0, this.y = y; |
| 5607 |
this.scrollDisp(-this.ydisp + yb); |
| 5608 |
|
| 5609 |
if (this.visualMode) { |
| 5610 |
this.selectText(ox, this.x, oy + oyd, this.ydisp + this.y); |
| 5611 |
} |
| 5612 |
return; |
| 5613 |
} |
| 5614 |
|
| 5615 |
if (key === '/' || key === '?') { |
| 5616 |
if (!this.visualMode) { |
| 5617 |
this.enterSearch(key === '/'); |
| 5618 |
} |
| 5619 |
return; |
| 5620 |
} |
| 5621 |
|
| 5622 |
return false; |
| 5623 |
}; |
| 5624 |
|
| 5625 |
Terminal.prototype.keySearch = function(ev, key) { |
| 5626 |
if (key === '\x1b') { |
| 5627 |
this.leaveSearch(); |
| 5628 |
return; |
| 5629 |
} |
| 5630 |
|
| 5631 |
if (key === '\r' || (!this.searchMode && (key === 'n' || key === 'N'))) { |
| 5632 |
this.leaveSearch(); |
| 5633 |
|
| 5634 |
var entry = this.entry; |
| 5635 |
|
| 5636 |
if (!entry) { |
| 5637 |
this.refresh(0, this.rows - 1); |
| 5638 |
return; |
| 5639 |
} |
| 5640 |
|
| 5641 |
var ox = this.x; |
| 5642 |
var oy = this.y; |
| 5643 |
var oyd = this.ydisp; |
| 5644 |
|
| 5645 |
var line; |
| 5646 |
var found = false; |
| 5647 |
var wrapped = false; |
| 5648 |
var x = this.x + 1; |
| 5649 |
var y = this.ydisp + this.y; |
| 5650 |
var yb, i; |
| 5651 |
var up = key === 'N' |
| 5652 |
? this.searchDown |
| 5653 |
: !this.searchDown; |
| 5654 |
|
| 5655 |
for (;;) { |
| 5656 |
line = this.lines[y]; |
| 5657 |
|
| 5658 |
while (x < this.cols) { |
| 5659 |
for (i = 0; i < entry.length; i++) { |
| 5660 |
if (x + i >= this.cols) break; |
| 5661 |
if (line[x + i][1] !== entry[i]) { |
| 5662 |
break; |
| 5663 |
} else if (line[x + i][1] === entry[i] && i === entry.length - 1) { |
| 5664 |
found = true; |
| 5665 |
break; |
| 5666 |
} |
| 5667 |
} |
| 5668 |
if (found) break; |
| 5669 |
x += i + 1; |
| 5670 |
} |
| 5671 |
if (found) break; |
| 5672 |
|
| 5673 |
x = 0; |
| 5674 |
|
| 5675 |
if (!up) { |
| 5676 |
y++; |
| 5677 |
if (y > this.ybase + this.rows - 1) { |
| 5678 |
if (wrapped) break; |
| 5679 |
|
| 5680 |
wrapped = true; |
| 5681 |
y = 0; |
| 5682 |
} |
| 5683 |
} else { |
| 5684 |
y--; |
| 5685 |
if (y < 0) { |
| 5686 |
if (wrapped) break; |
| 5687 |
|
| 5688 |
wrapped = true; |
| 5689 |
y = this.ybase + this.rows - 1; |
| 5690 |
} |
| 5691 |
} |
| 5692 |
} |
| 5693 |
|
| 5694 |
if (found) { |
| 5695 |
if (y - this.ybase < 0) { |
| 5696 |
yb = y; |
| 5697 |
y = 0; |
| 5698 |
if (yb > this.ybase) { |
| 5699 |
y = yb - this.ybase; |
| 5700 |
yb = this.ybase; |
| 5701 |
} |
| 5702 |
} else { |
| 5703 |
yb = this.ybase; |
| 5704 |
y -= this.ybase; |
| 5705 |
} |
| 5706 |
|
| 5707 |
this.x = x, this.y = y; |
| 5708 |
this.scrollDisp(-this.ydisp + yb); |
| 5709 |
|
| 5710 |
if (this.visualMode) { |
| 5711 |
this.selectText(ox, this.x, oy + oyd, this.ydisp + this.y); |
| 5712 |
} |
| 5713 |
return; |
| 5714 |
} |
| 5715 |
|
| 5716 |
|
| 5717 |
this.refresh(0, this.rows - 1); |
| 5718 |
|
| 5719 |
return; |
| 5720 |
} |
| 5721 |
|
| 5722 |
if (key === '\b' || key === '\x7f') { |
| 5723 |
if (this.entry.length === 0) return; |
| 5724 |
var bottom = this.ydisp + this.rows - 1; |
| 5725 |
this.entry = this.entry.slice(0, -1); |
| 5726 |
var i = this.entryPrefix.length + this.entry.length; |
| 5727 |
|
| 5728 |
this.lines[bottom][i] = [ |
| 5729 |
this.lines[bottom][i][0], |
| 5730 |
' ' |
| 5731 |
]; |
| 5732 |
this.x--; |
| 5733 |
this.refresh(this.rows - 1, this.rows - 1); |
| 5734 |
this.refresh(this.y, this.y); |
| 5735 |
return; |
| 5736 |
} |
| 5737 |
|
| 5738 |
if (key.length === 1 && key >= ' ' && key <= '~') { |
| 5739 |
var bottom = this.ydisp + this.rows - 1; |
| 5740 |
this.entry += key; |
| 5741 |
var i = this.entryPrefix.length + this.entry.length - 1; |
| 5742 |
|
| 5743 |
|
| 5744 |
this.lines[bottom][i] = [ |
| 5745 |
(this.defAttr & ~0x1ff) | 4, |
| 5746 |
key |
| 5747 |
]; |
| 5748 |
this.x++; |
| 5749 |
this.refresh(this.rows - 1, this.rows - 1); |
| 5750 |
this.refresh(this.y, this.y); |
| 5751 |
return; |
| 5752 |
} |
| 5753 |
|
| 5754 |
return false; |
| 5755 |
}; |
| 5756 |
|
| 5757 |
|
| 5758 |
|
| 5759 |
|
| 5760 |
|
| 5761 |
Terminal.charsets = {}; |
| 5762 |
|
| 5763 |
|
| 5764 |
|
| 5765 |
|
| 5766 |
|
| 5767 |
|
| 5768 |
|
| 5769 |
|
| 5770 |
|
| 5771 |
Terminal.charsets.SCLD = { |
| 5772 |
'`': '\u25c6', ◆' |
| 5773 |
'a': '\u2592', ▒' |
| 5774 |
'b': '\u0009', |
| 5775 |
'c': '\u000c', |
| 5776 |
'd': '\u000d', |
| 5777 |
'e': '\u000a', |
| 5778 |
'f': '\u00b0', ' |
| 5779 |
'g': '\u00b1', ' |
| 5780 |
'h': '\u2424', |
| 5781 |
'i': '\u000b', |
| 5782 |
'j': '\u2518', ┘' |
| 5783 |
'k': '\u2510', ┐' |
| 5784 |
'l': '\u250c', ┌' |
| 5785 |
'm': '\u2514', └' |
| 5786 |
'n': '\u253c', ┼' |
| 5787 |
'o': '\u23ba', ⎺' |
| 5788 |
'p': '\u23bb', ⎻' |
| 5789 |
'q': '\u2500', ─' |
| 5790 |
'r': '\u23bc', ⎼' |
| 5791 |
's': '\u23bd', ⎽' |
| 5792 |
't': '\u251c', ├' |
| 5793 |
'u': '\u2524', ┤' |
| 5794 |
'v': '\u2534', ┴' |
| 5795 |
'w': '\u252c', ┬' |
| 5796 |
'x': '\u2502', │' |
| 5797 |
'y': '\u2264', ≤' |
| 5798 |
'z': '\u2265', ≥' |
| 5799 |
'{': '\u03c0', ' |
| 5800 |
'|': '\u2260', ≠' |
| 5801 |
'}': '\u00a3', ' |
| 5802 |
'~': '\u00b7' ' |
| 5803 |
}; |
| 5804 |
|
| 5805 |
Terminal.charsets.UK = null; |
| 5806 |
Terminal.charsets.US = null; |
| 5807 |
Terminal.charsets.Dutch = null; |
| 5808 |
Terminal.charsets.Finnish = null; |
| 5809 |
Terminal.charsets.French = null; |
| 5810 |
Terminal.charsets.FrenchCanadian = null; |
| 5811 |
Terminal.charsets.German = null; |
| 5812 |
Terminal.charsets.Italian = null; |
| 5813 |
Terminal.charsets.NorwegianDanish = null; |
| 5814 |
Terminal.charsets.Spanish = null; |
| 5815 |
Terminal.charsets.Swedish = null; |
| 5816 |
Terminal.charsets.Swiss = null; |
| 5817 |
Terminal.charsets.ISOLatin = null; |
| 5818 |
|
| 5819 |
|
| 5820 |
|
| 5821 |
|
| 5822 |
|
| 5823 |
function on(el, type, handler, capture) { |
| 5824 |
el.addEventListener(type, handler, capture || false); |
| 5825 |
} |
| 5826 |
|
| 5827 |
function off(el, type, handler, capture) { |
| 5828 |
el.removeEventListener(type, handler, capture || false); |
| 5829 |
} |
| 5830 |
|
| 5831 |
function cancel(ev) { |
| 5832 |
if (ev.preventDefault) ev.preventDefault(); |
| 5833 |
ev.returnValue = false; |
| 5834 |
if (ev.stopPropagation) ev.stopPropagation(); |
| 5835 |
ev.cancelBubble = true; |
| 5836 |
return false; |
| 5837 |
} |
| 5838 |
|
| 5839 |
function inherits(child, parent) { |
| 5840 |
function f() { |
| 5841 |
this.constructor = child; |
| 5842 |
} |
| 5843 |
f.prototype = parent.prototype; |
| 5844 |
child.prototype = new f; |
| 5845 |
} |
| 5846 |
|
| 5847 |
|
| 5848 |
|
| 5849 |
function isBoldBroken(document) { |
| 5850 |
var body = document.getElementsByTagName('body')[0]; |
| 5851 |
var terminal = document.createElement('div'); |
| 5852 |
terminal.className = 'terminal'; |
| 5853 |
var line = document.createElement('div'); |
| 5854 |
var el = document.createElement('span'); |
| 5855 |
el.innerHTML = 'hello world'; |
| 5856 |
line.appendChild(el); |
| 5857 |
terminal.appendChild(line); |
| 5858 |
body.appendChild(terminal); |
| 5859 |
var w1 = el.scrollWidth; |
| 5860 |
el.style.fontWeight = 'bold'; |
| 5861 |
var w2 = el.scrollWidth; |
| 5862 |
body.removeChild(terminal); |
| 5863 |
return w1 !== w2; |
| 5864 |
} |
| 5865 |
|
| 5866 |
var String = this.String; |
| 5867 |
var setTimeout = this.setTimeout; |
| 5868 |
var setInterval = this.setInterval; |
| 5869 |
|
| 5870 |
function indexOf(obj, el) { |
| 5871 |
var i = obj.length; |
| 5872 |
while (i--) { |
| 5873 |
if (obj[i] === el) return i; |
| 5874 |
} |
| 5875 |
return -1; |
| 5876 |
} |
| 5877 |
|
| 5878 |
function isWide(ch) { |
| 5879 |
if (ch <= '\uff00') return false; |
| 5880 |
return (ch >= '\uff01' && ch <= '\uffbe') |
| 5881 |
|| (ch >= '\uffc2' && ch <= '\uffc7') |
| 5882 |
|| (ch >= '\uffca' && ch <= '\uffcf') |
| 5883 |
|| (ch >= '\uffd2' && ch <= '\uffd7') |
| 5884 |
|| (ch >= '\uffda' && ch <= '\uffdc') |
| 5885 |
|| (ch >= '\uffe0' && ch <= '\uffe6') |
| 5886 |
|| (ch >= '\uffe8' && ch <= '\uffee'); |
| 5887 |
} |
| 5888 |
|
| 5889 |
function matchColor(r1, g1, b1) { |
| 5890 |
var hash = (r1 << 16) | (g1 << 8) | b1; |
| 5891 |
|
| 5892 |
if (matchColor._cache[hash] != null) { |
| 5893 |
return matchColor._cache[hash]; |
| 5894 |
} |
| 5895 |
|
| 5896 |
var ldiff = Infinity |
| 5897 |
, li = -1 |
| 5898 |
, i = 0 |
| 5899 |
, c |
| 5900 |
, r2 |
| 5901 |
, g2 |
| 5902 |
, b2 |
| 5903 |
, diff; |
| 5904 |
|
| 5905 |
for (; i < Terminal.vcolors.length; i++) { |
| 5906 |
c = Terminal.vcolors[i]; |
| 5907 |
r2 = c[0]; |
| 5908 |
g2 = c[1]; |
| 5909 |
b2 = c[2]; |
| 5910 |
|
| 5911 |
diff = matchColor.distance(r1, g1, b1, r2, g2, b2); |
| 5912 |
|
| 5913 |
if (diff === 0) { |
| 5914 |
li = i; |
| 5915 |
break; |
| 5916 |
} |
| 5917 |
|
| 5918 |
if (diff < ldiff) { |
| 5919 |
ldiff = diff; |
| 5920 |
li = i; |
| 5921 |
} |
| 5922 |
} |
| 5923 |
|
| 5924 |
return matchColor._cache[hash] = li; |
| 5925 |
} |
| 5926 |
|
| 5927 |
matchColor._cache = {}; |
| 5928 |
|
| 5929 |
|
| 5930 |
matchColor.distance = function(r1, g1, b1, r2, g2, b2) { |
| 5931 |
return Math.pow(30 * (r1 - r2), 2) |
| 5932 |
+ Math.pow(59 * (g1 - g2), 2) |
| 5933 |
+ Math.pow(11 * (b1 - b2), 2); |
| 5934 |
}; |
| 5935 |
|
| 5936 |
function each(obj, iter, con) { |
| 5937 |
if (obj.forEach) return obj.forEach(iter, con); |
| 5938 |
for (var i = 0; i < obj.length; i++) { |
| 5939 |
iter.call(con, obj[i], i, obj); |
| 5940 |
} |
| 5941 |
} |
| 5942 |
|
| 5943 |
function keys(obj) { |
| 5944 |
if (Object.keys) return Object.keys(obj); |
| 5945 |
var key, keys = []; |
| 5946 |
for (key in obj) { |
| 5947 |
if (Object.prototype.hasOwnProperty.call(obj, key)) { |
| 5948 |
keys.push(key); |
| 5949 |
} |
| 5950 |
} |
| 5951 |
return keys; |
| 5952 |
} |
| 5953 |
|
| 5954 |
|
| 5955 |
|
| 5956 |
|
| 5957 |
|
| 5958 |
Terminal.EventEmitter = EventEmitter; |
| 5959 |
Terminal.Stream = Stream; |
| 5960 |
Terminal.inherits = inherits; |
| 5961 |
Terminal.on = on; |
| 5962 |
Terminal.off = off; |
| 5963 |
Terminal.cancel = cancel; |
| 5964 |
|
| 5965 |
if (typeof module !== 'undefined') { |
| 5966 |
module.exports = Terminal; |
| 5967 |
} else { |
| 5968 |
this.Terminal = Terminal; |
| 5969 |
} |
| 5970 |
|
| 5971 |
}).call(function() { |
| 5972 |
return this || (typeof window !== 'undefined' ? window : global); |
| 5973 |
}()); |