Compare commits

...

6 Commits

Author SHA1 Message Date
Christopher Jeffrey (JJ)
eab243fc7a Merge pull request #214 from dbkaplun/strict-mode-fixes
strict mode fixes
2016-01-04 00:13:40 -08:00
Dan Kaplun
ba1982d4a9 Replace octal parseInt with hex literal 2016-01-04 02:50:49 -05:00
Dan Kaplun
62b439ef8e strict mode fixes 2016-01-03 18:32:58 -05:00
Christopher Jeffrey
1c20b8b2ee improve listtable. 2015-12-22 02:03:40 -08:00
Christopher Jeffrey
04ffa283ac unicode env vars. 2015-09-07 05:14:10 -07:00
Christopher Jeffrey
10edaa088b use telnet2 for example. 2015-09-02 18:48:05 -07:00
5 changed files with 69 additions and 104 deletions

View File

@ -2140,47 +2140,20 @@ a full example):
``` js
var blessed = require('blessed');
var telnet = require('telnet');
var telnet = require('telnet2');
telnet.createServer(function(client) {
client.do.transmit_binary();
client.do.terminal_type();
client.do.window_size();
client.on('terminal type', function(data) {
if (data.command === 'sb' && data.name) {
screen.terminal = data.name;
screen.render();
}
telnet({ tty: true }, function(client) {
client.on('term', function(terminal) {
screen.terminal = terminal;
screen.render();
});
client.on('window size', function(data) {
if (data.command === 'sb') {
client.columns = data.columns;
client.rows = data.rows;
client.emit('resize');
}
client.on('size', function(width, height) {
client.columns = width;
client.rows = height;
client.emit('resize');
});
// Make the client look like a tty:
client.setRawMode = function(mode) {
client.isRaw = mode;
if (!client.writable) return;
if (mode) {
client.do.suppress_go_ahead();
client.will.suppress_go_ahead();
client.will.echo();
} else {
client.dont.suppress_go_ahead();
client.wont.suppress_go_ahead();
client.wont.echo();
}
};
client.isTTY = true;
client.isRaw = false;
client.columns = 80;
client.rows = 24;
var screen = blessed.screen({
smartCSR: true,
input: client,

View File

@ -13,64 +13,24 @@ process.title = 'blessed-telnet';
var fs = require('fs');
var path = require('path');
var blessed = require('blessed');
var telnet = require('telnet');
var server = telnet.createServer(function(client) {
client.do.transmit_binary();
client.do.terminal_type();
client.do.window_size();
client.do.environment_variables();
var telnet = require('telnet2');
var server = telnet({ tty: true }, function(client) {
client.on('debug', function(msg) {
console.error(msg);
});
client.on('environment variables', function(data) {
if (data.command === 'sb') {
if (data.name === 'TERM') {
screen.terminal = data.value;
} else {
// Clear the screen since they may have used `env send [var]`.
screen.realloc();
}
screen.render();
}
client.on('term', function(terminal) {
screen.terminal = terminal;
screen.render();
});
client.on('terminal type', function(data) {
if (data.command === 'sb' && data.name) {
screen.terminal = data.name;
screen.render();
}
client.on('size', function(width, height) {
client.columns = width;
client.rows = height;
client.emit('resize');
});
client.on('window size', function(data) {
if (data.command === 'sb') {
client.columns = data.columns;
client.rows = data.rows;
client.emit('resize');
}
});
// Make the client look like a tty:
client.setRawMode = function(mode) {
client.isRaw = mode;
if (!client.writable) return;
if (mode) {
client.do.suppress_go_ahead();
client.will.suppress_go_ahead();
client.will.echo();
} else {
client.dont.suppress_go_ahead();
client.wont.suppress_go_ahead();
client.wont.echo();
}
};
client.isTTY = true;
client.isRaw = false;
client.columns = 80;
client.rows = 24;
var screen = blessed.screen({
smartCSR: true,
input: client,

View File

@ -195,7 +195,7 @@ Program.prototype.setupDump = function() {
return data.replace(/[\0\x80\x1b-\x1f\x7f\x01-\x1a]/g, function(ch) {
switch (ch) {
case '\0':
case '\200':
case '\x80':
ch = '@';
break;
case '\x1b':
@ -1911,7 +1911,7 @@ Program.prototype.getCursorColor = function(callback) {
//Program.prototype.pad =
Program.prototype.nul = function() {
//if (this.has('pad')) return this.put.pad();
return this._write('\200');
return this._write('\x80');
};
Program.prototype.bel =

View File

@ -366,7 +366,7 @@ Tput.prototype.parseTerminfo = function(data, file) {
o = 0;
for (; i < l; i += 2) {
v = Tput.numbers[o++];
if (data[i + 1] === 0377 && data[i] === 0377) {
if (data[i + 1] === 0xff && data[i] === 0xff) {
info.numbers[v] = -1;
} else {
info.numbers[v] = (data[i + 1] << 8) | data[i];
@ -379,7 +379,7 @@ Tput.prototype.parseTerminfo = function(data, file) {
o = 0;
for (; i < l; i += 2) {
v = Tput.strings[o++];
if (data[i + 1] === 0377 && data[i] === 0377) {
if (data[i + 1] === 0xff && data[i] === 0xff) {
info.strings[v] = -1;
} else {
info.strings[v] = (data[i + 1] << 8) | data[i];
@ -533,7 +533,7 @@ Tput.prototype.parseExtended = function(data) {
var _numbers = [];
l = i + h.numCount * 2;
for (; i < l; i += 2) {
if (data[i + 1] === 0377 && data[i] === 0377) {
if (data[i + 1] === 0xff && data[i] === 0xff) {
_numbers.push(-1);
} else {
_numbers.push((data[i + 1] << 8) | data[i]);
@ -544,7 +544,7 @@ Tput.prototype.parseExtended = function(data) {
var _strings = [];
l = i + h.strCount * 2;
for (; i < l; i += 2) {
if (data[i + 1] === 0377 && data[i] === 0377) {
if (data[i + 1] === 0xff && data[i] === 0xff) {
_strings.push(-1);
} else {
_strings.push((data[i + 1] << 8) | data[i]);
@ -884,7 +884,7 @@ Tput.prototype._compile = function(info, key, str) {
ch = ':';
break;
case '0':
ch = '\200';
ch = '\x80';
break;
case 'a':
ch = '\x07';
@ -2041,6 +2041,10 @@ Tput.prototype.detectFeatures = function(info) {
};
Tput.prototype.detectUnicode = function() {
if (process.env.NCURSES_FORCE_UNICODE != null) {
return !!+process.env.NCURSES_FORCE_UNICODE;
}
if (this.options.forceUnicode != null) {
return this.options.forceUnicode;
}
@ -2094,10 +2098,10 @@ Tput.prototype.detectBrokenACS = function(info) {
&& process.env.TERMCAP
&& ~process.env.TERMCAP.indexOf('screen')
&& ~process.env.TERMCAP.indexOf('hhII00')) {
if (~info.strings.enter_alt_charset_mode.indexOf('\016')
|| ~info.strings.enter_alt_charset_mode.indexOf('\017')
|| ~info.strings.set_attributes.indexOf('\016')
|| ~info.strings.set_attributes.indexOf('\017')) {
if (~info.strings.enter_alt_charset_mode.indexOf('\x0e')
|| ~info.strings.enter_alt_charset_mode.indexOf('\x0f')
|| ~info.strings.set_attributes.indexOf('\x0e')
|| ~info.strings.set_attributes.indexOf('\x0f')) {
return true;
}
}
@ -2168,7 +2172,7 @@ Tput.prototype.GetConsoleCP = function() {
}
// Allow unicode on all windows consoles for now:
if (+process.env.NCURSES_UNICODE !== 0) {
if (+process.env.NCURSES_NO_WINDOWS_UNICODE !== 1) {
return 65001;
}
@ -2276,7 +2280,7 @@ function sprintf(src) {
break;
case 'c': // char
param = isFinite(param)
? String.fromCharCode(param || 0200)
? String.fromCharCode(param || 0x80)
: '';
break;
}

View File

@ -25,7 +25,8 @@ function ListTable(options) {
}
options = options || {};
options.shrink = true;
// options.shrink = true;
options.normalShrink = true;
options.style = options.style || {};
options.style.border = options.style.border || {};
@ -37,8 +38,19 @@ function ListTable(options) {
options.style.selected = options.style.cell.selected;
options.style.item = options.style.cell;
var border = options.border;
if (border
&& border.top === false
&& border.bottom === false
&& border.left === false
&& border.right === false) {
delete options.border;
}
List.call(this, options);
options.border = border;
this._header = new Box({
parent: this,
left: this.screen.autoPadding ? 0 : this.ileft,
@ -84,7 +96,10 @@ ListTable.prototype._calculateMaxes = Table.prototype._calculateMaxes;
ListTable.prototype.setRows =
ListTable.prototype.setData = function(rows) {
var self = this
, align = this.__align;
, align = this.__align
, selected = this.selected
, original = this.items.slice()
, sel = this.ritems[this.selected];
if (this.visible && this.lpos) {
this.clearPos();
@ -148,7 +163,15 @@ ListTable.prototype.setData = function(rows) {
this._header.setFront();
this.select(0);
// Try to find our old item if it still exists.
sel = this.ritems.indexOf(sel);
if (~sel) {
this.select(sel);
} else if (this.items.length === original.length) {
this.select(selected);
} else {
this.select(Math.min(selected, this.items.length - 1));
}
};
ListTable.prototype._select = ListTable.prototype.select;
@ -183,7 +206,12 @@ ListTable.prototype.render = function() {
var height = coords.yl - coords.yi - this.ibottom;
if (!this.border || this.options.noCellBorders) return coords;
var border = this.border;
if (!this.border && this.options.border) {
border = this.options.border;
}
if (!border || this.options.noCellBorders) return coords;
// Draw border with correct angles.
ry = 0;
@ -200,7 +228,7 @@ ListTable.prototype.render = function() {
lines[yi + ry][xi + rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u252c'; // '┬'
// XXX If we alter iheight and itop for no borders - nothing should be written here
if (!self.border.top) {
if (!border.top) {
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
}
lines[yi + ry].dirty = true;
@ -210,7 +238,7 @@ ListTable.prototype.render = function() {
lines[yi + ry][xi + rx][0] = battr;
lines[yi + ry][xi + rx][1] = '\u2534'; // '┴'
// XXX If we alter iheight and ibottom for no borders - nothing should be written here
if (!self.border.bottom) {
if (!border.bottom) {
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
}
lines[yi + ry].dirty = true;