From d63762fbe8035f7597dd188d9c6bbeb70cdf901a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 27 Jul 2013 05:13:04 -0500 Subject: [PATCH] tput.js fixes. --- lib/tput.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/tput.js b/lib/tput.js index 6298ee7..7679b5e 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -1092,28 +1092,37 @@ Tput.prototype.readTermcap = function(term) { , term = term || this.terminal , TERMCAP = process.env.TERMCAP || '' , TERMPATH = process.env.TERMPATH || '' - , HOME = process.env.HOME || ''; + , HOME = process.env.HOME || '' + , terms + , term_ + , root; // Termcap has a bunch of terminals usually stored in one file/string, // so we need to find the one containing our desired terminal. - var terms = (term[0] === '/' && this._tryCap(term)) - || this._tryCap(this.termcapFile, term) - || this._tryCap(TERMCAP, term) - || this._tryCap(TERMPATH && TERMPATH.split(/[: ]/), term) - || this._tryCap(HOME + '/.termcap', term) - || this._tryCap('/usr/share/misc/termcap', term) - || this._tryCap('/etc/termcap', term) - || this._tryCap(Tput.termcap, term); + if (term[0] === '/' && (terms = this._tryCap(term))) { + term_ = path.basename(term).split('.')[0]; + if (terms[process.env.TERM]) { + term = process.env.TERM; + } else if (terms[term_]) { + term = term_; + } else { + term = Object.keys(terms)[0]; + } + } else { + terms = this._tryCap(this.termcapFile, term) + || this._tryCap(TERMCAP, term) + || this._tryCap(TERMPATH && TERMPATH.split(/[: ]/), term) + || this._tryCap(HOME + '/.termcap', term) + || this._tryCap('/usr/share/misc/termcap', term) + || this._tryCap('/etc/termcap', term) + || this._tryCap(Tput.termcap, term); + } if (!terms) { throw new Error('Cannot find termcap for: ' + term); } - if (term[0] === '/') { - term = Object.keys(terms)[0]; - } - - var root = terms[term]; + root = terms[term]; if (this.debug) { this._termcap = terms; @@ -1589,7 +1598,7 @@ Tput.prototype._captoinfo = function(cap, s, parameterized) { if ((s[i] === '=' || s[i] === '+' || s[i] === '-' || s[i] === '*' || s[i] === '/') && (s[i + 1] === 'p' || s[i + 1] === 'c') - && s[i + 2] !== '\0') { + && s[i + 2] !== '\0' && s[i + 2]) { var l; l = 2; if (s[i] !== '=') {