Started implementing theming.

This commit is contained in:
paris
2014-03-24 17:56:49 +00:00
parent 7c6d4d4e3c
commit 3d680e1cb7
3 changed files with 1310 additions and 326 deletions
+4 -2
View File
@@ -1,5 +1,8 @@
var terminalContainer = document.getElementById('terminal-container'), var terminalContainer = document.getElementById('terminal-container'),
term = new Terminal({geometry: [95, 37]}); term = new Terminal({
geometry: [95, 37],
theme: 'crazy'
});
term.prompt = function () { term.prompt = function () {
term.write('> '); term.write('> ');
@@ -12,7 +15,6 @@ term.writeln('');
term.prompt(); term.prompt();
term.on('key', function (key, ev) { term.on('key', function (key, ev) {
console.log(this, key, ev);
if (ev.keyIdentifier == 'Enter') { if (ev.keyIdentifier == 'Enter') {
term.writeln(''); term.writeln('');
term.prompt(); term.prompt();
+1296 -256
View File
File diff suppressed because it is too large Load Diff
+10 -68
View File
@@ -363,6 +363,7 @@ Terminal.vcolors = (function() {
Terminal.defaults = { Terminal.defaults = {
colors: Terminal.colors, colors: Terminal.colors,
theme: 'default',
convertEol: false, convertEol: false,
termName: 'xterm', termName: 'xterm',
geometry: [80, 24], geometry: [80, 24],
@@ -372,7 +373,6 @@ Terminal.defaults = {
scrollback: 1000, scrollback: 1000,
screenKeys: false, screenKeys: false,
debug: false, debug: false,
useStyle: false,
cancelEvents: false cancelEvents: false
// programFeatures: false, // programFeatures: false,
// focusKeys: false, // focusKeys: false,
@@ -452,10 +452,6 @@ Terminal.prototype.initGlobal = function() {
if (this.isIpad || this.isIphone) { if (this.isIpad || this.isIphone) {
Terminal.fixIpad(document); Terminal.fixIpad(document);
} }
if (this.useStyle) {
Terminal.insertStyle(document, this.colors[256], this.colors[257]);
}
}; };
/** /**
@@ -603,52 +599,6 @@ Terminal.fixIpad = function(document) {
}, 1000); }, 1000);
}; };
/**
* Insert a default style
*/
Terminal.insertStyle = function(document, bg, fg) {
var style = document.getElementById('term-style');
if (style) return;
var head = document.getElementsByTagName('head')[0];
if (!head) return;
var style = document.createElement('style');
style.id = 'term-style';
// textContent doesn't work well with IE for <style> elements.
style.innerHTML = ''
+ '.terminal {\n'
+ ' float: left;\n'
+ ' border: ' + bg + ' solid 5px;\n'
+ ' font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;\n'
+ ' font-size: 11px;\n'
+ ' color: ' + fg + ';\n'
+ ' background: ' + bg + ';\n'
+ '}\n'
+ '\n'
+ '.terminal-cursor {\n'
+ ' color: ' + bg + ';\n'
+ ' background: ' + fg + ';\n'
+ '}\n';
// var out = '';
// each(Terminal.colors, function(color, i) {
// if (i === 256) {
// out += '\n.term-bg-color-default { background-color: ' + color + '; }';
// }
// if (i === 257) {
// out += '\n.term-fg-color-default { color: ' + color + '; }';
// }
// out += '\n.term-bg-color-' + i + ' { background-color: ' + color + '; }';
// out += '\n.term-fg-color-' + i + ' { color: ' + color + '; }';
// });
// style.innerHTML += out + '\n';
head.insertBefore(style, head.firstChild);
};
/** /**
* Open Terminal * Open Terminal
*/ */
@@ -680,6 +630,7 @@ Terminal.prototype.open = function(parent) {
// Create our main terminal element. // Create our main terminal element.
this.element = this.document.createElement('div'); this.element = this.document.createElement('div');
this.element.className = 'terminal'; this.element.className = 'terminal';
this.element.classList.add('xterm-theme-' + this.theme);
this.element.setAttribute('tabindex', 0); this.element.setAttribute('tabindex', 0);
// Create the lines for our terminal. // Create the lines for our terminal.
@@ -1194,7 +1145,7 @@ Terminal.prototype.refresh = function(start, end) {
if (data === -1) { if (data === -1) {
out += '<span class="reverse-video terminal-cursor">'; out += '<span class="reverse-video terminal-cursor">';
} else { } else {
out += '<span style="'; out += '<span class="';
bg = data & 0x1ff; bg = data & 0x1ff;
fg = (data >> 9) & 0x1ff; fg = (data >> 9) & 0x1ff;
@@ -1203,7 +1154,7 @@ Terminal.prototype.refresh = function(start, end) {
// bold // bold
if (flags & 1) { if (flags & 1) {
if (!Terminal.brokenBold) { if (!Terminal.brokenBold) {
out += 'font-weight:bold;'; out += ' xterm-bold ';
} }
// See: XTerm*boldColors // See: XTerm*boldColors
if (fg < 8) fg += 8; if (fg < 8) fg += 8;
@@ -1211,17 +1162,12 @@ Terminal.prototype.refresh = function(start, end) {
// underline // underline
if (flags & 2) { if (flags & 2) {
out += 'text-decoration:underline;'; out += ' xterm-underline ';
} }
// blink // blink
if (flags & 4) { if (flags & 4) {
if (flags & 2) { out += ' xterm-blink ';
out = out.slice(0, -1);
out += ' blink;';
} else {
out += 'text-decoration:blink;';
}
} }
// inverse // inverse
@@ -1235,7 +1181,7 @@ Terminal.prototype.refresh = function(start, end) {
// invisible // invisible
if (flags & 16) { if (flags & 16) {
out += 'visibility:hidden;'; out += ' xterm-hidden ';
} }
// out += '" class="' // out += '" class="'
@@ -1245,15 +1191,11 @@ Terminal.prototype.refresh = function(start, end) {
// + '">'; // + '">';
if (bg !== 256) { if (bg !== 256) {
out += 'background-color:' out += ' xterm-bg-color-' + bg + ' ';
+ this.colors[bg]
+ ';';
} }
if (fg !== 257) { if (fg !== 257) {
out += 'color:' out += ' xterm-color-' + fg + ' ';
+ this.colors[fg]
+ ';';
} }
out += '">'; out += '">';
@@ -1287,7 +1229,7 @@ Terminal.prototype.refresh = function(start, end) {
if (attr !== this.defAttr) { if (attr !== this.defAttr) {
out += '</span>'; out += '</span>';
} }
this.children[y].innerHTML = out; this.children[y].innerHTML = out;
} }