Копаюсь в сорцах интересненькой реализации
http://bellard.org/jslinux/Выкачал реализацию и привел исходники в более или менее читаемый вид.
Пытаюсь адаптировать внешний вид консоли для себя, но не могу разобраться как устроен интервал между строками, он пропорционально зависим от размера, а его нужно жестко задать.
Term.prototype.open = function () {
var y, ia, i, ja, c;
this.lines = new Array();
c = 32 | (this.def_attr << 16);
for (y = 0; y < this.h; y++) {
ia = new Array();
for (i = 0; i < this.w; i++) ia[i] = c;
this.lines[y] = ia;
}
document.writeln('<table border="0" cellspacing="0" cellpadding="0" style="width: 100%; height: 100%;">');
for (y = 0; y < this.h; y++) {
document.writeln('<tr><td class="term" id="tline' + y + '"></td></tr>');
}
document.writeln('</table>');
this.refresh(0, this.h - 1);
document.addEventListener("keydown", this.keyDownHandler.bind(this), true);
document.addEventListener("keypress", this.keyPressHandler.bind(this), true);
ja = this;
setInterval(function () {
ja.cursor_timer_cb();
}, 1000);
};
Term.prototype.refresh = function (ka, la) {
var ma, y, ia, na, c, w, i, oa, pa, qa, ra, sa;
for (y = ka; y <= la; y++) {
ia = this.lines[y];
na = "";
w = this.w;
if (y == this.y && this.cursor_state) {
oa = this.x;
} else {
oa = -1;
}
qa = this.def_attr;
for (i = 0; i < w; i++) {
c = ia[i];
pa = c >> 16;
c &= 0xffff;
if (i == oa) {
pa = -1;
}
if (pa != qa) {
if (qa != this.def_attr) na += '</span>';
if (pa != this.def_attr) {
if (pa == -1) {
na += '<span class="termReverse">';
} else {
na += '<span style="';
ra = (pa >> 3) & 7;
sa = pa & 7;
if (ra != 7) {
na += 'color:' + this.fg_colors[ra] + ';';
}
if (sa != 0) {
na += 'background-color:' + this.bg_colors[sa] + ';';
}
na += '">';
}
}
}
switch (c) {
case 32:
na += " ";
break;
case 38:
na += "&";
break;
case 60:
na += "<";
break;
case 62:
na += ">";
break;
default:
if (c < 32) {
na += " ";
} else {
na += String.fromCharCode(c);
}
break;
}
qa = pa;
}
if (qa != this.def_attr) {
na += '</span>';
}
ma = document.getElementById("tline" + y);
ma.innerHTML = na;
}
};
В атаче читаемый код виртуалки.
Линки на bin
http://bellard.org/jslinux/root.binhttp://bellard.org/jslinux/linuxstart.binhttp://bellard.org/jslinux/vmlinux26.bin