add setTerminal(). use terminal option always for consistency.

This commit is contained in:
Christopher Jeffrey 2015-08-05 19:34:18 -07:00
parent 72586faef9
commit 210c33d076
7 changed files with 45 additions and 21 deletions

View File

@ -333,7 +333,7 @@ The screen on which every other node renders.
- __input/output__ - Input and output streams. `process.stdin`/`process.stdout`
by default, however, it could be a `net.Socket` if you want to make a program
that runs over telnet or something of that nature.
- __term__ - `TERM` name used for terminfo parsing. The `$TERM` env variable is
- __terminal__ - `TERM` name used for terminfo parsing. The `$TERM` env variable is
used by default.
- __title__ - Set the terminal window title if possible.
@ -359,6 +359,7 @@ The screen on which every other node renders.
- __grabKeys__ - Whether the focused element grabs all keypresses.
- __lockKeys__ - Prevent keypresses from being received by any element.
- __hover__ - The currently hovered element. Only set if mouse events are bound.
- __terminal__ - Get terminal name.
- __title__ - Set or get window title.
##### Events:
@ -443,6 +444,7 @@ The screen on which every other node renders.
Also remove all global events relevant to the screen object. If all screen
objects are destroyed, the node process is essentially reset to its initial
state.
- __setTerminal(term)__ - Reset the terminal to `term`. Reloads terminfo.
#### Element (from Node)
@ -1377,7 +1379,7 @@ manager. Requires term.js and pty.js to be installed. See
- __shell__ - Name of shell. `$SHELL` by default.
- __args__ - Args for shell.
- __cursor__ - Can be `line`, `underline`, and `block`.
- __term__ - Terminal name (Default: `xterm`).
- __terminal__ - Terminal name (Default: `xterm`).
- __env__ - Object for process env.
- Other options similar to term.js'.
@ -2143,9 +2145,7 @@ telnet.createServer(function(client) {
// https://tools.ietf.org/html/rfc884
if (data.command === 'sb' && data.buf[3] === 1) {
var TERM = data.buf.slice(4, -2).toString('ascii');
screen.program.terminal = TERM;
screen.program.tput.terminal = TERM;
screen.program.tput.setup();
screen.setTerminal(TERM);
screen.render();
}
});
@ -2181,7 +2181,7 @@ telnet.createServer(function(client) {
smartCSR: true,
input: client,
output: client,
term: 'xterm-256color'
terminal: 'xterm-256color'
});
client.on('close', function() {
@ -2264,7 +2264,7 @@ Windows users will need to explicitly set `term` when creating a screen like so
This is now handled automatically):
``` js
var screen = blessed.screen({ term: 'windows-ansi' });
var screen = blessed.screen({ terminal: 'windows-ansi' });
```

View File

@ -23,9 +23,7 @@ var server = telnet.createServer(function(client) {
// https://tools.ietf.org/html/rfc884
if (data.command === 'sb' && data.buf[3] === 1) {
var TERM = data.buf.slice(4, -2).toString('ascii');
screen.program.terminal = TERM;
screen.program.tput.terminal = TERM;
screen.program.tput.setup();
screen.setTerminal(TERM);
screen.render();
}
});
@ -61,7 +59,7 @@ var server = telnet.createServer(function(client) {
smartCSR: true,
input: client,
output: client,
term: 'xterm-256color'
terminal: 'xterm-256color'
});
client.on('close', function() {

View File

@ -66,8 +66,8 @@ function Program(options) {
this.scrollTop = 0;
this.scrollBottom = this.rows - 1;
this.terminal = options.term
|| options.terminal
this.terminal = options.terminal
|| options.term
|| process.env.TERM
|| (process.platform === 'win32' ? 'windows-ansi' : 'xterm');
@ -247,7 +247,7 @@ Program.prototype.setupTput = function() {
, write = this._write.bind(this);
var tput = this.tput = new Tput({
term: this.terminal,
terminal: this.terminal,
padding: options.padding,
extended: options.extended,
printf: options.printf,
@ -292,6 +292,17 @@ Program.prototype.setupTput = function() {
});
};
Program.prototype.setTerminal = function(terminal) {
if (!this.tput) {
this.terminal = terminal;
this.setupTput();
return;
}
this.terminal = terminal;
this.tput.terminal = terminal;
this.tput.setup();
};
Program.prototype.has = function(name) {
return this.tput
? this.tput.has(name)

View File

@ -37,12 +37,12 @@ function Tput(options) {
options = options || {};
if (typeof options === 'string') {
options = { term: options };
options = { terminal: options };
}
this.options = options;
this.terminal = options.term
|| options.terminal
this.terminal = options.terminal
|| options.term
|| process.env.TERM
|| (process.platform === 'win32' ? 'windows-ansi' : 'xterm');
@ -56,7 +56,7 @@ function Tput(options) {
this.terminfoFile = options.terminfoFile;
this.termcapFile = options.termcapFile;
if (options.term || options.terminal) {
if (options.terminal || options.term) {
this.setup();
}
};

View File

@ -51,7 +51,7 @@ function Screen(options) {
log: options.log,
debug: options.debug,
dump: options.dump,
term: options.term,
terminal: options.terminal || options.term,
resizeTimeout: options.resizeTimeout,
forceUnicode: options.forceUnicode,
tput: true,
@ -252,6 +252,18 @@ Screen.prototype.__defineSetter__('title', function(title) {
return this.program.title = title;
});
Screen.prototype.__defineGetter__('terminal', function() {
return this.program.terminal;
});
Screen.prototype.__defineSetter__('terminal', function(terminal) {
return this.program.terminal = terminal;
});
Screen.prototype.setTerminal = function(terminal) {
return this.program.setTerminal(terminal);
};
Screen.prototype.enter = function() {
if (this.program.isAlt) return;
if (!this.cursor._set) {

View File

@ -48,7 +48,10 @@ function Terminal(options) {
this.style.bg = this.style.bg || 'default';
this.style.fg = this.style.fg || 'default';
this.termName = options.term || process.env.TERM || 'xterm';
this.termName = options.terminal
|| options.term
|| process.env.TERM
|| 'xterm';
this.bootstrap();
}

View File

@ -81,7 +81,7 @@ function parseArg() {
var argv = parseArg();
var tput = blessed.tput({
term: argv[0] !== 'all' && argv[0] !== 'rand'
terminal: argv[0] !== 'all' && argv[0] !== 'rand'
? argv[0] || __dirname + '/../usr/xterm'
: null,
extended: true,