assume screen.tput is present.

This commit is contained in:
Christopher Jeffrey 2013-08-27 08:58:53 -05:00
parent e563155b0e
commit f8c2ebef1d

View File

@ -12,8 +12,10 @@
var EventEmitter = require('./events').EventEmitter
, assert = require('assert')
, path = require('path')
, fs = require('fs')
, colors = require('./colors')
, fs = require('fs');
var colors = require('./colors')
, program = require('./program')
, widget = exports;
/**
@ -248,8 +250,6 @@ function Screen(options) {
options = { program: options };
}
var program = require('./program');
this.program = options.program || program.global;
if (!this.program) {
@ -604,6 +604,7 @@ Screen.prototype.render = function() {
this.emit('prerender');
// TODO: Possibly get rid of .dirty altogether.
// TODO: Could possibly drop .dirty and just clear the `lines` buffer every
// time before a screen.render. This way clearRegion doesn't have to be
// called in arbitrary places for the sake of clearing a spot where an
@ -636,8 +637,7 @@ Screen.prototype.blankLine = function(ch, dirty) {
Screen.prototype.insertLine = function(n, y, top, bottom) {
// if (y === top) return this.insertLineNC(n, y, top, bottom);
if (!this.tput
|| !this.tput.strings.change_scroll_region
if (!this.tput.strings.change_scroll_region
|| !this.tput.strings.delete_line
|| !this.tput.strings.insert_line) return;
@ -659,8 +659,7 @@ Screen.prototype.insertLine = function(n, y, top, bottom) {
Screen.prototype.deleteLine = function(n, y, top, bottom) {
// if (y === top) return this.deleteLineNC(n, y, top, bottom);
if (!this.tput
|| !this.tput.strings.change_scroll_region
if (!this.tput.strings.change_scroll_region
|| !this.tput.strings.delete_line
|| !this.tput.strings.insert_line) return;
@ -683,8 +682,7 @@ Screen.prototype.deleteLine = function(n, y, top, bottom) {
// Scroll down (up cursor-wise).
// This will only work for top line deletion as opposed to arbitrary lines.
Screen.prototype.insertLineNC = function(n, y, top, bottom) {
if (!this.tput
|| !this.tput.strings.change_scroll_region
if (!this.tput.strings.change_scroll_region
|| !this.tput.strings.delete_line) return;
this._buf += this.tput.csr(top, bottom);
@ -706,8 +704,7 @@ Screen.prototype.insertLineNC = function(n, y, top, bottom) {
// Scroll up (down cursor-wise).
// This will only work for bottom line deletion as opposed to arbitrary lines.
Screen.prototype.deleteLineNC = function(n, y, top, bottom) {
if (!this.tput
|| !this.tput.strings.change_scroll_region
if (!this.tput.strings.change_scroll_region
|| !this.tput.strings.delete_line) return;
this._buf += this.tput.csr(top, bottom);
@ -754,11 +751,6 @@ Screen.prototype.deleteTop = function(top, bottom) {
Screen.prototype.cleanSides = function(el) {
var pos = el.lpos;
// If we don't have tput, we can't use CSR anyway.
// if (!this.tput) {
// return false;
// }
if (!pos) {
return false;
}
@ -860,7 +852,6 @@ Screen.prototype.draw = function(start, end) {
line = this.lines[y];
o = this.olines[y];
// TODO: Possibly get rid of .dirty altogether.
if (!line.dirty) continue;
line.dirty = false;
@ -876,7 +867,7 @@ Screen.prototype.draw = function(start, end) {
// the bg for non BCE terminals worth the overhead?
if (this.options.useBCE
&& ch === ' '
&& ((this.tput && this.tput.bools.back_color_erase)
&& (this.tput.bools.back_color_erase
|| (data & 0x1ff) === (this.dattr & 0x1ff))
&& ((data >> 18) & 8) === ((this.dattr >> 18) & 8)) {
clr = true;
@ -898,12 +889,8 @@ Screen.prototype.draw = function(start, end) {
out += this.codeAttr(data);
attr = data;
}
out += this.tput
? this.tput.cup(y, x)
: '\x1b[' + (y + 1) + ';' + (x + 1) + 'H';
out += this.tput
? this.tput.el(0)
: '\x1b[K';
out += this.tput.cup(y, x);
out += this.tput.el();
for (xx = x; xx < this.cols; xx++) {
o[xx][0] = data;
o[xx][1] = ' ';
@ -915,31 +902,23 @@ Screen.prototype.draw = function(start, end) {
// and start over drawing the rest of line. Might
// not be worth it. Try to use ECH if the terminal
// supports it. Maybe only try to use ECH here.
// //if (this.tput && this.tput.strings.erase_chars)
// //if (this.tput.strings.erase_chars)
// if (!clr && neq && (xx - x) > 10) {
// lx = -1, ly = -1;
// if (data !== attr) {
// out += this.codeAttr(data);
// attr = data;
// }
// out += this.tput
// ? this.tput.cup(y, x)
// : '\x1b[' + (y + 1) + ';' + (x + 1) + 'H';
// if (this.tput && this.tput.strings.erase_chars) {
// out += this.tput.cup(y, x);
// if (this.tput.strings.erase_chars) {
// // Use erase_chars to avoid erasing the whole line.
// out += this.tput
// ? this.tput.ech(xx - x)
// : '\x1b[' + (xx - x) + 'X';
// out += this.tput.ech(xx - x);
// } else {
// out += this.tput
// ? this.tput.el(0)
// : '\x1b[K';
// out += this.tput.el();
// }
// out += this.tput
// ? this.tput.cuf(xx - x)
// : '\x1b[' + (xx - x) + 'C';
// out += this.tput.cuf(xx - x);
// this.fillRegion(data, ' ',
// x, this.tput && this.tput.strings.erase_chars ? xx : this.cols,
// x, this.tput.strings.erase_chars ? xx : this.cols,
// y, y + 1);
// x = xx - 1;
// continue;
@ -970,15 +949,9 @@ Screen.prototype.draw = function(start, end) {
}
continue;
} else if (lx !== -1) {
if (this.tput) {
out += y === ly
? this.tput.cuf(x - lx)
: this.tput.cup(y, x);
} else {
out += y === ly
? '\x1b[' + (x - lx) + 'C'
: '\x1b[' + (y + 1) + ';' + (x + 1) + 'H';
}
lx = -1, ly = -1;
}
o[x][0] = data;
@ -1069,7 +1042,6 @@ Screen.prototype.draw = function(start, end) {
// supports UTF8, but I imagine it's unlikely.
// Maybe remove !this.tput.unicode check, however,
// this seems to be the way ncurses does it.
if (this.tput) {
if (this.tput.strings.enter_alt_charset_mode) {
//if (!this.tput.brokenACS || !this.tput.unicode) {
if (!this.tput.brokenACS) {
@ -1100,7 +1072,6 @@ Screen.prototype.draw = function(start, end) {
ch = this.tput.utoa[ch] || '?';
}
}
}
// if (wideChars.test(ch)) x++;
@ -1113,9 +1084,7 @@ Screen.prototype.draw = function(start, end) {
}
if (out) {
main += this.tput
? this.tput.cup(y, 0) + out
: '\x1b[' + (y + 1) + ';1H' + out;
main += this.tput.cup(y, 0) + out;
}
}
@ -1128,20 +1097,12 @@ Screen.prototype.draw = function(start, end) {
pre = '';
post = '';
pre += this.tput
? this.tput.sc()
: '\x1b7';
post += this.tput
? this.tput.rc()
: '\x1b8';
pre += this.tput.sc();
post += this.tput.rc();
if (!this.program.cursorHidden) {
pre += this.tput
? this.tput.civis()
: '\x1b[?25l';
post += this.tput
? this.tput.cnorm()
: '\x1b[?25h';
pre += this.tput.civis();
post += this.tput.cnorm();
}
// this.program.flush();
@ -1151,7 +1112,6 @@ Screen.prototype.draw = function(start, end) {
};
Screen.prototype._reduceColor = function(col) {
if (this.tput) {
if (col >= 16 && this.tput.colors <= 16) {
col = colors.ccolors[col];
} else if (col >= 8 && this.tput.colors <= 8) {
@ -1159,7 +1119,6 @@ Screen.prototype._reduceColor = function(col) {
} else if (col >= 2 && this.tput.colors <= 2) {
col %= 2;
}
}
return col;
};