/**
* Created by nuintun on 2015/11/24.
*/
'use strict';
module.exports = function (Terminal){
// Rendering Engine
// In the screen buffer, each character
// is stored as a an array with a character
// and a 32-bit integer.
// First value: a utf-16 character.
// Second value:
// Next 9 bits: background color (0-511).
// Next 9 bits: foreground color (0-511).
// Next 14 bits: a mask for misc.
// flags: 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
function screen(foreground, background, content){
var intro = '
';
var outro = '
';
return intro + content + outro;
}
/**
* refresh
* @param start
* @param end
*/
Terminal.prototype.refresh = function (start, end){
var x, y, i, line, out, ch, width, data, attr, fgColor, bgColor, flags, row;
width = this.cols;
y = start;
if (end >= this.lines.length) {
end = this.lines.length - 1;
}
for (; y <= end; y++) {
i = 0;
out = '';
attr = this.defAttr;
row = y + this.ydisp;
line = this.lines[row];
if (y === this.y && this.cursor && this.cursorState && this.ydisp === this.ybase) {
x = this.x;
} else {
x = -1;
}
for (; i < width; i++) {
data = line[i][0];
ch = line[i][1];
if (i === x) data = -1;
if (data !== attr) {
if (attr !== this.defAttr) {
out += '';
}
if (data !== this.defAttr) {
if (data === -1) {
out += '';
} else {
out += '';
}
}
}
switch (ch) {
case '&':
out += '&';
break;
case '<':
out += '<';
break;
case '>':
out += '>';
break;
default:
if (ch <= ' ') {
out += ' ';
} else {
if (this.isWide(ch)) i++;
out += ch;
}
break;
}
attr = data;
}
if (attr !== this.defAttr) {
out += '';
}
this.screenLines[y] = '' + out + '
';
}
this.screen = screen(this.fgColor, this.bgColor, this.screenLines.join(''));
};
};