mirror of
https://github.com/chjj/blessed.git
synced 2026-02-06 18:21:46 +00:00
Compare commits
No commits in common. "master" and "v0.1.81" have entirely different histories.
45
README.md
45
README.md
@ -2140,20 +2140,47 @@ a full example):
|
||||
|
||||
``` js
|
||||
var blessed = require('blessed');
|
||||
var telnet = require('telnet2');
|
||||
var telnet = require('telnet');
|
||||
|
||||
telnet({ tty: true }, function(client) {
|
||||
client.on('term', function(terminal) {
|
||||
screen.terminal = terminal;
|
||||
screen.render();
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
|
||||
@ -13,24 +13,64 @@ process.title = 'blessed-telnet';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var blessed = require('blessed');
|
||||
var telnet = require('telnet2');
|
||||
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 server = telnet({ tty: true }, function(client) {
|
||||
client.on('debug', function(msg) {
|
||||
console.error(msg);
|
||||
});
|
||||
|
||||
client.on('term', function(terminal) {
|
||||
screen.terminal = terminal;
|
||||
screen.render();
|
||||
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('size', function(width, height) {
|
||||
client.columns = width;
|
||||
client.rows = height;
|
||||
client.emit('resize');
|
||||
client.on('terminal type', function(data) {
|
||||
if (data.command === 'sb' && data.name) {
|
||||
screen.terminal = data.name;
|
||||
screen.render();
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
|
||||
@ -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 '\x80':
|
||||
case '\200':
|
||||
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('\x80');
|
||||
return this._write('\200');
|
||||
};
|
||||
|
||||
Program.prototype.bel =
|
||||
|
||||
26
lib/tput.js
26
lib/tput.js
@ -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] === 0xff && data[i] === 0xff) {
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
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] === 0xff && data[i] === 0xff) {
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
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] === 0xff && data[i] === 0xff) {
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
_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] === 0xff && data[i] === 0xff) {
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
_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 = '\x80';
|
||||
ch = '\200';
|
||||
break;
|
||||
case 'a':
|
||||
ch = '\x07';
|
||||
@ -2041,10 +2041,6 @@ 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;
|
||||
}
|
||||
@ -2098,10 +2094,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('\x0e')
|
||||
|| ~info.strings.enter_alt_charset_mode.indexOf('\x0f')
|
||||
|| ~info.strings.set_attributes.indexOf('\x0e')
|
||||
|| ~info.strings.set_attributes.indexOf('\x0f')) {
|
||||
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')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -2172,7 +2168,7 @@ Tput.prototype.GetConsoleCP = function() {
|
||||
}
|
||||
|
||||
// Allow unicode on all windows consoles for now:
|
||||
if (+process.env.NCURSES_NO_WINDOWS_UNICODE !== 1) {
|
||||
if (+process.env.NCURSES_UNICODE !== 0) {
|
||||
return 65001;
|
||||
}
|
||||
|
||||
@ -2280,7 +2276,7 @@ function sprintf(src) {
|
||||
break;
|
||||
case 'c': // char
|
||||
param = isFinite(param)
|
||||
? String.fromCharCode(param || 0x80)
|
||||
? String.fromCharCode(param || 0200)
|
||||
: '';
|
||||
break;
|
||||
}
|
||||
|
||||
@ -25,8 +25,7 @@ function ListTable(options) {
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
// options.shrink = true;
|
||||
options.shrink = true;
|
||||
options.normalShrink = true;
|
||||
options.style = options.style || {};
|
||||
options.style.border = options.style.border || {};
|
||||
@ -38,19 +37,8 @@ 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,
|
||||
@ -96,10 +84,7 @@ ListTable.prototype._calculateMaxes = Table.prototype._calculateMaxes;
|
||||
ListTable.prototype.setRows =
|
||||
ListTable.prototype.setData = function(rows) {
|
||||
var self = this
|
||||
, align = this.__align
|
||||
, selected = this.selected
|
||||
, original = this.items.slice()
|
||||
, sel = this.ritems[this.selected];
|
||||
, align = this.__align;
|
||||
|
||||
if (this.visible && this.lpos) {
|
||||
this.clearPos();
|
||||
@ -163,15 +148,7 @@ ListTable.prototype.setData = function(rows) {
|
||||
|
||||
this._header.setFront();
|
||||
|
||||
// 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));
|
||||
}
|
||||
this.select(0);
|
||||
};
|
||||
|
||||
ListTable.prototype._select = ListTable.prototype.select;
|
||||
@ -206,12 +183,7 @@ ListTable.prototype.render = function() {
|
||||
|
||||
var height = coords.yl - coords.yi - this.ibottom;
|
||||
|
||||
var border = this.border;
|
||||
if (!this.border && this.options.border) {
|
||||
border = this.options.border;
|
||||
}
|
||||
|
||||
if (!border || this.options.noCellBorders) return coords;
|
||||
if (!this.border || this.options.noCellBorders) return coords;
|
||||
|
||||
// Draw border with correct angles.
|
||||
ry = 0;
|
||||
@ -228,7 +200,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 (!border.top) {
|
||||
if (!self.border.top) {
|
||||
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
|
||||
}
|
||||
lines[yi + ry].dirty = true;
|
||||
@ -238,7 +210,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 (!border.bottom) {
|
||||
if (!self.border.bottom) {
|
||||
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
|
||||
}
|
||||
lines[yi + ry].dirty = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user