add a default style option.

This commit is contained in:
Christopher Jeffrey
2013-08-11 09:32:17 -05:00
parent 791127bc88
commit 3b322929c6
3 changed files with 63 additions and 27 deletions
+57 -11
View File
@@ -146,7 +146,7 @@ function Terminal(options) {
};
}
this._options = options || {};
this.options = options || {};
// this.context = options.context || window;
// this.document = options.document || document;
@@ -402,19 +402,31 @@ Terminal.prototype.blur = function() {
Terminal.focus = null;
};
/**
* Initialize global behavior
*/
Terminal.prototype.initGlobal = function() {
var document = this.document;
Terminal._boundDocs = Terminal._boundDocs || [];
if (~indexOf(Terminal._boundDocs, document)) {
return;
}
Terminal._boundDocs.push(document);
Terminal.bindKeys(document);
if (this.options.style) {
Terminal.insertStyle(document);
}
};
/**
* Global Events for key handling
*/
Terminal.bindKeys = function(document) {
Terminal._boundDocs = Terminal._boundDocs || [];
if (~indexOf(Terminal._boundDocs, document)) {
return;
}
Terminal._boundDocs.push(document);
// We could put an "if (Terminal.focus)" check
// here, but it shouldn't be necessary.
on(document, 'keydown', function(ev) {
@@ -461,6 +473,39 @@ Terminal.bindKeys = function(document) {
});
};
/**
* Insert a default style
*/
Terminal.insertStyle = function(document) {
var style = document.getElementById('termjs-style');
if (style) return;
var head = document.getElementsByTagName('head')[0];
if (!head) return;
var style = document.createElement('style');
style.id = 'termjs-style';
// textContent doesn't work well with IE for <style> elements.
style.innerHTML = ''
+ '.terminal {\n'
+ ' float: left;\n'
+ ' border: ' + Terminal.defaultColors.bg + ' solid 5px;\n'
+ ' font-family: "DejaVu Sans Mono", "Liberation Mono", monospace;\n'
+ ' font-size: 11px;\n'
+ ' color: ' + Terminal.defaultColors.fg + ';\n'
+ ' background: ' + Terminal.defaultColors.bg + ';\n'
+ '}\n'
+ '\n'
+ '.terminal-cursor {\n'
+ ' color: ' + Terminal.defaultColors.bg + ';\n'
+ ' background: ' + Terminal.defaultColors.fg + ';\n'
+ '}\n';
head.insertBefore(style, head.firstChild);
};
/**
* Open Terminal
*/
@@ -496,7 +541,7 @@ Terminal.prototype.open = function(parent) {
this.refresh(0, this.rows - 1);
Terminal.bindKeys(this.document);
this.initGlobal();
this.focus();
@@ -550,7 +595,8 @@ Terminal.prototype.open = function(parent) {
this.bindMouse();
// XXX - hack, move this somewhere else.
// Figure out whether boldness affects
// the character width of monospace fonts.
if (Terminal.brokenBold == null) {
Terminal.brokenBold = isBoldBroken(this.document);
}