mirror of
https://github.com/chjj/blessed.git
synced 2026-02-06 14:11:51 +00:00
refactor
This commit is contained in:
parent
17891e74c7
commit
d04c335aa9
67
lib/tput.js
67
lib/tput.js
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
var assert = require('assert')
|
||||
, path = require('path')
|
||||
, fs = require('fs');
|
||||
|
||||
/**
|
||||
@ -38,10 +39,11 @@ function Tput(term, debug) {
|
||||
Tput.prototype.readTermInfo = function() {
|
||||
if (this.data) return;
|
||||
|
||||
var file = '/usr/share/terminfo/'
|
||||
+ this.term[0]
|
||||
+ '/'
|
||||
+ this.term;
|
||||
var file = path.resolve(
|
||||
'/usr/share/terminfo',
|
||||
path.basename(this.term[0]),
|
||||
path.basename(this.term)
|
||||
);
|
||||
|
||||
this.data = fs.readFileSync(file);
|
||||
this.info = this.parseTermInfo(this.data);
|
||||
@ -49,6 +51,11 @@ Tput.prototype.readTermInfo = function() {
|
||||
return this.info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Terminfo Parser
|
||||
* All shorts are little-endian
|
||||
*/
|
||||
|
||||
Tput.prototype.parseTermInfo = function(data) {
|
||||
var info = {}
|
||||
, l = data.length
|
||||
@ -257,6 +264,10 @@ Tput.prototype.parseExtended = function(data) {
|
||||
return info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compiler - terminfo cap->javascript
|
||||
*/
|
||||
|
||||
Tput.prototype.compile = function(key) {
|
||||
var self = this
|
||||
, info = this.info;
|
||||
@ -282,11 +293,11 @@ Tput.prototype.compile = function(key) {
|
||||
|
||||
Object.keys(info.all).forEach(function(key) {
|
||||
if (self.debug) {
|
||||
console.log('Compiling ' + key + ': ' + JSON.stringify(info.all[key]));
|
||||
console.log('Compiling %s: %s', key, JSON.stringify(info.all[key]));
|
||||
}
|
||||
self.methods[key] = self._compile(info.all[key]);
|
||||
var alias = self.alias(key);
|
||||
self.methods[alias] = self.methods[key];
|
||||
var alias = Tput.alias[key];
|
||||
if (alias) self.methods[alias] = self.methods[key];
|
||||
});
|
||||
|
||||
Tput.bools.concat(Tput.numbers).concat(Tput.strings).forEach(function(key) {
|
||||
@ -718,29 +729,37 @@ Tput.prototype._compile = function(val) {
|
||||
}
|
||||
};
|
||||
|
||||
// Return alias if one exists.
|
||||
Tput.prototype.alias = function(key) {
|
||||
switch (key) {
|
||||
case 'no_esc_ctlc': // bool
|
||||
return 'beehive_glitch';
|
||||
case 'dest_tabs_magic_smso': // bool
|
||||
return 'teleray_glitch';
|
||||
case 'micro_col_size': // num
|
||||
return 'micro_char_size';
|
||||
}
|
||||
};
|
||||
|
||||
Tput.prototype.setupAliases = function(info) {
|
||||
var self = this;
|
||||
Object.keys(info).forEach(function(name) {
|
||||
var obj = info[name];
|
||||
Object.keys(obj).forEach(function(key) {
|
||||
var alias = self.alias(key);
|
||||
var alias = Tput.alias[key];
|
||||
if (alias) obj[alias] = obj[key];
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function noop() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminfo Data
|
||||
*/
|
||||
|
||||
Tput.alias = {
|
||||
// Bools
|
||||
'no_esc_ctlc': 'beehive_glitch',
|
||||
'dest_tabs_magic_smso': 'teleray_glitch',
|
||||
// Numbers
|
||||
'micro_col_size': 'micro_char_size'
|
||||
};
|
||||
|
||||
Tput.bools = [
|
||||
'auto_left_margin',
|
||||
'auto_right_margin',
|
||||
@ -1253,14 +1272,6 @@ Tput.strings = [
|
||||
'box_chars_1'
|
||||
];
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function noop() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user