From ad53cbed094e9f7bd258a553dca301f7edc2f570 Mon Sep 17 00:00:00 2001 From: nuintun Date: Fri, 4 Dec 2015 16:39:55 +0800 Subject: [PATCH] update files --- static/js/terminal/canvas-xterm.js | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/static/js/terminal/canvas-xterm.js b/static/js/terminal/canvas-xterm.js index 512c299..d4fffba 100644 --- a/static/js/terminal/canvas-xterm.js +++ b/static/js/terminal/canvas-xterm.js @@ -20,13 +20,48 @@ function textRepeat(text, n){ return str; } +/** + * iterator + * @param from + * @param iterator + * @param context + */ +function iterator(from, iterator, context){ + for (var key in from) { + if (from.hasOwnProperty(key)) { + iterator.call(context, key, from[key]); + } + } +} + +// default font +var FONT = { + size: 13, + color: '#fff', + lineHeight: 20, + family: 'Consolas' +}; + /** * CanvasXTerm * @param font * @constructor */ function CanvasXTerm(font){ - this.font = font || { family: 'Consolas', lineHeight: 20, size: 13, color: '#fff' }; + font = font || {}; + + // font setting + this.font = {}; + + // inherits + iterator(FONT, function (key, value){ + if (font.hasOwnProperty(key)) { + this.font[key] = font[key]; + } else { + this.font[key] = value; + } + }, this); + this.canvas = document.createElement('canvas'); this.canvas.style.backgroundColor = 'transparent'; this.brush = this.canvas.getContext('2d');