neo-blessed/test/widget-png.js

108 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-06-29 05:46:04 +00:00
var blessed = require('../');
var fs = require('fs');
2015-06-30 05:16:18 +00:00
var argv = {};
process.argv = process.argv.map(function(arg, i) {
2015-06-30 07:23:15 +00:00
if (/^--\w+=/.test(arg)) {
2015-06-30 05:16:18 +00:00
arg = arg.split('=');
if (/^[0-9.]+$/.test(arg[1])) arg[1] = +arg[1];
2015-06-30 07:23:15 +00:00
argv[arg[0].replace(/^--/, '')] = arg[1];
2015-06-30 05:16:18 +00:00
return;
}
if (arg.indexOf('--') === 0) {
arg = arg.slice(2);
argv[arg] = true;
return;
}
return arg;
}).filter(Boolean);
2015-06-29 05:46:04 +00:00
var screen = blessed.screen({
tput: true,
smartCSR: true,
2015-07-22 02:23:57 +00:00
dump: __dirname + '/logs/png.log',
warnings: true
2015-06-29 05:46:04 +00:00
});
2015-06-30 05:16:18 +00:00
var box1 = blessed.box({
2015-06-29 05:46:04 +00:00
parent: screen,
left: 4,
top: 3,
width: 10,
height: 6,
border: 'line',
style: {
bg: 'green'
},
2015-06-30 05:16:18 +00:00
content: fs.readFileSync(__dirname + '/lorem.txt', 'utf8')
});
var box2 = blessed.box({
parent: screen,
left: 20,
top: 8,
width: 40,
height: 15,
border: 'line',
style: {
bg: 'green'
},
content: fs.readFileSync(__dirname + '/lorem.txt', 'utf8')
2015-06-29 05:46:04 +00:00
});
var file = process.argv[2];
var testImage = __dirname + '/test-image.png';
var spinfox = __dirname + '/spinfox.png';
// XXX I'm not sure of the license of this file,
// so I'm not going to redistribute it in the repo.
var url = 'https://people.mozilla.org/~dolske/apng/spinfox.png';
if (!file) {
try {
if (!fs.existsSync(spinfox)) {
var buf = blessed.ansiimage.curl(url);
2015-06-29 05:46:04 +00:00
fs.writeFileSync(spinfox, buf);
}
file = spinfox;
} catch (e) {
file = testImage;
}
}
2015-06-30 05:16:18 +00:00
if (!argv.width && !argv.height && !argv.scale) {
argv.width = 20;
}
var png = blessed.image({
2015-06-29 05:46:04 +00:00
parent: screen,
// border: 'line',
2015-06-30 05:16:18 +00:00
width: argv.width,
height: argv.height,
2015-06-29 05:46:04 +00:00
top: 2,
left: 0,
file: file,
2015-06-30 05:16:18 +00:00
draggable: true,
2015-07-18 21:40:51 +00:00
type: 'ansi',
2015-06-30 05:16:18 +00:00
scale: argv.scale,
ascii: argv.ascii,
optimization: argv.optimization,
speed: argv.speed
2015-06-29 05:46:04 +00:00
});
screen.render();
screen.key('q', function() {
process.exit(0);
});
var timeout = setInterval(function() {
png.left++;
screen.render();
}, 100);
png.on('mousedown', function() {
clearInterval(timeout);
});