UNPKG

1.13 kBJavaScriptView Raw
1'use strict';
2
3// if bold is broken, we can't
4// use it in the terminal.
5function isBoldBroken() {
6 var el = document.createElement('span');
7 el.innerHTML = 'hello world';
8 document.body.appendChild(el);
9 var w1 = el.scrollWidth;
10 el.style.fontWeight = 'bold';
11 var w2 = el.scrollWidth;
12 document.body.removeChild(el);
13 return w1 !== w2;
14}
15
16module.exports = function (Terminal) {
17 /**
18 * Open Terminal
19 */
20
21 Terminal.prototype.open = function() {
22 var self = this,
23 i = 0,
24 div;
25
26 this.element = document.createElement('div');
27 this.element.className = 'terminal';
28 this.children = [];
29
30 for (; i < this.rows; i++) {
31 div = document.createElement('div');
32 this.element.appendChild(div);
33 this.children.push(div);
34 }
35
36 this.refresh(0, this.rows - 1);
37
38 // XXX - hack, move this somewhere else.
39 if (Terminal.brokenBold === null) {
40 Terminal.brokenBold = isBoldBroken();
41 }
42
43 // sync default bg/fg colors
44 this.element.style.backgroundColor = Terminal.defaultColors.bg;
45 this.element.style.color = Terminal.defaultColors.fg;
46 };
47};