neo-blessed/test/tput.js

149 lines
4.2 KiB
JavaScript
Raw Normal View History

/**
* Tput for node.js
* Copyright (c) 2013, Christopher Jeffrey (MIT License)
* https://github.com/chjj/blessed
*/
2013-03-05 08:58:03 +00:00
// Compile xterm terminfo/termcap:
// $ tic -a -I -1 usr/xterm.terminfo
// $ tic -a -C -U usr/xterm.termcap
// Compile xterm terminfo/termcap:
// $ tic -a -1 usr/xterm.terminfo
// $ tic -a -1 usr/xterm.terminfo && ls ~/.terminfo
// $ tic -a -1 -o usr usr/xterm.terminfo && mv usr/x/xterm usr/ && rm -rf usr/v usr/x
2013-03-06 10:27:42 +00:00
// $ tic -a -1 -o usr usr/xterm.terminfo && mv usr/x/xterm-256color usr/ && rm -rf usr/v usr/x
2013-03-05 08:58:03 +00:00
// Check tput output:
2013-03-05 08:35:36 +00:00
// $ node test/tput.js xterm | tee out
2013-03-05 20:31:34 +00:00
// $ node test/tput.js xterm --ifile usr/xterm | tee out
2013-03-06 10:27:42 +00:00
// $ node test/tput.js xterm-256color --ifile usr/xterm-256color | tee out
// $ node test/tput.js vt102 --termcap | tee out
2013-03-05 08:35:36 +00:00
// $ node test/tput.js xterm --termcap --cfile usr/xterm.termcap | tee out
// $ node test/tput.js xterm --iprefix ~/.terminfo | tee out
// $ node test/tput.js xterm-256color --ifile ~/.terminfo/x/xterm-256color | tee out
// $ cdiff test/terminfo out
2013-07-18 22:56:05 +00:00
var blessed = require('../');
2013-02-15 17:42:52 +00:00
// Simple argument parser
// Copyright (c) 2012, Christopher Jeffrey (MIT License)
function parseArg() {
var argv = process.argv.slice(2)
, options = [];
function getarg() {
var arg = argv.shift();
if (arg.indexOf('--') === 0) {
// e.g. --opt
arg = arg.split('=');
if (arg.length > 1) {
// e.g. --opt=val
argv.unshift(arg.slice(1).join('='));
}
arg = arg[0];
} else if (arg[0] === '-') {
if (arg.length > 2) {
// e.g. -abc
argv = arg.substring(1).split('').map(function(ch) {
return '-' + ch;
}).concat(argv);
arg = argv.shift();
} else {
// e.g. -a
}
} else {
// e.g. foo
}
return arg;
}
while (argv.length) {
arg = getarg();
if (arg.indexOf('-') === 0) {
arg = arg.replace(/^--?/, '');
if (argv[0] && argv[0].indexOf('-') !== 0) {
options[arg] = argv.shift();
} else {
options[arg] = true;
}
} else {
options.push(arg);
}
}
return options;
}
var argv = parseArg();
2013-02-27 23:17:26 +00:00
2013-07-18 22:56:05 +00:00
var tput = blessed.tput({
2013-07-23 05:22:49 +00:00
term: argv[0] && argv[0] !== 'all' && argv[0] !== 'rand' ? argv[0] : 'xterm',
extended: true,
2013-02-28 00:30:14 +00:00
debug: true,
2013-03-05 08:35:36 +00:00
termcap: argv.termcap,
terminfoFile: argv.i || argv.ifile,
terminfoPrefix: argv.p || argv.iprefix,
termcapFile: argv.c || argv.cfile
2013-02-24 13:53:18 +00:00
});
2013-02-15 17:42:52 +00:00
if (!argv[0] || argv[0] === 'all') {
console.log('');
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var text = '\x1b[31mWARNING:\x1b[m '
+ 'This will compile every single terminfo file on your disk.\n'
+ 'It will probably use a lot of CPU.\n'
+ 'Do you wish to proceed? (Y/n) ';
rl.question(text, function(result) {
result = result.trim().toLowerCase();
if (result !== 'y') return process.exit(0);
console.log('\x1b[32m(You bet your ass I wish to proceed.)\x1b[m');
setTimeout(function() { process.stdout.write('.'); }, 1000);
setTimeout(function() { process.stdout.write('.'); }, 2000);
setTimeout(function() { process.stdout.write('.'); }, 3000);
setTimeout(function() {
console.log('Let\'s go...');
}, 3000);
setTimeout(function() {
tput.compileAll(argv[1]);
process.exit(0);
}, 4000);
});
return;
}
2013-07-23 05:22:49 +00:00
if (argv[0] === 'rand') {
var terms = tput.getAll();
var term = terms[(terms.length - 1) * Math.random() | 0];
console.log('Compiling ' + term + '...');
tput.compileTerminfo(term);
return;
}
// console.log('Max colors: %d.', tput.colors);
2013-02-16 23:54:20 +00:00
2013-07-14 08:14:48 +00:00
// console.log(tput.strings.acs_chars.split('').map(function(ch) { return ch.charCodeAt(0); }));
// console.log(JSON.stringify(tput.strings.acs_chars));
2013-07-18 22:56:05 +00:00
// process.stdout.write(blessed.tput.sprintf('%-10s\n', 'hello'));
2013-02-24 17:51:14 +00:00
// tput._compile('%?%p9%t\u001b(0%e\u001b(B%;\u001b[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m');
2013-02-18 20:43:53 +00:00
// console.log(tput.setaf(4) + 'foo' + tput.sgr0());
// console.log(tput.setaf(4) + 'foo' + tput.sgr(0));
2013-02-22 21:51:13 +00:00
// tput.padding = true;
// tput._print('hello$<1000/>world', console.log, function() {
// tput._print('$<1000*>foo$<1000/>bar', console.log, process.exit);
// });