neo-blessed/lib/tput.js

1744 lines
37 KiB
JavaScript
Raw Normal View History

2013-02-08 13:43:45 +00:00
/**
* Tput for node.js
* Copyright (c) 2013, Christopher Jeffrey (MIT License)
* https://github.com/chjj/blessed
*/
// Resources:
// $ man term
// $ man terminfo
// http://invisible-island.net/ncurses/man/term.5.html
// https://en.wikipedia.org/wiki/Terminfo
/**
* Modules
*/
var assert = require('assert')
2013-02-22 11:20:50 +00:00
, path = require('path')
2013-02-08 13:43:45 +00:00
, fs = require('fs');
/**
* Tput
*/
2013-02-24 13:53:18 +00:00
function Tput(options) {
2013-02-15 17:42:52 +00:00
if (!(this instanceof Tput)) {
2013-02-24 13:53:18 +00:00
return new Tput(options);
2013-02-15 17:42:52 +00:00
}
2013-02-24 13:53:18 +00:00
if (typeof options === 'string') {
options = { term: options };
}
this.options = options;
2013-02-25 07:47:32 +00:00
this.term = options.term || process.env.TERM;
2013-02-08 13:43:45 +00:00
this.data = null;
this.info = {};
2013-02-24 13:53:18 +00:00
this.debug = options.debug;
this.padding = options.padding;
2013-02-24 21:07:54 +00:00
this.extended = options.extended;
2013-02-20 00:35:26 +00:00
2013-02-22 22:12:34 +00:00
this.readTerminfo();
2013-02-20 00:35:26 +00:00
this.compile();
2013-02-08 13:43:45 +00:00
}
2013-02-22 22:12:34 +00:00
Tput.prototype.readTerminfo = function() {
2013-02-08 13:43:45 +00:00
if (this.data) return;
2013-02-22 11:20:50 +00:00
var file = path.resolve(
'/usr/share/terminfo',
path.basename(this.term[0]),
path.basename(this.term)
);
2013-02-08 13:43:45 +00:00
this.data = fs.readFileSync(file);
2013-02-22 22:12:34 +00:00
this.info = this.parseTerminfo(this.data);
2013-02-08 13:43:45 +00:00
return this.info;
};
2013-02-22 11:20:50 +00:00
/**
* Terminfo Parser
* All shorts are little-endian
*/
2013-02-22 22:12:34 +00:00
Tput.prototype.parseTerminfo = function(data) {
2013-02-08 13:43:45 +00:00
var info = {}
, l = data.length
2013-02-24 13:39:29 +00:00
, i = 0
, v
, o;
2013-02-08 13:43:45 +00:00
var h = info.header = {
dataSize: data.length,
headerSize: 12,
magicNumber: (data[1] << 8) | data[0],
namesSize: (data[3] << 8) | data[2],
boolCount: (data[5] << 8) | data[4],
numCount: (data[7] << 8) | data[6],
strCount: (data[9] << 8) | data[8],
strTableSize: (data[11] << 8) | data[10]
};
h.total = h.headerSize
+ h.namesSize
+ h.boolCount
+ h.numCount * 2
+ h.strCount * 2
+ h.strTableSize;
i = h.headerSize;
// Names Section
var names = data.toString('ascii', i, i + h.namesSize - 1)
, parts = names.split('|')
, name = parts[0]
2013-02-23 22:01:50 +00:00
, desc = parts.pop();
2013-02-08 13:43:45 +00:00
info.name = name;
2013-02-23 22:01:50 +00:00
info.names = parts;
2013-02-08 13:43:45 +00:00
info.desc = desc;
i += h.namesSize - 1;
// Names is nul-terminated.
assert.equal(data[i], 0);
i++;
// Booleans Section
// One byte for each flag
// Same order as <term.h>
info.bools = {};
l = i + h.boolCount;
2013-02-24 13:39:29 +00:00
o = 0;
2013-02-08 13:43:45 +00:00
for (; i < l; i++) {
2013-02-25 06:40:46 +00:00
v = Tput.bools[o++];
2013-02-24 13:39:29 +00:00
info.bools[v] = !!data[i];
2013-02-08 13:43:45 +00:00
}
// Null byte in between to make sure numbers begin on an even byte.
if (i % 2) {
assert.equal(data[i], 0);
i++;
}
// Numbers Section
info.numbers = {};
l = i + h.numCount * 2;
2013-02-24 13:39:29 +00:00
o = 0;
2013-02-08 13:43:45 +00:00
for (; i < l; i += 2) {
2013-02-25 06:40:46 +00:00
v = Tput.numbers[o++];
2013-02-08 13:43:45 +00:00
if (data[i + 1] === 0377 && data[i] === 0377) {
2013-02-24 13:39:29 +00:00
info.numbers[v] = -1;
2013-02-08 13:43:45 +00:00
} else {
2013-02-24 13:39:29 +00:00
info.numbers[v] = (data[i + 1] << 8) | data[i];
2013-02-08 13:43:45 +00:00
}
}
// Strings Section
info.strings = {};
l = i + h.strCount * 2;
2013-02-24 13:39:29 +00:00
o = 0;
2013-02-08 13:43:45 +00:00
for (; i < l; i += 2) {
2013-02-25 06:40:46 +00:00
v = Tput.strings[o++];
2013-02-08 13:43:45 +00:00
if (data[i + 1] === 0377 && data[i] === 0377) {
2013-02-24 13:39:29 +00:00
info.strings[v] = -1;
2013-02-08 13:43:45 +00:00
} else {
2013-02-24 13:39:29 +00:00
info.strings[v] = (data[i + 1] << 8) | data[i];
2013-02-08 13:43:45 +00:00
}
}
// String Table
Object.keys(info.strings).forEach(function(key) {
if (info.strings[key] === -1) {
delete info.strings[key];
return;
}
var s = i + info.strings[key]
, j = s;
while (data[j]) j++;
if (s >= data.length || j > data.length) {
delete info.strings[key];
return;
}
info.strings[key] = data.toString('ascii', s, j);
});
2013-02-15 17:42:52 +00:00
// Extended Header
if (this.extended) {
2013-02-24 22:31:33 +00:00
i += h.strTableSize;
2013-02-15 17:42:52 +00:00
l = data.length;
if (i < l) {
2013-02-25 00:47:37 +00:00
var extended = this.parseExtended(data.slice(i));
['bools', 'numbers', 'strings'].forEach(function(key) {
merge(info[key], extended[key]);
2013-02-15 17:42:52 +00:00
});
}
2013-02-08 13:43:45 +00:00
}
return info;
};
2013-02-25 00:47:37 +00:00
/**
* Extended Parsing
*/
// Some data to help understand:
2013-02-24 22:31:33 +00:00
// For xterm, non-extended header:
// { dataSize: 3270,
// headerSize: 12,
// magicNumber: 282,
// namesSize: 48,
// boolCount: 38,
// numCount: 15,
// strCount: 413,
// strTableSize: 1388,
// total: 2342 }
// For xterm, header:
// Offset: 2342
// { header:
// { dataSize: 928,
// headerSize: 10,
// boolCount: 2,
// numCount: 1,
// strCount: 57,
// strTableSize: 117,
// lastStrTableOffset: 680,
// total: 245 },
// For xterm, layout:
// { header: '0 - 10', // length: 10
// bools: '10 - 12', // length: 2
// numbers: '12 - 14', // length: 2
2013-02-25 00:19:04 +00:00
// strings: '14 - 128', // length: 114 (57 short)
// symoffsets: '128 - 248', // length: 120 (60 short)
// stringtable: '248 - 612', // length: 364
// sym: '612 - 928' } // length: 316
2013-02-24 22:31:33 +00:00
//
// How lastStrTableOffset works:
// data.length - h.lastStrTableOffset === 248 (sym-offset end, string-table start)
// 364 + 316 === 680 (lastStrTableOffset)
// How strTableSize works:
// h.strCount + [symOffsetCount] === h.strTableSize
// 57 + 60 === 117 (strTableSize)
// symOffsetCount doesn't actually exist in the header. it's just implied.
// Getting the number of sym offsets:
// h.symOffsetCount = h.strTableSize - h.strCount;
// h.symOffsetSize = (h.strTableSize - h.strCount) * 2;
2013-02-24 22:31:33 +00:00
2013-02-25 00:47:37 +00:00
Tput.prototype.parseExtended = function(data) {
2013-02-08 13:43:45 +00:00
var info = {}
, l = data.length
2013-02-25 00:47:37 +00:00
, i = 0;
2013-02-08 13:43:45 +00:00
2013-02-24 21:07:54 +00:00
var h = info.header = {
dataSize: data.length,
headerSize: 10,
boolCount: (data[i + 1] << 8) | data[i + 0],
numCount: (data[i + 3] << 8) | data[i + 2],
strCount: (data[i + 5] << 8) | data[i + 4],
strTableSize: (data[i + 7] << 8) | data[i + 6],
lastStrTableOffset: (data[i + 9] << 8) | data[i + 8]
};
// h.symOffsetCount = h.strTableSize - h.strCount;
2013-02-24 21:07:54 +00:00
h.total = h.headerSize
+ h.boolCount
+ h.numCount * 2
+ h.strCount * 2
+ h.strTableSize;
i = h.headerSize;
// Booleans Section
// One byte for each flag
// Same order as <term.h>
2013-02-24 22:43:26 +00:00
var _bools = [];
2013-02-24 21:07:54 +00:00
l = i + h.boolCount;
for (; i < l; i++) {
2013-02-24 22:43:26 +00:00
_bools.push(!!data[i]);
2013-02-24 21:07:54 +00:00
}
// Null byte in between to make sure numbers begin on an even byte.
if (i % 2) {
assert.equal(data[i], 0);
i++;
}
// Numbers Section
2013-02-24 22:43:26 +00:00
var _numbers = [];
2013-02-24 21:07:54 +00:00
l = i + h.numCount * 2;
for (; i < l; i += 2) {
if (data[i + 1] === 0377 && data[i] === 0377) {
2013-02-24 22:43:26 +00:00
_numbers.push(-1);
2013-02-24 21:07:54 +00:00
} else {
2013-02-24 22:43:26 +00:00
_numbers.push((data[i + 1] << 8) | data[i]);
2013-02-24 21:07:54 +00:00
}
}
// Strings Section
2013-02-24 22:43:26 +00:00
var _strings = [];
2013-02-24 21:07:54 +00:00
l = i + h.strCount * 2;
for (; i < l; i += 2) {
if (data[i + 1] === 0377 && data[i] === 0377) {
2013-02-24 22:43:26 +00:00
_strings.push(-1);
2013-02-24 21:07:54 +00:00
} else {
2013-02-24 22:43:26 +00:00
_strings.push((data[i + 1] << 8) | data[i]);
2013-02-24 21:07:54 +00:00
}
}
2013-02-25 00:22:32 +00:00
// Pass over the sym offsets and get to the string table.
2013-02-25 00:19:04 +00:00
i = data.length - h.lastStrTableOffset;
2013-02-25 08:09:17 +00:00
// Might be better to do this instead if the file has trailing bytes:
// i += h.symOffsetCount * 2;
2013-02-25 00:19:04 +00:00
2013-02-24 22:43:26 +00:00
// String Table
2013-02-25 00:43:04 +00:00
var high = 0;
2013-02-24 22:43:26 +00:00
_strings.forEach(function(offset, k) {
2013-02-24 21:07:54 +00:00
if (offset === -1) {
2013-02-24 22:43:26 +00:00
_strings[k] = '';
2013-02-24 22:31:33 +00:00
return;
2013-02-24 21:07:54 +00:00
}
var s = i + offset
, j = s;
while (data[j]) j++;
if (s >= data.length || j > data.length) {
2013-02-24 22:43:26 +00:00
_strings[k] = '';
2013-02-24 21:07:54 +00:00
return;
}
2013-02-25 00:43:04 +00:00
// Find out where the string table ends by
// getting the highest string length.
if (high < j - i) {
high = j - i;
}
2013-02-24 22:43:26 +00:00
_strings[k] = data.toString('ascii', s, j);
2013-02-08 13:43:45 +00:00
});
2013-02-24 21:07:54 +00:00
// Symbol Table
2013-02-25 00:43:04 +00:00
// Add one to the highest string length because we didn't count \0.
i += high + 1;
2013-02-24 21:07:54 +00:00
l = data.length;
var sym = []
, j;
2013-02-24 21:07:54 +00:00
for (; i < l; i++) {
j = i;
while (data[j]) j++;
sym.push(data.toString('ascii', i, j));
i = j;
}
2013-02-24 22:43:26 +00:00
// Identify by name
info.bools = {};
_bools.forEach(function(bool) {
info.bools[sym.shift()] = bool;
2013-02-24 21:07:54 +00:00
});
2013-02-24 22:43:26 +00:00
info.numbers = {};
_numbers.forEach(function(number) {
info.numbers[sym.shift()] = number;
2013-02-24 21:07:54 +00:00
});
2013-02-24 22:43:26 +00:00
info.strings = {};
_strings.forEach(function(string) {
info.strings[sym.shift()] = string;
2013-02-24 21:07:54 +00:00
});
2013-02-24 22:43:26 +00:00
2013-02-08 13:43:45 +00:00
return info;
};
2013-02-22 11:20:50 +00:00
/**
* Compiler - terminfo cap->javascript
*/
2013-02-16 21:11:05 +00:00
Tput.prototype.compile = function(key) {
var self = this
, info = this.info;
2013-02-20 00:35:26 +00:00
if (this.debug) {
console.log(this.info);
}
2013-02-16 21:11:05 +00:00
this.methods = {};
this.info.all = {};
Object.keys(info.bools).forEach(function(key) {
2013-02-17 19:25:58 +00:00
info.all[key] = info.bools[key];
2013-02-16 21:11:05 +00:00
});
Object.keys(info.numbers).forEach(function(key) {
2013-02-17 19:25:58 +00:00
info.all[key] = info.numbers[key];
2013-02-16 21:11:05 +00:00
});
2013-02-08 13:43:45 +00:00
2013-02-16 21:11:05 +00:00
Object.keys(info.strings).forEach(function(key) {
2013-02-17 19:25:58 +00:00
info.all[key] = info.strings[key];
2013-02-16 21:11:05 +00:00
});
Object.keys(info.all).forEach(function(key) {
2013-02-20 00:35:26 +00:00
if (self.debug) {
2013-02-22 11:20:50 +00:00
console.log('Compiling %s: %s', key, JSON.stringify(info.all[key]));
2013-02-20 00:35:26 +00:00
}
2013-02-16 21:11:05 +00:00
self.methods[key] = self._compile(info.all[key]);
2013-02-19 19:21:28 +00:00
});
2013-02-24 14:02:07 +00:00
Tput.bools.forEach(function(key) {
if (self.methods[key] == null) self.methods[key] = false;
});
Tput.numbers.forEach(function(key) {
if (self.methods[key] == null) self.methods[key] = -1;
});
Tput.strings.forEach(function(key) {
2013-02-19 19:21:28 +00:00
if (!self.methods[key]) self.methods[key] = noop;
2013-02-16 21:11:05 +00:00
});
2013-02-20 00:35:26 +00:00
2013-02-24 16:59:20 +00:00
Object.keys(this.methods).forEach(function(key) {
var alias = Tput.alias[key];
if (alias) {
if (!Array.isArray(alias)) alias = [alias];
alias.forEach(function(alias) {
2013-02-25 08:09:17 +00:00
if (self.methods[alias] && alias !== key && alias !== 'ML') {
// We can ignore `lines` and `ML` here.
throw new Error('Alias collision: ' + key + ' -> ' + alias);
}
2013-02-24 16:59:20 +00:00
self.methods[alias] = self.methods[key];
});
}
});
2013-02-20 00:35:26 +00:00
Object.keys(self.methods).forEach(function(key) {
2013-02-24 14:02:07 +00:00
if (typeof self.methods[key] !== 'function') {
self[key] = self.methods[key];
return;
}
2013-02-20 13:47:11 +00:00
self[key] = function() {
var args = Array.prototype.slice.call(arguments);
return self.methods[key].call(self, args);
};
2013-02-20 00:35:26 +00:00
});
2013-02-16 21:11:05 +00:00
};
Tput.prototype._compile = function(val) {
var self = this;
2013-02-08 13:43:45 +00:00
switch (typeof val) {
case 'boolean':
2013-02-24 13:39:29 +00:00
return val;
2013-02-08 13:43:45 +00:00
case 'number':
2013-02-24 13:39:29 +00:00
return val;
2013-02-08 13:43:45 +00:00
case 'string':
2013-02-16 21:11:05 +00:00
break;
default:
return function() {};
}
2013-02-25 06:40:46 +00:00
if (!val) {
return noop;
}
2013-02-25 01:20:56 +00:00
2013-02-20 20:01:01 +00:00
var code = 'var v, dyn = {}, stat = {}, stack = [], out = [];'
, buff = ''
, cap;
2013-02-20 13:47:11 +00:00
var ch
, op
, i
, v
2013-02-24 13:44:48 +00:00
var then
, els
, end;
2013-02-18 17:00:44 +00:00
function clear() {
2013-02-16 23:54:20 +00:00
if (buff) {
2013-02-22 09:40:58 +00:00
echo(JSON.stringify(buff).replace(/\\u001b/g, '\\x1b'));
2013-02-16 23:54:20 +00:00
buff = '';
}
}
2013-02-18 20:43:53 +00:00
function read(regex) {
2013-02-17 22:40:45 +00:00
cap = regex.exec(val);
if (!cap) return;
val = val.substring(cap[0].length);
ch = op = i = v = cap[1];
2013-02-18 17:00:44 +00:00
clear();
2013-02-17 22:40:45 +00:00
return cap;
}
2013-02-17 20:46:01 +00:00
2013-02-22 09:40:58 +00:00
function stmt(c) {
if (code[code.length-1] === ',') {
code = code.slice(0, -1);
}
code += c;
// code += ';' + c;
}
function expr(c) {
code += c + ',';
// code += '(' + c + '),';
}
function echo(c) {
expr('out.push(' + c + ')');
}
function print(c) {
echo('"' + c + '"');
2013-02-20 20:01:01 +00:00
}
2013-02-22 10:11:04 +00:00
function push(c) {
expr('(stack.push(v = ' + c + '), v)');
}
function pop(c) {
expr((c ? c + ' = ' : '') + 'stack.pop()');
}
2013-02-17 22:40:45 +00:00
while (val) {
2013-02-16 21:11:05 +00:00
// '\e' -> ^[
2013-02-18 20:43:53 +00:00
if (read(/^\\e/i)) {
2013-02-22 09:40:58 +00:00
print('\\x1b');
2013-02-16 21:11:05 +00:00
continue;
}
// '^A' -> ^A
2013-02-20 13:47:11 +00:00
if (read(/^\^(.)/i)) {
2013-02-22 10:11:04 +00:00
ch = ch.toUpperCase(); // ?
switch (ch) {
2013-02-16 21:11:05 +00:00
case '@':
2013-02-22 09:40:58 +00:00
ch = '\\x00';
2013-02-16 21:11:05 +00:00
break;
2013-02-22 10:11:04 +00:00
case '[':
ch = '\\x1b';
2013-02-16 21:11:05 +00:00
break;
case '\\':
2013-02-22 09:40:58 +00:00
ch = '\\x1c';
2013-02-16 21:11:05 +00:00
break;
2013-02-22 10:11:04 +00:00
case ']':
ch = '\\x1d';
break;
2013-02-16 21:11:05 +00:00
case '^':
2013-02-22 09:40:58 +00:00
ch = '\\x1e';
2013-02-16 21:11:05 +00:00
break;
case '_':
2013-02-22 09:40:58 +00:00
ch = '\\x1f';
2013-02-16 21:11:05 +00:00
break;
case '?':
2013-02-22 09:40:58 +00:00
ch = '\\x7f';
2013-02-16 21:11:05 +00:00
break;
2013-02-20 13:47:11 +00:00
default:
2013-02-22 10:11:04 +00:00
if (ch >= 'A' && ch <= 'Z') {
ch = ch.charCodeAt(0) - 64;
ch = ch.toString(16);
if (ch.length < 2) ch = '0' + ch;
ch = '\\x' + ch;
} else {
2013-02-24 02:38:24 +00:00
ch = cap[0];
2013-02-22 10:11:04 +00:00
}
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
}
2013-02-22 09:40:58 +00:00
print(ch);
2013-02-16 21:11:05 +00:00
continue;
}
// '\n' -> \n
// '\r' -> \r
// '\0' -> \200 (special case)
2013-02-18 20:43:53 +00:00
if (read(/^\\([nlrtbfs\^\\,:0])/)) {
2013-02-16 21:11:05 +00:00
switch (ch) {
case 'n':
2013-02-22 09:40:58 +00:00
ch = '\\n';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case 'l':
2013-02-22 09:40:58 +00:00
ch = '';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case 'r':
2013-02-22 09:40:58 +00:00
ch = '\\r';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case 't':
2013-02-22 09:40:58 +00:00
ch = '\\t';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case 'b':
2013-02-22 09:40:58 +00:00
ch = '\\x08';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case 'f':
2013-02-22 09:40:58 +00:00
ch = '\\x0c';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case 's':
2013-02-22 09:40:58 +00:00
ch = ' ';
2013-02-20 13:47:11 +00:00
break;
2013-02-24 14:19:38 +00:00
case '^':
ch = '^';
break;
2013-02-16 21:11:05 +00:00
case '\\':
2013-02-22 09:40:58 +00:00
ch = '\\\\';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case ',':
2013-02-22 09:40:58 +00:00
ch = ',';
2013-02-20 13:47:11 +00:00
break;
2013-02-24 14:19:38 +00:00
case ':':
ch = ':';
2013-02-20 13:47:11 +00:00
break;
2013-02-16 21:11:05 +00:00
case '0':
2013-02-22 09:40:58 +00:00
//ch = '\\0';
ch = '\\200';
2013-02-20 13:47:11 +00:00
break;
//case 'v':
2013-02-22 09:40:58 +00:00
// ch = '\\x0b';
2013-02-20 13:47:11 +00:00
// break;
//case 'a':
2013-02-22 09:40:58 +00:00
// ch = '\\x07':
2013-02-20 13:47:11 +00:00
// break;
2013-02-22 09:40:58 +00:00
default:
ch = '';
break;
2013-02-15 23:08:36 +00:00
}
2013-02-22 09:40:58 +00:00
print(ch);
2013-02-16 21:11:05 +00:00
continue;
}
2013-02-16 18:15:10 +00:00
2013-02-16 21:11:05 +00:00
// 3 octal digits -> character
2013-02-22 17:12:05 +00:00
if (read(/^\\(\d{3})/)) {
2013-02-22 09:40:58 +00:00
print('\\' + ch);
2013-02-16 21:11:05 +00:00
continue;
}
2013-02-16 18:15:10 +00:00
2013-02-16 21:11:05 +00:00
// $<5> -> padding
2013-02-19 19:21:28 +00:00
// e.g. flash_screen: '\u001b[?5h$<100/>\u001b[?5l',
2013-02-24 02:38:24 +00:00
if (read(/^\$<(\d+)([*\/]{0,2})>/)) {
if (this.padding) print(cap[0]);
2013-02-16 21:11:05 +00:00
continue;
}
// %% outputs `%'
2013-02-18 20:43:53 +00:00
if (read(/^%%/)) {
2013-02-22 09:40:58 +00:00
print('%');
2013-02-16 21:11:05 +00:00
continue;
}
// %[[:]flags][width[.precision]][doxXs]
// as in printf, flags are [-+#] and space. Use a `:' to allow the
// next character to be a `-' flag, avoiding interpreting "%-" as an
// operator.
2013-02-24 17:51:14 +00:00
if (read(/^%((?::-|[+# ]){1,4})?(\d+(?:\.\d+)?)?([doxXs])/)) {
2013-02-24 17:20:30 +00:00
// echo('sprintf("'+ cap[0].replace(':-', '-') + '", stack.pop())');
2013-02-24 14:22:37 +00:00
echo('stack.pop()');
2013-02-16 21:11:05 +00:00
continue;
}
// %c print pop() like %c in printf
2013-02-18 20:43:53 +00:00
if (read(/^%c/)) {
2013-02-24 17:20:30 +00:00
// echo('sprintf("%c", stack.pop())');
2013-02-24 18:42:02 +00:00
// echo('stack.pop()');
echo('String.fromCharCode(stack.pop())');
2013-02-16 21:11:05 +00:00
continue;
}
2013-02-24 13:53:18 +00:00
// %d print pop()
// "Print (e.g., "%d") is a special case."
2013-02-24 14:22:37 +00:00
//if (read(/^%d/)) {
// echo('stack.pop()');
// continue;
//}
2013-02-16 21:11:05 +00:00
// %s print pop() like %s in printf
2013-02-24 14:22:37 +00:00
//if (read(/^%s/)) {
// echo('stack.pop()');
// continue;
//}
2013-02-16 21:11:05 +00:00
// %p[1-9]
// push i'th parameter
2013-02-18 20:43:53 +00:00
if (read(/^%p([1-9])/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = params[' + (i - 1) + ']), v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %P[a-z]
// set dynamic variable [a-z] to pop()
2013-02-18 20:43:53 +00:00
if (read(/^%P([a-z])/)) {
2013-02-22 09:40:58 +00:00
expr('dyn.' + v + ' = stack.pop()');
2013-02-16 21:11:05 +00:00
continue;
}
// %g[a-z]
// get dynamic variable [a-z] and push it
2013-02-18 20:43:53 +00:00
if (read(/^%g([a-z])/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(dyn.' + v + '), dyn.' + v + ')');
2013-02-16 21:11:05 +00:00
continue;
}
// %P[A-Z]
// set static variable [a-z] to pop()
2013-02-18 20:43:53 +00:00
if (read(/^%P([A-Z])/)) {
2013-02-22 09:40:58 +00:00
expr('stat.' + v + ' = stack.pop()');
2013-02-16 21:11:05 +00:00
continue;
}
// %g[A-Z]
// get static variable [a-z] and push it
// The terms "static" and "dynamic" are misleading. Historically,
// these are simply two different sets of variables, whose values are
// not reset between calls to tparm. However, that fact is not
// documented in other implementations. Relying on it will adversely
// impact portability to other implementations.
2013-02-18 20:43:53 +00:00
if (read(/^%g([A-Z])/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = stat.' + v + '), v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %'c' char constant c
2013-02-18 20:43:53 +00:00
if (read(/^%'(\w)'/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = "' + ch + '", v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %{nn}
// integer constant nn
2013-02-18 20:43:53 +00:00
if (read(/^%\{(\d+)\}/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = ' + ch + '), v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %l push strlen(pop)
2013-02-18 20:43:53 +00:00
if (read(/^%l/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = stack.pop().length), v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %+ %- %* %/ %m
// arithmetic (%m is mod): push(pop() op pop())
// %& %| %^
// bit operations (AND, OR and exclusive-OR): push(pop() op pop())
// %= %> %<
// logical operations: push(pop() op pop())
2013-02-18 20:43:53 +00:00
if (read(/^%([+\-*\/m&|\^=><])/)) {
2013-02-16 21:11:05 +00:00
if (op === '=') op = '===';
else if (op === 'm') op = '%';
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = (stack.pop() ' + op + ' stack.pop())), v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %A, %O
// logical AND and OR operations (for conditionals)
2013-02-18 20:43:53 +00:00
if (read(/^%([AO])/)) {
2013-02-22 09:40:58 +00:00
stmt(op === ' A ' ? ' && ' : ' || ');
2013-02-16 21:11:05 +00:00
continue;
}
// %! %~
// unary operations (logical and bit complement): push(op pop())
2013-02-18 20:43:53 +00:00
if (read(/^%([!~])/)) {
2013-02-22 09:40:58 +00:00
expr('(stack.push(v = ' + op + 'stack.pop()), v)');
2013-02-16 21:11:05 +00:00
continue;
}
// %i add 1 to first two parameters (for ANSI terminals)
2013-02-18 20:43:53 +00:00
if (read(/^%i/)) {
2013-02-22 09:40:58 +00:00
expr('(params[0]++, params[1]++)');
2013-02-16 21:11:05 +00:00
continue;
}
// %? expr %t thenpart %e elsepart %;
// This forms an if-then-else. The %e elsepart is optional. Usually
// the %? expr part pushes a value onto the stack, and %t pops it from
// the stack, testing if it is nonzero (true). If it is zero (false),
// control passes to the %e (else) part.
// It is possible to form else-if's a la Algol 68:
// %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e %;
// where ci are conditions, bi are bodies.
// Use the -f option of tic or infocmp to see the structure of
// if-then-else's. Some strings, e.g., sgr can be very complicated when
// written on one line. The -f option splits the string into lines with
// the parts indented.
2013-02-18 20:43:53 +00:00
if (read(/^%\?/)) {
2013-02-22 09:40:58 +00:00
stmt(';if (');
2013-02-16 21:11:05 +00:00
continue;
}
2013-02-18 20:43:53 +00:00
if (read(/^%t/)) {
2013-02-22 09:40:58 +00:00
stmt(') {');
2013-02-16 21:11:05 +00:00
continue;
}
2013-02-18 20:43:53 +00:00
if (read(/^%e/)) {
2013-02-24 13:44:48 +00:00
then = val.indexOf('%t');
els = val.indexOf('%e');
end = val.indexOf('%;');
// Terminfo does elseif's like
// this: %?[expr]%t...%e[expr]%t...%;
2013-02-17 19:25:58 +00:00
if (then < end && then < els) {
2013-02-22 09:40:58 +00:00
stmt('} else if (');
2013-02-17 19:25:58 +00:00
} else {
2013-02-22 09:40:58 +00:00
stmt('} else {');
2013-02-17 19:25:58 +00:00
}
2013-02-16 21:11:05 +00:00
continue;
}
2013-02-18 20:43:53 +00:00
if (read(/^%;/)) {
2013-02-22 09:40:58 +00:00
stmt('}');
2013-02-16 21:11:05 +00:00
continue;
}
// Binary operations are in postfix form with the operands in the usual
// order. That is, to get x-5 one would use "%gx%{5}%-". %P and %g vari
// ables are persistent across escape-string evaluations.
// Consider the HP2645, which, to get to row 3 and column 12, needs to be
// sent \E&a12c03Y padded for 6 milliseconds. Note that the order of the
// rows and columns is inverted here, and that the row and column are
// printed as two digits. Thus its cup capability is
// “cup=6\E&%p2%2dc%p1%2dY”.
// The Microterm ACT-IV needs the current row and column sent
// preceded by a ^T, with the row and column simply encoded in
// binary, “cup=^T%p1%c%p2%c”. Terminals which use “%c” need to be able
// to backspace the cursor (cub1), and to move the cursor up one line
// on the screen (cuu1). This is necessary because it is not always safe
// to transmit \n ^D and \r, as the system may change or discard them.
// (The library routines dealing with terminfo set tty modes so that tabs
// are never expanded, so \t is safe to send. This turns out to be
// essential for the Ann Arbor 4080.)
// A final example is the LSI ADM-3a, which uses row and column offset
// by a blank character, thus “cup=\E=%p1%' '%+%c%p2%' '%+%c”. After
// sending `\E=', this pushes the first parameter, pushes the ASCII value
// for a space (32), adds them (pushing the sum on the stack in place of
// the two previous values) and outputs that value as a character.
// Then the same is done for the second parameter. More complex
// arithmetic is possible using the stack.
2013-02-16 23:54:20 +00:00
buff += val[0];
2013-02-16 21:11:05 +00:00
val = val.substring(1);
2013-02-08 13:43:45 +00:00
}
2013-02-18 17:00:44 +00:00
clear();
2013-02-17 19:25:58 +00:00
2013-02-22 09:40:58 +00:00
stmt(';return out.join("");');
2013-02-08 13:43:45 +00:00
2013-02-25 01:20:56 +00:00
// TODO: Make this less ridiculous.
2013-02-21 09:08:17 +00:00
// Optimize
// ... out.push("foo");return out.join("");
// To:
// return "foo";
v = code.split(/out = \[\];out\.push\(|\);return out/);
if (v.length === 3 && /^"[^"]+"$/.test(v[1])) {
code = 'return ' + v[1] + ';';
2013-02-25 01:20:56 +00:00
} else if (~code.indexOf('out = [];;return')) {
code = 'return "";';
2013-02-21 09:08:17 +00:00
}
2013-02-20 00:35:26 +00:00
if (this.debug) {
2013-02-21 09:08:17 +00:00
v = code
.replace(/\x1b/g, '\\x1b')
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n');
process.stdout.write(v + '\n');
2013-02-20 00:35:26 +00:00
}
2013-02-16 23:54:20 +00:00
try {
return new Function('params', code);
2013-02-24 18:42:02 +00:00
// return new Function('sprintf, params', code).bind(null, sprintf);
2013-02-16 23:54:20 +00:00
} catch (e) {
2013-02-18 17:00:44 +00:00
e.stack = e.stack.replace(/\x1b/g, '\\x1b');
throw e;
2013-02-16 23:54:20 +00:00
}
2013-02-08 13:43:45 +00:00
};
2013-02-24 18:58:29 +00:00
Tput.prototype._print =
2013-02-24 02:38:24 +00:00
Tput.prototype._parsePadding = function(code, print, done) {
2013-02-24 18:58:29 +00:00
var print = print || write
, done = done || noop;
2013-02-24 02:38:24 +00:00
if (!this.padding) {
print(code);
return done();
}
var parts = code.split(/(?=\$<\d+[*\/]{0,2}>)/)
, i = 0;
// if (!parts[0]) parts.shift();
(function next() {
if (i === parts.length) {
return done();
}
var part = parts[i++]
, padding = /^\$<(\d+)([*\/]{0,2})>/.exec(part);
if (!padding) {
print(part);
return next();
}
2013-02-24 14:13:25 +00:00
part = part.substring(padding[0].length);
2013-02-24 02:38:24 +00:00
// A `*' indicates that the padding required is proportional to the number
// of lines affected by the operation, and the amount given is the
// per-affected-unit padding required. (In the case of insert character,
// the factor is still the number of lines affected.) Normally, padding is
// advisory if the device has the xon capability; it is used for cost
// computation but does not trigger delays.
if (~padding[2].indexOf('*')) {
;
}
// A `/' suffix indicates that the padding is mandatory and forces a
// delay of the given number of milliseconds even on devices for which xon
// is present to indicate flow control.
if (~padding[2].indexOf('/')) {
;
}
return setTimeout(function() {
print(part);
return next();
}, +padding[1]);
})();
};
2013-02-08 13:43:45 +00:00
Tput.prototype.setupAliases = function(info) {
var self = this;
2013-02-24 16:59:20 +00:00
['bools', 'numbers', 'strings'].forEach(function(name) {
2013-02-08 13:43:45 +00:00
var obj = info[name];
Object.keys(obj).forEach(function(key) {
2013-02-22 11:20:50 +00:00
var alias = Tput.alias[key];
2013-02-24 16:59:20 +00:00
if (alias) {
if (!Array.isArray(alias)) alias = [alias];
alias.forEach(function(alias) {
obj[alias] = obj[key];
});
}
2013-02-08 13:43:45 +00:00
});
});
};
2013-02-22 21:51:13 +00:00
/**
* Termcap
*/
2013-02-22 22:12:34 +00:00
Tput.prototype.readTermcap = function() {
2013-02-22 21:51:13 +00:00
if (this.termcap) return;
this.termcap = {};
2013-02-23 22:03:39 +00:00
this.termcap.data = process.env.TERMCAP
|| fs.readFileSync('/etc/termcap', 'ascii');
2013-02-22 21:51:13 +00:00
2013-02-22 22:12:34 +00:00
this.termcap.terms = this.parseTermcap(this.termcap.data);
2013-02-22 21:51:13 +00:00
this.termcap.info = this.termcap.terms[this.term];
return this.termcap;
};
/**
* Termcap Parser
* http://en.wikipedia.org/wiki/Termcap
* http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html
* http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html#SEC17
* http://tldp.org/HOWTO/Text-Terminal-HOWTO.html#toc16
* man termcap
*/
// Example:
// vt102|dec vt102:\
// :do=^J:co#80:li#24:cl=50\E[;H\E[2J:\
// :le=^H:bs:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
// :ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
// :md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H:\
// :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\
// :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
// :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=5\EM:vt#3:\
// :sc=\E7:rc=\E8:cs=\E[%i%d;%dr:vs=\E[?7l:ve=\E[?7h:\
// :mi:al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:
2013-02-22 22:12:34 +00:00
Tput.prototype.parseTermcap = function(data) {
2013-02-22 21:51:13 +00:00
var terms = {}
, term
, entries
, fields
, field
, names
, i
, j
, k;
2013-02-22 21:51:13 +00:00
// remove escaped newlines
data = data.replace(/\\\n[ \t]*/g, '');
// remove comments
data = data.replace(/^#[^\n]+/gm, '');
// split entries
2013-02-24 13:40:42 +00:00
entries = data.trim().split(/\n+/);
2013-02-22 21:51:13 +00:00
for (i = 0; i < entries.length; i++) {
fields = entries[i].split(/:+/);
for (j = 0; j < fields.length; j++) {
field = fields[j].trim();
if (!field) continue;
if (j === 0) {
names = field.split('|');
term = {
2013-02-22 21:51:13 +00:00
name: names[0],
names: names,
desc: names.pop()
};
k = names.length;
while (k--) terms[names[k]] = term;
2013-02-22 21:51:13 +00:00
term.bools = {};
term.numbers = {};
term.strings = {};
2013-02-22 21:51:13 +00:00
continue;
}
if (~field.indexOf('=')) {
parts = field.split('=');
term.strings[parts[0]] = parts.slice(1).join('=');
} else if (~field.indexOf('#')) {
parts = field.split('#');
term.numbers[parts[0]] = +parts.slice(1).join('#');
} else {
term.bools[field] = true;
}
}
}
return terms;
};
/**
* Termcap Compiler
* man termcap
*/
Tput.prototype.compileTermcap = function() {
};
Tput.prototype._compileTermcap = function() {
};
2013-02-22 11:20:50 +00:00
/**
* Helpers
*/
function noop() {
return '';
}
noop.unsupported = true;
2013-02-24 16:59:20 +00:00
function merge(a, b) {
Object.keys(b).forEach(function(key) {
a[key] = b[key];
});
return a;
}
2013-02-24 18:58:29 +00:00
function write(data) {
return process.stdout.write(data);
}
2013-02-24 17:51:14 +00:00
/**
* sprintf
* http://www.cplusplus.com/reference/cstdio/printf/
*/
function sprintf(src) {
var params = Array.prototype.slice.call(arguments, 1)
, rule = /%([\-+# ]{1,4})?(\d+(?:\.\d+)?)?([doxXsc])/g
, i = 0;
return src.replace(rule, function(_, flag, width, type) {
var flags = flag.split('')
, param = params[i++] || ''
, initial = param
, width = +width
, opt = {}
, pre = '';
switch (type) {
case 'd': // signed int
param = (+param).toString(10);
break;
case 'o': // unsigned octal
param = (+param).toString(8);
break;
case 'x': // unsigned hex int
param = (+param).toString(16);
break;
case 'X': // unsigned hex int uppercase
param = (+param).toString(16).toUppercase();
break;
case 's': // string
break;
case 'c': // char
// Should return here?
param = isFinite(param)
? String.fromCharCode(param)
: param[0];
break;
}
flags.forEach(function(flag) {
switch (flag) {
// left-justify by width
case '-':
opt.left = true;
break;
// always precede numbers with their signs
case '+':
opt.signs = true;
break;
// used with o, x, X - value is preceded with 0, 0x, or 0X respectively.
// used with a, A, e, E, f, F, g, G - forces written output to contain
// a decimal point even if no more digits follow
case '#':
opt.hexpoint = true;
break;
// if no sign is going to be written, black space in front of the value
case ' ':
opt.space = true;
break;
}
});
if (opt.signs) {
if (+initial >= 0) {
pre += '+';
}
}
if (opt.space) {
if (!opt.signs && +initial >= 0) {
param = ' ' + param;
}
}
if (opt.hexpoint) {
switch (type) {
case 'o': // unsigned octal
pre += '0';
break;
case 'x': // unsigned hex int
pre += '0x';
break;
case 'X': // unsigned hex int uppercase
pre += '0X';
break;
}
}
if (opt.left) {
if (width > (pre.length + param.length)) {
width -= pre.length + param.length;
pre = Array(width + 1).join(' ') + pre;
}
}
return pre + param;
});
}
2013-02-22 11:20:50 +00:00
/**
2013-02-24 16:59:20 +00:00
* Aliases
2013-02-22 11:20:50 +00:00
*/
2013-02-24 16:59:20 +00:00
Tput.alias = require('./alias');
// Bools
merge(Tput.alias.bools, {
2013-02-22 11:20:50 +00:00
'no_esc_ctlc': 'beehive_glitch',
'dest_tabs_magic_smso': 'teleray_glitch',
2013-02-24 16:59:20 +00:00
});
// Numbers
merge(Tput.alias.numbers, {
2013-02-22 11:20:50 +00:00
'micro_col_size': 'micro_char_size'
2013-02-24 16:59:20 +00:00
});
// Merge into one object
merge(Tput.alias, Tput.alias.bools);
delete Tput.alias.bools;
merge(Tput.alias, Tput.alias.numbers);
delete Tput.alias.numbers;
merge(Tput.alias, Tput.alias.strings);
delete Tput.alias.strings;
// Make sure there are no collisions between cap and tcap.
2013-02-25 08:09:17 +00:00
Tput._vec = Object.keys(Tput.alias).map(function(key) {
return Array.isArray(Tput.alias[key])
? Tput.alias[key][0]
: Tput.alias[key];
});
Object.keys(Tput.alias).forEach(function(key) {
if (!Array.isArray(Tput.alias[key])) {
return;
}
var alias = Tput.alias[key]
, tcap = alias[1];
if (!tcap) return;
if (~Tput._vec.indexOf(tcap)) {
alias.splice(1, 1);
}
});
2013-02-25 08:09:17 +00:00
assert.equal(Tput.alias.exit_delete_mode[1], undefined);
2013-02-24 16:59:20 +00:00
/**
* Terminfo Data
*/
2013-02-22 11:20:50 +00:00
2013-02-08 13:43:45 +00:00
Tput.bools = [
'auto_left_margin',
'auto_right_margin',
'no_esc_ctlc',
'ceol_standout_glitch',
'eat_newline_glitch',
'erase_overstrike',
'generic_type',
'hard_copy',
'has_meta_key',
'has_status_line',
'insert_null_glitch',
'memory_above',
'memory_below',
'move_insert_mode',
'move_standout_mode',
'over_strike',
'status_line_esc_ok',
'dest_tabs_magic_smso',
'tilde_glitch',
'transparent_underline',
'xon_xoff',
'needs_xon_xoff',
'prtr_silent',
'hard_cursor',
'non_rev_rmcup',
'no_pad_char',
'non_dest_scroll_region',
'can_change',
'back_color_erase',
'hue_lightness_saturation',
'col_addr_glitch',
'cr_cancels_micro_mode',
'has_print_wheel',
'row_addr_glitch',
'semi_auto_right_margin',
'cpi_changes_res',
'lpi_changes_res',
// #ifdef __INTERNAL_CAPS_VISIBLE
'backspaces_with_bs',
'crt_no_scrolling',
'no_correctly_working_cr',
'gnu_has_meta_key',
'linefeed_is_newline',
'has_hardware_tabs',
'return_does_clr_eol'
];
Tput.numbers = [
'columns',
'init_tabs',
'lines',
'lines_of_memory',
'magic_cookie_glitch',
'padding_baud_rate',
'virtual_terminal',
'width_status_line',
'num_labels',
'label_height',
'label_width',
'max_attributes',
'maximum_windows',
'max_colors',
'max_pairs',
'no_color_video',
'buffer_capacity',
'dot_vert_spacing',
'dot_horz_spacing',
'max_micro_address',
'max_micro_jump',
'micro_col_size',
'micro_line_size',
'number_of_pins',
'output_res_char',
'output_res_line',
'output_res_horz_inch',
'output_res_vert_inch',
'print_rate',
'wide_char_size',
'buttons',
'bit_image_entwining',
'bit_image_type',
// #ifdef __INTERNAL_CAPS_VISIBLE
'magic_cookie_glitch_ul',
'carriage_return_delay',
'new_line_delay',
'backspace_delay',
'horizontal_tab_delay',
'number_of_function_keys'
];
Tput.strings = [
'back_tab',
'bell',
'carriage_return',
'change_scroll_region',
'clear_all_tabs',
'clear_screen',
'clr_eol',
'clr_eos',
'column_address',
'command_character',
'cursor_address',
'cursor_down',
'cursor_home',
'cursor_invisible',
'cursor_left',
'cursor_mem_address',
'cursor_normal',
'cursor_right',
'cursor_to_ll',
'cursor_up',
'cursor_visible',
'delete_character',
'delete_line',
'dis_status_line',
'down_half_line',
'enter_alt_charset_mode',
'enter_blink_mode',
'enter_bold_mode',
'enter_ca_mode',
'enter_delete_mode',
'enter_dim_mode',
'enter_insert_mode',
'enter_secure_mode',
'enter_protected_mode',
'enter_reverse_mode',
'enter_standout_mode',
'enter_underline_mode',
'erase_chars',
'exit_alt_charset_mode',
'exit_attribute_mode',
'exit_ca_mode',
'exit_delete_mode',
'exit_insert_mode',
'exit_standout_mode',
'exit_underline_mode',
'flash_screen',
'form_feed',
'from_status_line',
'init_1string',
'init_2string',
'init_3string',
'init_file',
'insert_character',
'insert_line',
'insert_padding',
'key_backspace',
'key_catab',
'key_clear',
'key_ctab',
'key_dc',
'key_dl',
'key_down',
'key_eic',
'key_eol',
'key_eos',
'key_f0',
'key_f1',
'key_f10',
'key_f2',
'key_f3',
'key_f4',
'key_f5',
'key_f6',
'key_f7',
'key_f8',
'key_f9',
'key_home',
'key_ic',
'key_il',
'key_left',
'key_ll',
'key_npage',
'key_ppage',
'key_right',
'key_sf',
'key_sr',
'key_stab',
'key_up',
'keypad_local',
'keypad_xmit',
'lab_f0',
'lab_f1',
'lab_f10',
'lab_f2',
'lab_f3',
'lab_f4',
'lab_f5',
'lab_f6',
'lab_f7',
'lab_f8',
'lab_f9',
'meta_off',
'meta_on',
'newline',
'pad_char',
'parm_dch',
'parm_delete_line',
'parm_down_cursor',
'parm_ich',
'parm_index',
'parm_insert_line',
'parm_left_cursor',
'parm_right_cursor',
'parm_rindex',
'parm_up_cursor',
'pkey_key',
'pkey_local',
'pkey_xmit',
'print_screen',
'prtr_off',
'prtr_on',
'repeat_char',
'reset_1string',
'reset_2string',
'reset_3string',
'reset_file',
'restore_cursor',
'row_address',
'save_cursor',
'scroll_forward',
'scroll_reverse',
'set_attributes',
'set_tab',
'set_window',
'tab',
'to_status_line',
'underline_char',
'up_half_line',
'init_prog',
'key_a1',
'key_a3',
'key_b2',
'key_c1',
'key_c3',
'prtr_non',
'char_padding',
'acs_chars',
'plab_norm',
'key_btab',
'enter_xon_mode',
'exit_xon_mode',
'enter_am_mode',
'exit_am_mode',
'xon_character',
'xoff_character',
'ena_acs',
'label_on',
'label_off',
'key_beg',
'key_cancel',
'key_close',
'key_command',
'key_copy',
'key_create',
'key_end',
'key_enter',
'key_exit',
'key_find',
'key_help',
'key_mark',
'key_message',
'key_move',
'key_next',
'key_open',
'key_options',
'key_previous',
'key_print',
'key_redo',
'key_reference',
'key_refresh',
'key_replace',
'key_restart',
'key_resume',
'key_save',
'key_suspend',
'key_undo',
'key_sbeg',
'key_scancel',
'key_scommand',
'key_scopy',
'key_screate',
'key_sdc',
'key_sdl',
'key_select',
'key_send',
'key_seol',
'key_sexit',
'key_sfind',
'key_shelp',
'key_shome',
'key_sic',
'key_sleft',
'key_smessage',
'key_smove',
'key_snext',
'key_soptions',
'key_sprevious',
'key_sprint',
'key_sredo',
'key_sreplace',
'key_sright',
'key_srsume',
'key_ssave',
'key_ssuspend',
'key_sundo',
'req_for_input',
'key_f11',
'key_f12',
'key_f13',
'key_f14',
'key_f15',
'key_f16',
'key_f17',
'key_f18',
'key_f19',
'key_f20',
'key_f21',
'key_f22',
'key_f23',
'key_f24',
'key_f25',
'key_f26',
'key_f27',
'key_f28',
'key_f29',
'key_f30',
'key_f31',
'key_f32',
'key_f33',
'key_f34',
'key_f35',
'key_f36',
'key_f37',
'key_f38',
'key_f39',
'key_f40',
'key_f41',
'key_f42',
'key_f43',
'key_f44',
'key_f45',
'key_f46',
'key_f47',
'key_f48',
'key_f49',
'key_f50',
'key_f51',
'key_f52',
'key_f53',
'key_f54',
'key_f55',
'key_f56',
'key_f57',
'key_f58',
'key_f59',
'key_f60',
'key_f61',
'key_f62',
'key_f63',
'clr_bol',
'clear_margins',
'set_left_margin',
'set_right_margin',
'label_format',
'set_clock',
'display_clock',
'remove_clock',
'create_window',
'goto_window',
'hangup',
'dial_phone',
'quick_dial',
'tone',
'pulse',
'flash_hook',
'fixed_pause',
'wait_tone',
'user0',
'user1',
'user2',
'user3',
'user4',
'user5',
'user6',
'user7',
'user8',
'user9',
'orig_pair',
'orig_colors',
'initialize_color',
'initialize_pair',
'set_color_pair',
'set_foreground',
'set_background',
'change_char_pitch',
'change_line_pitch',
'change_res_horz',
'change_res_vert',
'define_char',
'enter_doublewide_mode',
'enter_draft_quality',
'enter_italics_mode',
'enter_leftward_mode',
'enter_micro_mode',
'enter_near_letter_quality',
'enter_normal_quality',
'enter_shadow_mode',
'enter_subscript_mode',
'enter_superscript_mode',
'enter_upward_mode',
'exit_doublewide_mode',
'exit_italics_mode',
'exit_leftward_mode',
'exit_micro_mode',
'exit_shadow_mode',
'exit_subscript_mode',
'exit_superscript_mode',
'exit_upward_mode',
'micro_column_address',
'micro_down',
'micro_left',
'micro_right',
'micro_row_address',
'micro_up',
'order_of_pins',
'parm_down_micro',
'parm_left_micro',
'parm_right_micro',
'parm_up_micro',
'select_char_set',
'set_bottom_margin',
'set_bottom_margin_parm',
'set_left_margin_parm',
'set_right_margin_parm',
'set_top_margin',
'set_top_margin_parm',
'start_bit_image',
'start_char_set_def',
'stop_bit_image',
'stop_char_set_def',
'subscript_characters',
'superscript_characters',
'these_cause_cr',
'zero_motion',
'char_set_names',
'key_mouse',
'mouse_info',
'req_mouse_pos',
'get_mouse',
'set_a_foreground',
'set_a_background',
'pkey_plab',
'device_type',
'code_set_init',
'set0_des_seq',
'set1_des_seq',
'set2_des_seq',
'set3_des_seq',
'set_lr_margin',
'set_tb_margin',
'bit_image_repeat',
'bit_image_newline',
'bit_image_carriage_return',
'color_names',
'define_bit_image_region',
'end_bit_image_region',
'set_color_band',
'set_page_length',
'display_pc_char',
'enter_pc_charset_mode',
'exit_pc_charset_mode',
'enter_scancode_mode',
'exit_scancode_mode',
'pc_term_options',
'scancode_escape',
'alt_scancode_esc',
'enter_horizontal_hl_mode',
'enter_left_hl_mode',
'enter_low_hl_mode',
'enter_right_hl_mode',
'enter_top_hl_mode',
'enter_vertical_hl_mode',
'set_a_attributes',
'set_pglen_inch',
// #ifdef __INTERNAL_CAPS_VISIBLE
'termcap_init2',
'termcap_reset',
'linefeed_if_not_lf',
'backspace_if_not_bs',
'other_non_function_keys',
'arrow_key_map',
'acs_ulcorner',
'acs_llcorner',
'acs_urcorner',
'acs_lrcorner',
'acs_ltee',
'acs_rtee',
'acs_btee',
'acs_ttee',
'acs_hline',
'acs_vline',
'acs_plus',
'memory_lock',
'memory_unlock',
'box_chars_1'
];
2013-02-19 19:21:28 +00:00
/**
* Expose
*/
2013-02-24 17:51:14 +00:00
exports = Tput;
exports.sprintf = sprintf;
module.exports = exports;