PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/butterfly/static/main.js

https://github.com/PKUbuntu/butterfly
JavaScript | 2891 lines | 2730 code | 160 blank | 1 comment | 560 complexity | 4cac6a01a99d89cee09c0c422076a746 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. (function() {
  2. var $, Selection, State, Terminal, alt, bench, cancel, cbench, cols, ctl, ctrl, first, next_leaf, open_ts, previous_leaf, quit, rows, s, selection, send, term, virtual_input, ws, ws_url,
  3. __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
  4. __slice = [].slice;
  5. cancel = function(ev) {
  6. if (ev.preventDefault) {
  7. ev.preventDefault();
  8. }
  9. if (ev.stopPropagation) {
  10. ev.stopPropagation();
  11. }
  12. ev.cancelBubble = true;
  13. return false;
  14. };
  15. s = 0;
  16. State = {
  17. normal: s++,
  18. escaped: s++,
  19. csi: s++,
  20. osc: s++,
  21. charset: s++,
  22. dcs: s++,
  23. ignore: s++
  24. };
  25. Terminal = (function() {
  26. function Terminal(parent, out, ctl) {
  27. var div, i, term_size;
  28. this.parent = parent;
  29. this.out = out;
  30. this.ctl = ctl != null ? ctl : function() {};
  31. this.context = this.parent.ownerDocument.defaultView;
  32. this.document = this.parent.ownerDocument;
  33. this.body = this.document.getElementsByTagName('body')[0];
  34. this.element = this.document.createElement('div');
  35. this.element.className = 'terminal focus';
  36. this.element.style.outline = 'none';
  37. this.element.setAttribute('tabindex', 0);
  38. this.parent.appendChild(this.element);
  39. div = this.document.createElement('div');
  40. div.className = 'line';
  41. this.element.appendChild(div);
  42. this.children = [div];
  43. this.compute_char_size();
  44. div.style.height = this.char_size.height + 'px';
  45. term_size = this.parent.getBoundingClientRect();
  46. this.cols = Math.floor(term_size.width / this.char_size.width);
  47. this.rows = Math.floor(term_size.height / this.char_size.height);
  48. i = this.rows - 1;
  49. while (i--) {
  50. div = this.document.createElement('div');
  51. div.style.height = this.char_size.height + 'px';
  52. div.className = 'line';
  53. this.element.appendChild(div);
  54. this.children.push(div);
  55. }
  56. this.scrollback = 100000;
  57. this.visualBell = 100;
  58. this.convertEol = false;
  59. this.termName = 'xterm';
  60. this.cursorBlink = true;
  61. this.cursorState = 0;
  62. this.last_cc = 0;
  63. this.reset_vars();
  64. this.refresh(0, this.rows - 1);
  65. this.focus();
  66. this.startBlink();
  67. addEventListener('keydown', this.keyDown.bind(this));
  68. addEventListener('keypress', this.keyPress.bind(this));
  69. addEventListener('focus', this.focus.bind(this));
  70. addEventListener('blur', this.blur.bind(this));
  71. addEventListener('paste', this.paste.bind(this));
  72. addEventListener('resize', this.resize.bind(this));
  73. if (typeof InstallTrigger !== "undefined") {
  74. this.element.contentEditable = 'true';
  75. this.element.addEventListener("mouseup", function() {
  76. var sel;
  77. sel = getSelection().getRangeAt(0);
  78. if (sel.startOffset === sel.endOffset) {
  79. return getSelection().removeAllRanges();
  80. }
  81. });
  82. }
  83. this.initmouse();
  84. setTimeout(this.resize.bind(this), 100);
  85. }
  86. Terminal.prototype.reset_vars = function() {
  87. var i;
  88. this.ybase = 0;
  89. this.ydisp = 0;
  90. this.x = 0;
  91. this.y = 0;
  92. this.cursorHidden = false;
  93. this.state = State.normal;
  94. this.queue = '';
  95. this.scrollTop = 0;
  96. this.scrollBottom = this.rows - 1;
  97. this.applicationKeypad = false;
  98. this.applicationCursor = false;
  99. this.originMode = false;
  100. this.wraparoundMode = false;
  101. this.normal = null;
  102. this.charset = null;
  103. this.gcharset = null;
  104. this.glevel = 0;
  105. this.charsets = [null];
  106. this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
  107. this.curAttr = this.defAttr;
  108. this.params = [];
  109. this.currentParam = 0;
  110. this.prefix = "";
  111. this.lines = [];
  112. i = this.rows;
  113. while (i--) {
  114. this.lines.push(this.blankLine());
  115. }
  116. this.setupStops();
  117. return this.skipNextKey = null;
  118. };
  119. Terminal.prototype.compute_char_size = function() {
  120. var test_span;
  121. test_span = document.createElement('span');
  122. test_span.textContent = '0123456789';
  123. this.children[0].appendChild(test_span);
  124. this.char_size = {
  125. width: test_span.getBoundingClientRect().width / 10,
  126. height: this.children[0].getBoundingClientRect().height
  127. };
  128. return this.children[0].removeChild(test_span);
  129. };
  130. Terminal.prototype.eraseAttr = function() {
  131. return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
  132. };
  133. Terminal.prototype.focus = function() {
  134. if (this.sendFocus) {
  135. this.send('\x1b[I');
  136. }
  137. this.showCursor();
  138. this.element.classList.add('focus');
  139. return this.element.classList.remove('blur');
  140. };
  141. Terminal.prototype.blur = function() {
  142. this.cursorState = 1;
  143. this.refresh(this.y, this.y);
  144. if (this.sendFocus) {
  145. this.send('\x1b[O');
  146. }
  147. this.element.classList.add('blur');
  148. return this.element.classList.remove('focus');
  149. };
  150. Terminal.prototype.paste = function(ev) {
  151. if (ev.clipboardData) {
  152. this.send(ev.clipboardData.getData('text/plain'));
  153. } else if (this.context.clipboardData) {
  154. this.send(this.context.clipboardData.getData('Text'));
  155. }
  156. return cancel(ev);
  157. };
  158. Terminal.prototype.initmouse = function() {
  159. var encode, getButton, getCoords, pressed, sendButton, sendEvent, sendMove;
  160. pressed = 32;
  161. sendButton = function(ev) {
  162. var button, pos;
  163. button = getButton(ev);
  164. pos = getCoords(ev);
  165. if (!pos) {
  166. return;
  167. }
  168. sendEvent(button, pos);
  169. switch (ev.type) {
  170. case "mousedown":
  171. return pressed = button;
  172. case "mouseup":
  173. return pressed = 32;
  174. }
  175. };
  176. sendMove = function(ev) {
  177. var button, pos;
  178. button = pressed;
  179. pos = getCoords(ev);
  180. if (!pos) {
  181. return;
  182. }
  183. button += 32;
  184. return sendEvent(button, pos);
  185. };
  186. encode = (function(_this) {
  187. return function(data, ch) {
  188. if (!_this.utfMouse) {
  189. if (ch === 255) {
  190. return data.push(0);
  191. }
  192. if (ch > 127) {
  193. ch = 127;
  194. }
  195. return data.push(ch);
  196. } else {
  197. if (ch === 2047) {
  198. return data.push(0);
  199. }
  200. if (ch < 127) {
  201. return data.push(ch);
  202. } else {
  203. if (ch > 2047) {
  204. ch = 2047;
  205. }
  206. data.push(0xC0 | (ch >> 6));
  207. return data.push(0x80 | (ch & 0x3F));
  208. }
  209. }
  210. };
  211. })(this);
  212. sendEvent = (function(_this) {
  213. return function(button, pos) {
  214. var data;
  215. if (_this.urxvtMouse) {
  216. pos.x -= 32;
  217. pos.y -= 32;
  218. pos.x++;
  219. pos.y++;
  220. _this.send("\x1b[" + button + ";" + pos.x + ";" + pos.y + "M");
  221. return;
  222. }
  223. if (_this.sgrMouse) {
  224. pos.x -= 32;
  225. pos.y -= 32;
  226. _this.send("\x1b[<" + ((button & 3) === 3 ? button & ~3 : button) + ";" + pos.x + ";" + pos.y + ((button & 3) === 3 ? "m" : "M"));
  227. return;
  228. }
  229. data = [];
  230. encode(data, button);
  231. encode(data, pos.x);
  232. encode(data, pos.y);
  233. return _this.send("\x1b[M" + String.fromCharCode.apply(String, data));
  234. };
  235. })(this);
  236. getButton = (function(_this) {
  237. return function(ev) {
  238. var button, ctrl, meta, mod, shift;
  239. switch (ev.type) {
  240. case "mousedown":
  241. button = ev.button != null ? +ev.button : (ev.which != null ? ev.which - 1 : null);
  242. break;
  243. case "mouseup":
  244. button = 3;
  245. break;
  246. case "wheel":
  247. button = ev.deltaY < 0 ? 64 : 65;
  248. }
  249. shift = ev.shiftKey ? 4 : 0;
  250. meta = ev.metaKey ? 8 : 0;
  251. ctrl = ev.ctrlKey ? 16 : 0;
  252. mod = shift | meta | ctrl;
  253. if (_this.vt200Mouse) {
  254. mod &= ctrl;
  255. } else {
  256. if (!_this.normalMouse) {
  257. mod = 0;
  258. }
  259. }
  260. return (32 + (mod << 2)) + button;
  261. };
  262. })(this);
  263. getCoords = (function(_this) {
  264. return function(ev) {
  265. var el, h, w, x, y;
  266. x = ev.pageX;
  267. y = ev.pageY;
  268. el = _this.element;
  269. while (el && el !== _this.document.documentElement) {
  270. x -= el.offsetLeft;
  271. y -= el.offsetTop;
  272. el = "offsetParent" in el ? el.offsetParent : el.parentNode;
  273. }
  274. w = _this.element.clientWidth;
  275. h = _this.element.clientHeight;
  276. x = Math.ceil((x / w) * _this.cols);
  277. y = Math.ceil((y / h) * _this.rows);
  278. if (x < 0) {
  279. x = 0;
  280. }
  281. if (x > _this.cols) {
  282. x = _this.cols;
  283. }
  284. if (y < 0) {
  285. y = 0;
  286. }
  287. if (y > _this.rows) {
  288. y = _this.rows;
  289. }
  290. x += 32;
  291. y += 32;
  292. return {
  293. x: x,
  294. y: y,
  295. type: ev.type
  296. };
  297. };
  298. })(this);
  299. addEventListener("mousedown", (function(_this) {
  300. return function(ev) {
  301. var sm, up;
  302. if (!_this.mouseEvents) {
  303. return;
  304. }
  305. sendButton(ev);
  306. if (_this.vt200Mouse) {
  307. sendButton({
  308. __proto__: ev,
  309. type: "mouseup"
  310. });
  311. return cancel(ev);
  312. }
  313. sm = sendMove.bind(_this);
  314. if (_this.normalMouse) {
  315. addEventListener("mousemove", sm);
  316. }
  317. if (!_this.x10Mouse) {
  318. addEventListener("mouseup", up = function(ev) {
  319. sendButton(ev);
  320. if (_this.normalMouse) {
  321. removeEventListener("mousemove", sm);
  322. }
  323. removeEventListener("mouseup", up);
  324. return cancel(ev);
  325. });
  326. }
  327. return cancel(ev);
  328. };
  329. })(this));
  330. return addEventListener("wheel", (function(_this) {
  331. return function(ev) {
  332. if (_this.mouseEvents) {
  333. if (_this.x10Mouse) {
  334. return;
  335. }
  336. sendButton(ev);
  337. } else {
  338. if (_this.applicationKeypad) {
  339. return;
  340. }
  341. _this.scrollDisp(ev.deltaY > 0 ? 5 : -5);
  342. }
  343. return cancel(ev);
  344. };
  345. })(this));
  346. };
  347. Terminal.prototype.refresh = function(start, end) {
  348. var attr, bg, ch, classes, data, fg, flags, i, line, out, parent, row, width, x, y;
  349. if (end - start >= this.rows / 3) {
  350. parent = this.element.parentNode;
  351. if (parent != null) {
  352. parent.removeChild(this.element);
  353. }
  354. }
  355. width = this.cols;
  356. y = start;
  357. if (end >= this.lines.length) {
  358. end = this.lines.length - 1;
  359. }
  360. while (y <= end) {
  361. row = y + this.ydisp;
  362. line = this.lines[row];
  363. out = "";
  364. if (y === this.y && (this.ydisp === this.ybase || this.selectMode) && !this.cursorHidden) {
  365. x = this.x;
  366. } else {
  367. x = -Infinity;
  368. }
  369. attr = this.defAttr;
  370. i = 0;
  371. while (i < width) {
  372. data = line[i][0];
  373. ch = line[i][1];
  374. if (data !== attr) {
  375. if (attr !== this.defAttr) {
  376. out += "</span>";
  377. }
  378. if (data !== this.defAttr) {
  379. classes = [];
  380. out += "<span ";
  381. bg = data & 0x1ff;
  382. fg = (data >> 9) & 0x1ff;
  383. flags = data >> 18;
  384. if (flags & 1) {
  385. classes.push("bold");
  386. }
  387. if (flags & 2) {
  388. classes.push("underline");
  389. }
  390. if (flags & 4) {
  391. classes.push("blink");
  392. }
  393. if (flags & 8) {
  394. classes.push("reverse-video");
  395. }
  396. if (flags & 16) {
  397. classes.push("invisible");
  398. }
  399. if (flags & 1 && fg < 8) {
  400. fg += 8;
  401. }
  402. classes.push("bg-color-" + bg);
  403. classes.push("fg-color-" + fg);
  404. out += "class=\"";
  405. out += classes.join(" ");
  406. out += "\">";
  407. }
  408. }
  409. if (i === x) {
  410. out += "<span class=\"" + (this.cursorState ? "reverse-video " : "") + "cursor\">";
  411. }
  412. if (ch.length > 1) {
  413. out += ch;
  414. } else {
  415. switch (ch) {
  416. case "&":
  417. out += "&amp;";
  418. break;
  419. case "<":
  420. out += "&lt;";
  421. break;
  422. case ">":
  423. out += "&gt;";
  424. break;
  425. default:
  426. if (ch <= " ") {
  427. out += "&nbsp;";
  428. } else {
  429. if (("\uff00" < ch && ch < "\uffef")) {
  430. i++;
  431. }
  432. out += ch;
  433. }
  434. }
  435. }
  436. if (i === x) {
  437. out += "</span>";
  438. }
  439. attr = data;
  440. i++;
  441. }
  442. if (attr !== this.defAttr) {
  443. out += "</span>";
  444. }
  445. this.children[y].innerHTML = out;
  446. y++;
  447. }
  448. return parent != null ? parent.appendChild(this.element) : void 0;
  449. };
  450. Terminal.prototype._cursorBlink = function() {
  451. var cursor;
  452. this.cursorState ^= 1;
  453. cursor = this.element.querySelector(".cursor");
  454. if (!cursor) {
  455. return;
  456. }
  457. if (cursor.classList.contains("reverse-video")) {
  458. return cursor.classList.remove("reverse-video");
  459. } else {
  460. return cursor.classList.add("reverse-video");
  461. }
  462. };
  463. Terminal.prototype.showCursor = function() {
  464. if (!this.cursorState) {
  465. this.cursorState = 1;
  466. return this.refresh(this.y, this.y);
  467. }
  468. };
  469. Terminal.prototype.startBlink = function() {
  470. if (!this.cursorBlink) {
  471. return;
  472. }
  473. this._blinker = (function(_this) {
  474. return function() {
  475. return _this._cursorBlink();
  476. };
  477. })(this);
  478. return this.t_blink = setInterval(this._blinker, 500);
  479. };
  480. Terminal.prototype.refreshBlink = function() {
  481. if (!this.cursorBlink) {
  482. return;
  483. }
  484. clearInterval(this.t_blink);
  485. return this.t_blink = setInterval(this._blinker, 500);
  486. };
  487. Terminal.prototype.scroll = function() {
  488. var row;
  489. if (++this.ybase === this.scrollback) {
  490. this.ybase = this.ybase / 2 | 0;
  491. this.lines = this.lines.slice(-(this.ybase + this.rows) + 1);
  492. }
  493. this.ydisp = this.ybase;
  494. row = this.ybase + this.rows - 1;
  495. row -= this.rows - 1 - this.scrollBottom;
  496. if (row === this.lines.length) {
  497. this.lines.push(this.blankLine());
  498. } else {
  499. this.lines.splice(row, 0, this.blankLine());
  500. }
  501. if (this.scrollTop !== 0) {
  502. if (this.ybase !== 0) {
  503. this.ybase--;
  504. this.ydisp = this.ybase;
  505. }
  506. this.lines.splice(this.ybase + this.scrollTop, 1);
  507. }
  508. this.updateRange(this.scrollTop);
  509. return this.updateRange(this.scrollBottom);
  510. };
  511. Terminal.prototype.scrollDisp = function(disp) {
  512. this.ydisp += disp;
  513. if (this.ydisp > this.ybase) {
  514. this.ydisp = this.ybase;
  515. } else {
  516. if (this.ydisp < 0) {
  517. this.ydisp = 0;
  518. }
  519. }
  520. return this.refresh(0, this.rows - 1);
  521. };
  522. Terminal.prototype.write = function(data) {
  523. var ch, cs, i, j, l, pt, valid, _ref;
  524. this.refreshStart = this.y;
  525. this.refreshEnd = this.y;
  526. if (this.ybase !== this.ydisp) {
  527. this.ydisp = this.ybase;
  528. this.maxRange();
  529. }
  530. i = 0;
  531. l = data.length;
  532. while (i < l) {
  533. ch = data[i];
  534. switch (this.state) {
  535. case State.normal:
  536. switch (ch) {
  537. case "\x07":
  538. this.bell();
  539. break;
  540. case "\n":
  541. case "\x0b":
  542. case "\x0c":
  543. if (this.convertEol) {
  544. this.x = 0;
  545. }
  546. this.y++;
  547. if (this.y > this.scrollBottom) {
  548. this.y--;
  549. this.scroll();
  550. }
  551. break;
  552. case "\r":
  553. this.x = 0;
  554. break;
  555. case "\b":
  556. if (this.x > 0) {
  557. this.x--;
  558. }
  559. break;
  560. case "\t":
  561. this.x = this.nextStop();
  562. break;
  563. case "\x0e":
  564. this.setgLevel(1);
  565. break;
  566. case "\x0f":
  567. this.setgLevel(0);
  568. break;
  569. case "\x1b":
  570. this.state = State.escaped;
  571. break;
  572. default:
  573. if (ch >= " ") {
  574. if ((_ref = this.charset) != null ? _ref[ch] : void 0) {
  575. ch = this.charset[ch];
  576. }
  577. if (this.x >= this.cols) {
  578. this.x = 0;
  579. this.y++;
  580. if (this.y > this.scrollBottom) {
  581. this.y--;
  582. this.scroll();
  583. }
  584. }
  585. this.lines[this.y + this.ybase][this.x] = [this.curAttr, ch];
  586. this.x++;
  587. this.updateRange(this.y);
  588. if (("\uff00" < ch && ch < "\uffef")) {
  589. j = this.y + this.ybase;
  590. if (this.cols < 2 || this.x >= this.cols) {
  591. this.lines[j][this.x - 1] = [this.curAttr, " "];
  592. break;
  593. }
  594. this.lines[j][this.x] = [this.curAttr, " "];
  595. this.x++;
  596. }
  597. }
  598. }
  599. break;
  600. case State.escaped:
  601. switch (ch) {
  602. case "[":
  603. this.params = [];
  604. this.currentParam = 0;
  605. this.state = State.csi;
  606. break;
  607. case "]":
  608. this.params = [];
  609. this.currentParam = 0;
  610. this.state = State.osc;
  611. break;
  612. case "P":
  613. this.params = [];
  614. this.currentParam = 0;
  615. this.state = State.dcs;
  616. break;
  617. case "_":
  618. this.state = State.ignore;
  619. break;
  620. case "^":
  621. this.state = State.ignore;
  622. break;
  623. case "c":
  624. this.reset();
  625. break;
  626. case "E":
  627. this.x = 0;
  628. this.index();
  629. break;
  630. case "D":
  631. this.index();
  632. break;
  633. case "M":
  634. this.reverseIndex();
  635. break;
  636. case "%":
  637. this.setgLevel(0);
  638. this.setgCharset(0, Terminal.prototype.charsets.US);
  639. this.state = State.normal;
  640. i++;
  641. break;
  642. case "(":
  643. case ")":
  644. case "*":
  645. case "+":
  646. case "-":
  647. case ".":
  648. switch (ch) {
  649. case "(":
  650. this.gcharset = 0;
  651. break;
  652. case ")":
  653. case "-":
  654. this.gcharset = 1;
  655. break;
  656. case "*":
  657. case ".":
  658. this.gcharset = 2;
  659. break;
  660. case "+":
  661. this.gcharset = 3;
  662. }
  663. this.state = State.charset;
  664. break;
  665. case "/":
  666. this.gcharset = 3;
  667. this.state = State.charset;
  668. i--;
  669. break;
  670. case "n":
  671. this.setgLevel(2);
  672. break;
  673. case "o":
  674. this.setgLevel(3);
  675. break;
  676. case "|":
  677. this.setgLevel(3);
  678. break;
  679. case "}":
  680. this.setgLevel(2);
  681. break;
  682. case "~":
  683. this.setgLevel(1);
  684. break;
  685. case "7":
  686. this.saveCursor();
  687. this.state = State.normal;
  688. break;
  689. case "8":
  690. this.restoreCursor();
  691. this.state = State.normal;
  692. break;
  693. case "#":
  694. this.state = State.normal;
  695. i++;
  696. break;
  697. case "H":
  698. this.tabSet();
  699. break;
  700. case "=":
  701. this.applicationKeypad = true;
  702. this.state = State.normal;
  703. break;
  704. case ">":
  705. this.applicationKeypad = false;
  706. this.state = State.normal;
  707. break;
  708. default:
  709. this.state = State.normal;
  710. console.log("Unknown ESC control:", ch);
  711. }
  712. break;
  713. case State.charset:
  714. switch (ch) {
  715. case "0":
  716. cs = Terminal.prototype.charsets.SCLD;
  717. break;
  718. case "A":
  719. cs = Terminal.prototype.charsets.UK;
  720. break;
  721. case "B":
  722. cs = Terminal.prototype.charsets.US;
  723. break;
  724. case "4":
  725. cs = Terminal.prototype.charsets.Dutch;
  726. break;
  727. case "C":
  728. case "5":
  729. cs = Terminal.prototype.charsets.Finnish;
  730. break;
  731. case "R":
  732. cs = Terminal.prototype.charsets.French;
  733. break;
  734. case "Q":
  735. cs = Terminal.prototype.charsets.FrenchCanadian;
  736. break;
  737. case "K":
  738. cs = Terminal.prototype.charsets.German;
  739. break;
  740. case "Y":
  741. cs = Terminal.prototype.charsets.Italian;
  742. break;
  743. case "E":
  744. case "6":
  745. cs = Terminal.prototype.charsets.NorwegianDanish;
  746. break;
  747. case "Z":
  748. cs = Terminal.prototype.charsets.Spanish;
  749. break;
  750. case "H":
  751. case "7":
  752. cs = Terminal.prototype.charsets.Swedish;
  753. break;
  754. case "=":
  755. cs = Terminal.prototype.charsets.Swiss;
  756. break;
  757. case "/":
  758. cs = Terminal.prototype.charsets.ISOLatin;
  759. i++;
  760. break;
  761. default:
  762. cs = Terminal.prototype.charsets.US;
  763. }
  764. this.setgCharset(this.gcharset, cs);
  765. this.gcharset = null;
  766. this.state = State.normal;
  767. break;
  768. case State.osc:
  769. if (ch === "\x1b" || ch === "\x07") {
  770. if (ch === "\x1b") {
  771. i++;
  772. }
  773. this.params.push(this.currentParam);
  774. switch (this.params[0]) {
  775. case 0:
  776. case 1:
  777. case 2:
  778. if (this.params[1]) {
  779. this.title = this.params[1] + " - ƸӜƷ butterfly";
  780. this.handleTitle(this.title);
  781. }
  782. }
  783. this.params = [];
  784. this.currentParam = 0;
  785. this.state = State.normal;
  786. } else {
  787. if (!this.params.length) {
  788. if (ch >= "0" && ch <= "9") {
  789. this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48;
  790. } else if (ch === ";") {
  791. this.params.push(this.currentParam);
  792. this.currentParam = "";
  793. }
  794. } else {
  795. this.currentParam += ch;
  796. }
  797. }
  798. break;
  799. case State.csi:
  800. if (ch === "?" || ch === ">" || ch === "!") {
  801. this.prefix = ch;
  802. break;
  803. }
  804. if (ch >= "0" && ch <= "9") {
  805. this.currentParam = this.currentParam * 10 + ch.charCodeAt(0) - 48;
  806. break;
  807. }
  808. if (ch === "$" || ch === "\"" || ch === " " || ch === "'") {
  809. break;
  810. }
  811. this.params.push(this.currentParam);
  812. this.currentParam = 0;
  813. if (ch === ";") {
  814. break;
  815. }
  816. this.state = State.normal;
  817. switch (ch) {
  818. case "A":
  819. this.cursorUp(this.params);
  820. break;
  821. case "B":
  822. this.cursorDown(this.params);
  823. break;
  824. case "C":
  825. this.cursorForward(this.params);
  826. break;
  827. case "D":
  828. this.cursorBackward(this.params);
  829. break;
  830. case "H":
  831. this.cursorPos(this.params);
  832. break;
  833. case "J":
  834. this.eraseInDisplay(this.params);
  835. break;
  836. case "K":
  837. this.eraseInLine(this.params);
  838. break;
  839. case "m":
  840. if (!this.prefix) {
  841. this.charAttributes(this.params);
  842. }
  843. break;
  844. case "n":
  845. if (!this.prefix) {
  846. this.deviceStatus(this.params);
  847. }
  848. break;
  849. case "@":
  850. this.insertChars(this.params);
  851. break;
  852. case "E":
  853. this.cursorNextLine(this.params);
  854. break;
  855. case "F":
  856. this.cursorPrecedingLine(this.params);
  857. break;
  858. case "G":
  859. this.cursorCharAbsolute(this.params);
  860. break;
  861. case "L":
  862. this.insertLines(this.params);
  863. break;
  864. case "M":
  865. this.deleteLines(this.params);
  866. break;
  867. case "P":
  868. this.deleteChars(this.params);
  869. break;
  870. case "X":
  871. this.eraseChars(this.params);
  872. break;
  873. case "`":
  874. this.charPosAbsolute(this.params);
  875. break;
  876. case "a":
  877. this.HPositionRelative(this.params);
  878. break;
  879. case "c":
  880. this.sendDeviceAttributes(this.params);
  881. break;
  882. case "d":
  883. this.linePosAbsolute(this.params);
  884. break;
  885. case "e":
  886. this.VPositionRelative(this.params);
  887. break;
  888. case "f":
  889. this.HVPosition(this.params);
  890. break;
  891. case "h":
  892. this.setMode(this.params);
  893. break;
  894. case "l":
  895. this.resetMode(this.params);
  896. break;
  897. case "r":
  898. this.setScrollRegion(this.params);
  899. break;
  900. case "s":
  901. this.saveCursor(this.params);
  902. break;
  903. case "u":
  904. this.restoreCursor(this.params);
  905. break;
  906. case "I":
  907. this.cursorForwardTab(this.params);
  908. break;
  909. case "S":
  910. this.scrollUp(this.params);
  911. break;
  912. case "T":
  913. if (this.params.length < 2 && !this.prefix) {
  914. this.scrollDown(this.params);
  915. }
  916. break;
  917. case "Z":
  918. this.cursorBackwardTab(this.params);
  919. break;
  920. case "b":
  921. this.repeatPrecedingCharacter(this.params);
  922. break;
  923. case "g":
  924. this.tabClear(this.params);
  925. break;
  926. case "p":
  927. if (this.prefix === '!') {
  928. this.softReset(this.params);
  929. }
  930. break;
  931. default:
  932. console.error("Unknown CSI code: %s.", ch);
  933. }
  934. this.prefix = "";
  935. break;
  936. case State.dcs:
  937. if (ch === "\x1b" || ch === "\x07") {
  938. if (ch === "\x1b") {
  939. i++;
  940. }
  941. switch (this.prefix) {
  942. case "":
  943. break;
  944. case "$q":
  945. pt = this.currentParam;
  946. valid = false;
  947. switch (pt) {
  948. case "\"q":
  949. pt = "0\"q";
  950. break;
  951. case "\"p":
  952. pt = "61\"p";
  953. break;
  954. case "r":
  955. pt = "" + (this.scrollTop + 1) + ";" + (this.scrollBottom + 1) + "r";
  956. break;
  957. case "m":
  958. pt = "0m";
  959. break;
  960. default:
  961. console.error("Unknown DCS Pt: %s.", pt);
  962. pt = "";
  963. }
  964. this.send("\x1bP" + +valid + "$r" + pt + "\x1b\\");
  965. break;
  966. case "+q":
  967. pt = this.currentParam;
  968. valid = false;
  969. this.send("\x1bP" + +valid + "+r" + pt + "\x1b\\");
  970. break;
  971. default:
  972. console.error("Unknown DCS prefix: %s.", this.prefix);
  973. }
  974. this.currentParam = 0;
  975. this.prefix = "";
  976. this.state = State.normal;
  977. } else if (!this.currentParam) {
  978. if (!this.prefix && ch !== "$" && ch !== "+") {
  979. this.currentParam = ch;
  980. } else if (this.prefix.length === 2) {
  981. this.currentParam = ch;
  982. } else {
  983. this.prefix += ch;
  984. }
  985. } else {
  986. this.currentParam += ch;
  987. }
  988. break;
  989. case State.ignore:
  990. if (ch === "\x1b" || ch === "\x07") {
  991. if (ch === "\x1b") {
  992. i++;
  993. }
  994. this.state = State.normal;
  995. }
  996. }
  997. i++;
  998. }
  999. this.updateRange(this.y);
  1000. return this.refresh(this.refreshStart, this.refreshEnd);
  1001. };
  1002. Terminal.prototype.writeln = function(data) {
  1003. return this.write("" + data + "\r\n");
  1004. };
  1005. Terminal.prototype.keyDown = function(ev) {
  1006. var id, key, t, _ref;
  1007. if (ev.keyCode > 15 && ev.keyCode < 19) {
  1008. return true;
  1009. }
  1010. if ((ev.shiftKey || ev.ctrlKey) && ev.keyCode === 45) {
  1011. return true;
  1012. }
  1013. if ((ev.shiftKey && ev.ctrlKey) && ((_ref = ev.keyCode) === 67 || _ref === 86)) {
  1014. return true;
  1015. }
  1016. if (ev.altKey && ev.keyCode === 90 && !this.skipNextKey) {
  1017. this.skipNextKey = true;
  1018. this.element.classList.add('skip');
  1019. return cancel(ev);
  1020. }
  1021. if (this.skipNextKey) {
  1022. this.skipNextKey = false;
  1023. this.element.classList.remove('skip');
  1024. return true;
  1025. }
  1026. switch (ev.keyCode) {
  1027. case 8:
  1028. key = ev.altKey ? "\x1b" : "";
  1029. if (ev.shiftKey) {
  1030. key += "\x08";
  1031. break;
  1032. }
  1033. key += "\x7f";
  1034. break;
  1035. case 9:
  1036. if (ev.shiftKey) {
  1037. key = "\x1b[Z";
  1038. break;
  1039. }
  1040. key = "\t";
  1041. break;
  1042. case 13:
  1043. key = "\r";
  1044. break;
  1045. case 27:
  1046. key = "\x1b";
  1047. break;
  1048. case 37:
  1049. if (this.applicationCursor) {
  1050. key = "\x1bOD";
  1051. break;
  1052. }
  1053. key = "\x1b[D";
  1054. break;
  1055. case 39:
  1056. if (this.applicationCursor) {
  1057. key = "\x1bOC";
  1058. break;
  1059. }
  1060. key = "\x1b[C";
  1061. break;
  1062. case 38:
  1063. if (this.applicationCursor) {
  1064. key = "\x1bOA";
  1065. break;
  1066. }
  1067. if (ev.ctrlKey) {
  1068. this.scrollDisp(-1);
  1069. return cancel(ev);
  1070. } else {
  1071. key = "\x1b[A";
  1072. }
  1073. break;
  1074. case 40:
  1075. if (this.applicationCursor) {
  1076. key = "\x1bOB";
  1077. break;
  1078. }
  1079. if (ev.ctrlKey) {
  1080. this.scrollDisp(1);
  1081. return cancel(ev);
  1082. } else {
  1083. key = "\x1b[B";
  1084. }
  1085. break;
  1086. case 46:
  1087. key = "\x1b[3~";
  1088. break;
  1089. case 45:
  1090. key = "\x1b[2~";
  1091. break;
  1092. case 36:
  1093. if (this.applicationKeypad) {
  1094. key = "\x1bOH";
  1095. break;
  1096. }
  1097. key = "\x1bOH";
  1098. break;
  1099. case 35:
  1100. if (this.applicationKeypad) {
  1101. key = "\x1bOF";
  1102. break;
  1103. }
  1104. key = "\x1bOF";
  1105. break;
  1106. case 33:
  1107. if (ev.shiftKey) {
  1108. this.scrollDisp(-(this.rows - 1));
  1109. return cancel(ev);
  1110. } else {
  1111. key = "\x1b[5~";
  1112. }
  1113. break;
  1114. case 34:
  1115. if (ev.shiftKey) {
  1116. this.scrollDisp(this.rows - 1);
  1117. return cancel(ev);
  1118. } else {
  1119. key = "\x1b[6~";
  1120. }
  1121. break;
  1122. case 112:
  1123. key = "\x1bOP";
  1124. break;
  1125. case 113:
  1126. key = "\x1bOQ";
  1127. break;
  1128. case 114:
  1129. key = "\x1bOR";
  1130. break;
  1131. case 115:
  1132. key = "\x1bOS";
  1133. break;
  1134. case 116:
  1135. key = "\x1b[15~";
  1136. break;
  1137. case 117:
  1138. key = "\x1b[17~";
  1139. break;
  1140. case 118:
  1141. key = "\x1b[18~";
  1142. break;
  1143. case 119:
  1144. key = "\x1b[19~";
  1145. break;
  1146. case 120:
  1147. key = "\x1b[20~";
  1148. break;
  1149. case 121:
  1150. key = "\x1b[21~";
  1151. break;
  1152. case 122:
  1153. key = "\x1b[23~";
  1154. break;
  1155. case 123:
  1156. key = "\x1b[24~";
  1157. break;
  1158. default:
  1159. if (ev.ctrlKey) {
  1160. if (ev.keyCode >= 65 && ev.keyCode <= 90) {
  1161. if (ev.keyCode === 67) {
  1162. t = (new Date()).getTime();
  1163. if ((t - this.last_cc) < 75) {
  1164. id = (setTimeout(function() {})) - 6;
  1165. this.write('\r\n --8<------8<-- Sectioned --8<------8<-- \r\n\r\n');
  1166. while (id--) {
  1167. if (id !== this.t_bell && id !== this.t_queue && id !== this.t_blink) {
  1168. clearTimeout(id);
  1169. }
  1170. }
  1171. }
  1172. this.last_cc = t;
  1173. }
  1174. key = String.fromCharCode(ev.keyCode - 64);
  1175. } else if (ev.keyCode === 32) {
  1176. key = String.fromCharCode(0);
  1177. } else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
  1178. key = String.fromCharCode(ev.keyCode - 51 + 27);
  1179. } else if (ev.keyCode === 56) {
  1180. key = String.fromCharCode(127);
  1181. } else if (ev.keyCode === 219) {
  1182. key = String.fromCharCode(27);
  1183. } else {
  1184. if (ev.keyCode === 221) {
  1185. key = String.fromCharCode(29);
  1186. }
  1187. }
  1188. } else if ((ev.altKey && __indexOf.call(navigator.platform, 'Mac') < 0) || (ev.metaKey && __indexOf.call(navigator.platform, 'Mac') >= 0)) {
  1189. if (ev.keyCode >= 65 && ev.keyCode <= 90) {
  1190. key = "\x1b" + String.fromCharCode(ev.keyCode + 32);
  1191. } else if (ev.keyCode === 192) {
  1192. key = "\x1b`";
  1193. } else {
  1194. if (ev.keyCode >= 48 && ev.keyCode <= 57) {
  1195. key = "\x1b" + (ev.keyCode - 48);
  1196. }
  1197. }
  1198. }
  1199. }
  1200. if (ev.keyCode >= 37 && ev.keyCode <= 40) {
  1201. if (ev.ctrlKey) {
  1202. key = key.slice(0, -1) + "1;5" + key.slice(-1);
  1203. } else if (ev.altKey) {
  1204. key = key.slice(0, -1) + "1;3" + key.slice(-1);
  1205. } else if (ev.shiftKey) {
  1206. key = key.slice(0, -1) + "1;4" + key.slice(-1);
  1207. }
  1208. }
  1209. if (!key) {
  1210. return true;
  1211. }
  1212. if (this.prefixMode) {
  1213. this.leavePrefix();
  1214. return cancel(ev);
  1215. }
  1216. if (this.selectMode) {
  1217. this.keySelect(ev, key);
  1218. return cancel(ev);
  1219. }
  1220. this.showCursor();
  1221. this.handler(key);
  1222. return cancel(ev);
  1223. };
  1224. Terminal.prototype.setgLevel = function(g) {
  1225. this.glevel = g;
  1226. return this.charset = this.charsets[g];
  1227. };
  1228. Terminal.prototype.setgCharset = function(g, charset) {
  1229. this.charsets[g] = charset;
  1230. if (this.glevel === g) {
  1231. return this.charset = charset;
  1232. }
  1233. };
  1234. Terminal.prototype.keyPress = function(ev) {
  1235. var key;
  1236. if (this.skipNextKey === false) {
  1237. this.skipNextKey = null;
  1238. return true;
  1239. }
  1240. cancel(ev);
  1241. if (ev.charCode) {
  1242. key = ev.charCode;
  1243. } else if (ev.which == null) {
  1244. key = ev.keyCode;
  1245. } else if (ev.which !== 0 && ev.charCode !== 0) {
  1246. key = ev.which;
  1247. } else {
  1248. return false;
  1249. }
  1250. if (!key || ev.ctrlKey || ev.altKey || ev.metaKey) {
  1251. return false;
  1252. }
  1253. key = String.fromCharCode(key);
  1254. this.showCursor();
  1255. this.handler(key);
  1256. return false;
  1257. };
  1258. Terminal.prototype.send = function(data) {
  1259. if (!this.queue) {
  1260. this.t_queue = setTimeout(((function(_this) {
  1261. return function() {
  1262. _this.handler(_this.queue);
  1263. return _this.queue = "";
  1264. };
  1265. })(this)), 1);
  1266. }
  1267. return this.queue += data;
  1268. };
  1269. Terminal.prototype.bell = function() {
  1270. if (!this.visualBell) {
  1271. return;
  1272. }
  1273. this.element.classList.add("bell");
  1274. return this.t_bell = setTimeout(((function(_this) {
  1275. return function() {
  1276. return _this.element.classList.remove("bell");
  1277. };
  1278. })(this)), this.visualBell);
  1279. };
  1280. Terminal.prototype.resize = function() {
  1281. var ch, el, i, j, line, old_cols, old_rows, term_size;
  1282. old_cols = this.cols;
  1283. old_rows = this.rows;
  1284. this.compute_char_size();
  1285. term_size = this.parent.getBoundingClientRect();
  1286. this.cols = Math.floor(term_size.width / this.char_size.width);
  1287. this.rows = Math.floor(term_size.height / this.char_size.height);
  1288. if (old_cols === this.cols && old_rows === this.rows) {
  1289. return;
  1290. }
  1291. this.ctl('Resize', this.cols, this.rows);
  1292. if (old_cols < this.cols) {
  1293. ch = [this.defAttr, " "];
  1294. i = this.lines.length;
  1295. while (i--) {
  1296. while (this.lines[i].length < this.cols) {
  1297. this.lines[i].push(ch);
  1298. }
  1299. }
  1300. } else if (old_cols > this.cols) {
  1301. i = this.lines.length;
  1302. while (i--) {
  1303. while (this.lines[i].length > this.cols) {
  1304. this.lines[i].pop();
  1305. }
  1306. }
  1307. }
  1308. this.setupStops(old_cols);
  1309. j = old_rows;
  1310. if (j < this.rows) {
  1311. el = this.element;
  1312. while (j++ < this.rows) {
  1313. if (this.lines.length < this.rows + this.ybase) {
  1314. this.lines.push(this.blankLine());
  1315. }
  1316. if (this.children.length < this.rows) {
  1317. line = this.document.createElement("div");
  1318. line.className = 'line';
  1319. line.style.height = this.char_size.height + 'px';
  1320. el.appendChild(line);
  1321. this.children.push(line);
  1322. }
  1323. }
  1324. } else if (j > this.rows) {
  1325. while (j-- > this.rows) {
  1326. if (this.lines.length > this.rows + this.ybase) {
  1327. this.lines.pop();
  1328. }
  1329. if (this.children.length > this.rows) {
  1330. el = this.children.pop();
  1331. if (!el) {
  1332. continue;
  1333. }
  1334. el.parentNode.removeChild(el);
  1335. }
  1336. }
  1337. }
  1338. if (this.y >= this.rows) {
  1339. this.y = this.rows - 1;
  1340. }
  1341. if (this.x >= this.cols) {
  1342. this.x = this.cols - 1;
  1343. }
  1344. this.scrollTop = 0;
  1345. this.scrollBottom = this.rows - 1;
  1346. this.refresh(0, this.rows - 1);
  1347. return this.normal = null;
  1348. };
  1349. Terminal.prototype.updateRange = function(y) {
  1350. if (y < this.refreshStart) {
  1351. this.refreshStart = y;
  1352. }
  1353. if (y > this.refreshEnd) {
  1354. return this.refreshEnd = y;
  1355. }
  1356. };
  1357. Terminal.prototype.maxRange = function() {
  1358. this.refreshStart = 0;
  1359. return this.refreshEnd = this.rows - 1;
  1360. };
  1361. Terminal.prototype.setupStops = function(i) {
  1362. var _results;
  1363. if (i != null) {
  1364. if (!this.tabs[i]) {
  1365. i = this.prevStop(i);
  1366. }
  1367. } else {
  1368. this.tabs = {};
  1369. i = 0;
  1370. }
  1371. _results = [];
  1372. while (i < this.cols) {
  1373. this.tabs[i] = true;
  1374. _results.push(i += 8);
  1375. }
  1376. return _results;
  1377. };
  1378. Terminal.prototype.prevStop = function(x) {
  1379. if (x == null) {
  1380. x = this.x;
  1381. }
  1382. while (!this.tabs[--x] && x > 0) {
  1383. 1;
  1384. }
  1385. if (x >= this.cols) {
  1386. return this.cols - 1;
  1387. } else {
  1388. if (x < 0) {
  1389. return 0;
  1390. } else {
  1391. return x;
  1392. }
  1393. }
  1394. };
  1395. Terminal.prototype.nextStop = function(x) {
  1396. if (x == null) {
  1397. x = this.x;
  1398. }
  1399. while (!this.tabs[++x] && x < this.cols) {
  1400. 1;
  1401. }
  1402. if (x >= this.cols) {
  1403. return this.cols - 1;
  1404. } else {
  1405. if (x < 0) {
  1406. return 0;
  1407. } else {
  1408. return x;
  1409. }
  1410. }
  1411. };
  1412. Terminal.prototype.eraseRight = function(x, y) {
  1413. var ch, line;
  1414. line = this.lines[this.ybase + y];
  1415. ch = [this.eraseAttr(), " "];
  1416. while (x < this.cols) {
  1417. line[x] = ch;
  1418. x++;
  1419. }
  1420. return this.updateRange(y);
  1421. };
  1422. Terminal.prototype.eraseLeft = function(x, y) {
  1423. var ch, line;
  1424. line = this.lines[this.ybase + y];
  1425. ch = [this.eraseAttr(), " "];
  1426. x++;
  1427. while (x--) {
  1428. line[x] = ch;
  1429. }
  1430. return this.updateRange(y);
  1431. };
  1432. Terminal.prototype.eraseLine = function(y) {
  1433. return this.eraseRight(0, y);
  1434. };
  1435. Terminal.prototype.blankLine = function(cur) {
  1436. var attr, ch, i, line;
  1437. attr = (cur ? this.eraseAttr() : this.defAttr);
  1438. ch = [attr, " "];
  1439. line = [];
  1440. i = 0;
  1441. while (i < this.cols) {
  1442. line[i] = ch;
  1443. i++;
  1444. }
  1445. return line;
  1446. };
  1447. Terminal.prototype.ch = function(cur) {
  1448. if (cur) {
  1449. return [this.eraseAttr(), " "];
  1450. } else {
  1451. return [this.defAttr, " "];
  1452. }
  1453. };
  1454. Terminal.prototype.isterm = function(term) {
  1455. return ("" + this.termName).indexOf(term) === 0;
  1456. };
  1457. Terminal.prototype.handler = function(data) {
  1458. return this.out(data);
  1459. };
  1460. Terminal.prototype.handleTitle = function(title) {
  1461. return document.title = title;
  1462. };
  1463. Terminal.prototype.index = function() {
  1464. this.y++;
  1465. if (this.y > this.scrollBottom) {
  1466. this.y--;
  1467. this.scroll();
  1468. }
  1469. return this.state = State.normal;
  1470. };
  1471. Terminal.prototype.reverseIndex = function() {
  1472. var j;
  1473. this.y--;
  1474. if (this.y < this.scrollTop) {
  1475. this.y++;
  1476. this.lines.splice(this.y + this.ybase, 0, this.blankLine(true));
  1477. j = this.rows - 1 - this.scrollBottom;
  1478. this.lines.splice(this.rows - 1 + this.ybase - j + 1, 1);
  1479. this.updateRange(this.scrollTop);
  1480. this.updateRange(this.scrollBottom);
  1481. }
  1482. return this.state = State.normal;
  1483. };
  1484. Terminal.prototype.reset = function() {
  1485. this.reset_vars();
  1486. return this.refresh(0, this.rows - 1);
  1487. };
  1488. Terminal.prototype.tabSet = function() {
  1489. this.tabs[this.x] = true;
  1490. return this.state = State.normal;
  1491. };
  1492. Terminal.prototype.cursorUp = function(params) {
  1493. var param;
  1494. param = params[0];
  1495. if (param < 1) {
  1496. param = 1;
  1497. }
  1498. this.y -= param;
  1499. if (this.y < 0) {
  1500. return this.y = 0;
  1501. }
  1502. };
  1503. Terminal.prototype.cursorDown = function(params) {
  1504. var param;
  1505. param = params[0];
  1506. if (param < 1) {
  1507. param = 1;
  1508. }
  1509. this.y += param;
  1510. if (this.y >= this.rows) {
  1511. return this.y = this.rows - 1;
  1512. }
  1513. };
  1514. Terminal.prototype.cursorForward = function(params) {
  1515. var param;
  1516. param = params[0];
  1517. if (param < 1) {
  1518. param = 1;
  1519. }
  1520. this.x += param;
  1521. if (this.x >= this.cols) {
  1522. return this.x = this.cols - 1;
  1523. }
  1524. };
  1525. Terminal.prototype.cursorBackward = function(params) {
  1526. var param;
  1527. param = params[0];
  1528. if (param < 1) {
  1529. param = 1;
  1530. }
  1531. this.x -= param;
  1532. if (this.x < 0) {
  1533. return this.x = 0;
  1534. }
  1535. };
  1536. Terminal.prototype.cursorPos = function(params) {
  1537. var col, row;
  1538. row = params[0] - 1;
  1539. if (params.length >= 2) {
  1540. col = params[1] - 1;
  1541. } else {
  1542. col = 0;
  1543. }
  1544. if (row < 0) {
  1545. row = 0;
  1546. } else {
  1547. if (row >= this.rows) {
  1548. row = this.rows - 1;
  1549. }
  1550. }
  1551. if (col < 0) {
  1552. col = 0;
  1553. } else {
  1554. if (col >= this.cols) {
  1555. col = this.cols - 1;
  1556. }
  1557. }
  1558. this.x = col;
  1559. return this.y = row;
  1560. };
  1561. Terminal.prototype.eraseInDisplay = function(params) {
  1562. var j, _results, _results1, _results2;
  1563. switch (params[0]) {
  1564. case 0:
  1565. this.eraseRight(this.x, this.y);
  1566. j = this.y + 1;
  1567. _results = [];
  1568. while (j < this.rows) {
  1569. this.eraseLine(j);
  1570. _results.push(j++);
  1571. }
  1572. return _results;
  1573. break;
  1574. case 1:
  1575. this.eraseLeft(this.x, this.y);
  1576. j = this.y;
  1577. _results1 = [];
  1578. while (j--) {
  1579. _results1.push(this.eraseLine(j));
  1580. }
  1581. return _results1;
  1582. break;
  1583. case 2:
  1584. j = this.rows;
  1585. _results2 = [];
  1586. while (j--) {
  1587. _results2.push(this.eraseLine(j));
  1588. }
  1589. return _results2;
  1590. }
  1591. };
  1592. Terminal.prototype.eraseInLine = function(params) {
  1593. switch (params[0]) {
  1594. case 0:
  1595. return this.eraseRight(this.x, this.y);
  1596. case 1:
  1597. return this.eraseLeft(this.x, this.y);
  1598. case 2:
  1599. return this.eraseLine(this.y);
  1600. }
  1601. };
  1602. Terminal.prototype.charAttributes = function(params) {
  1603. var bg, fg, flags, i, l, p;
  1604. if (params.length === 1 && params[0] === 0) {
  1605. this.curAttr = this.defAttr;
  1606. return;
  1607. }
  1608. flags = this.curAttr >> 18;
  1609. fg = (this.curAttr >> 9) & 0x1ff;
  1610. bg = this.curAttr & 0x1ff;
  1611. l = params.length;
  1612. i = 0;
  1613. while (i < l) {
  1614. p = params[i];
  1615. if (p >= 30 && p <= 37) {
  1616. fg = p - 30;
  1617. } else if (p >= 40 && p <= 47) {
  1618. bg = p - 40;
  1619. } else if (p >= 90 && p <= 97) {
  1620. p += 8;
  1621. fg = p - 90;
  1622. } else if (p >= 100 && p <= 107) {
  1623. p += 8;
  1624. bg = p - 100;
  1625. } else if (p === 0) {
  1626. flags = this.defAttr >> 18;
  1627. fg = (this.defAttr >> 9) & 0x1ff;
  1628. bg = this.defAttr & 0x1ff;
  1629. } else if (p === 1) {
  1630. flags |= 1;
  1631. } else if (p === 4) {
  1632. flags |= 2;
  1633. } else if (p === 5) {
  1634. flags |= 4;
  1635. } else if (p === 7) {
  1636. flags |= 8;
  1637. } else if (p === 8) {
  1638. flags |= 16;
  1639. } else if (p === 22) {
  1640. flags &= ~1;
  1641. } else if (p === 24) {
  1642. flags &= ~2;
  1643. } else if (p === 25) {
  1644. flags &= ~4;
  1645. } else if (p === 27) {
  1646. flags &= ~8;
  1647. } else if (p === 28) {
  1648. flags &= ~16;
  1649. } else if (p === 39) {
  1650. fg = (this.defAttr >> 9) & 0x1ff;
  1651. } else if (p === 49) {
  1652. bg = this.defAttr & 0x1ff;
  1653. } else if (p === 38) {
  1654. if (params[i + 1] === 2) {
  1655. i += 2;
  1656. fg = "#" + params[i] & 0xff + params[i + 1] & 0xff + params[i + 2] & 0xff;
  1657. i += 2;
  1658. } else if (params[i + 1] === 5) {
  1659. i += 2;
  1660. fg = params[i] & 0xff;
  1661. }
  1662. } else if (p === 48) {
  1663. if (params[i + 1] === 2) {
  1664. i += 2;
  1665. bg = "#" + params[i] & 0xff + params[i + 1] & 0xff + params[i + 2] & 0xff;
  1666. i += 2;
  1667. } else if (params[i + 1] === 5) {
  1668. i += 2;
  1669. bg = params[i] & 0xff;
  1670. }
  1671. } else if (p === 100) {
  1672. fg = (this.defAttr >> 9) & 0x1ff;
  1673. bg = this.defAttr & 0x1ff;
  1674. } else {
  1675. console.error("Unknown SGR attribute: %d.", p);
  1676. }
  1677. i++;
  1678. }

Large files files are truncated, but you can click here to view the full file