easier feature checking.

This commit is contained in:
Christopher Jeffrey 2013-07-14 08:37:57 -05:00
parent 3e6a89099e
commit 9db97cd61c
2 changed files with 50 additions and 11 deletions

View File

@ -118,6 +118,12 @@ Program.prototype.setupTput = function() {
});
};
Program.prototype.has = function(name) {
return this.tput
? this.tput.has(name)
: false;
};
Program.prototype.term = function(is) {
return this.terminal.indexOf(is) === 0;
};
@ -953,13 +959,13 @@ Program.prototype.repeat = function(ch, i) {
//Program.prototype.pad =
Program.prototype.nul = function() {
//if (this.tput) return this.put.pad();
//if (this.has('pad')) return this.put.pad();
return this.write('\0');
};
Program.prototype.bel =
Program.prototype.bell = function() {
if (this.tput) return this.put.bel();
if (this.has('bel')) return this.put.bel();
return this.write('\x07');
};
@ -971,7 +977,7 @@ Program.prototype.vtab = function() {
Program.prototype.ff =
Program.prototype.form = function() {
if (this.tput) return this.put.ff();
if (this.has('ff')) return this.put.ff();
return this.write('\x0c');
};
@ -979,7 +985,7 @@ Program.prototype.kbs =
Program.prototype.backspace = function() {
this.x--;
this._ncoords();
if (this.tput) return this.put.kbs();
if (this.has('kbs')) return this.put.kbs();
return this.write('\x08');
};
@ -987,24 +993,24 @@ Program.prototype.ht =
Program.prototype.tab = function() {
this.x += 8;
this._ncoords();
if (this.tput) return this.put.ht();
if (this.has('ht')) return this.put.ht();
return this.write('\t');
};
Program.prototype.shiftOut = function() {
// if (this.tput) return this.put.S2();
// if (this.has('S2')) return this.put.S2();
return this.write('\x0e');
};
Program.prototype.shiftIn = function() {
// if (this.tput) return this.put.S3();
// if (this.has('S3')) return this.put.S3();
return this.write('\x0f');
};
Program.prototype.cr =
Program.prototype.return = function() {
this.x = 0;
if (this.tput) return this.put.cr();
if (this.has('cr')) return this.put.cr();
return this.write('\r');
};
@ -1014,7 +1020,7 @@ Program.prototype.feed = function() {
this.x = 0;
this.y++;
this._ncoords();
if (this.tput) return this.put.nel();
if (this.has('nel')) return this.put.nel();
return this.write('\n');
};
@ -1050,14 +1056,18 @@ Program.prototype.nextLine = function() {
this.y++;
this.x = 0;
this._ncoords();
if (this.tput) return this.put.nel();
if (this.has('nel')) return this.put.nel();
return this.write('\x1bE');
};
// ESC c Full Reset (RIS).
Program.prototype.reset = function() {
this.x = this.y = 0;
if (this.tput) return this.put.rs1 ? this.put.rs1() : this.put.ris();
if (this.has('rs1') || this.has('ris')) {
return this.has('rs1')
? this.put.rs1()
: this.put.ris();
}
return this.write('\x1bc');
};

View File

@ -1581,6 +1581,35 @@ assert.equal(Tput.alias.exit_delete_mode.termcap, 'ed');
// Tput.alias.lines.ignore = 0;
// Tput.alias.set_lr_margin.ignore = 1;
/**
* Feature Checking
*/
Tput.aliasMap = {};
Object.keys(Tput.alias).forEach(function(key) {
var aliases = Array.isArray(Tput.alias[key])
? Tput.alias[key]
: [Tput.alias[key]];
Tput.aliasMap[key] = key;
aliases.forEach(function(k) {
Tput.aliasMap[k] = key;
});
});
Tput.prototype.has = function(name) {
var name = Tput.aliasMap[name]
, val = this.all[name];
if (!name) return false;
if (typeof val === 'number') {
return val !== -1;
}
return !!val;
};
/**
* Fallback Termcap Entry
*/