diff --git a/README.md b/README.md index b4ad4e1..b984112 100644 --- a/README.md +++ b/README.md @@ -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' }); ``` diff --git a/example/blessed-telnet.js b/example/blessed-telnet.js index a0ae405..1e790a7 100755 --- a/example/blessed-telnet.js +++ b/example/blessed-telnet.js @@ -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() { diff --git a/lib/program.js b/lib/program.js index 79e24b7..9452af8 100644 --- a/lib/program.js +++ b/lib/program.js @@ -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) diff --git a/lib/tput.js b/lib/tput.js index e17986f..9b07fb9 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -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(); } }; diff --git a/lib/widgets/screen.js b/lib/widgets/screen.js index 3993e42..2103d3d 100644 --- a/lib/widgets/screen.js +++ b/lib/widgets/screen.js @@ -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) { diff --git a/lib/widgets/terminal.js b/lib/widgets/terminal.js index 458daf1..cc857f4 100644 --- a/lib/widgets/terminal.js +++ b/lib/widgets/terminal.js @@ -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(); } diff --git a/test/tput.js b/test/tput.js index 744cd56..d42bde7 100644 --- a/test/tput.js +++ b/test/tput.js @@ -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,