neo-blessed/example/time.js

1048 lines
14 KiB
JavaScript
Raw Normal View History

2013-10-14 15:02:08 +00:00
#!/usr/bin/env node
2013-10-14 14:40:17 +00:00
/**
* A clock using blessed
* Copyright (c) 2013, Christopher Jeffrey (MIT License).
* https://github.com/chjj/blessed
*/
2013-10-16 11:27:03 +00:00
process.title = 'time.js';
var argv = process.argv;
if (~argv.indexOf('-h') || ~argv.indexOf('--help')) {
console.log('Options:');
console.log('-s - Show seconds.');
console.log('-n - No leading zero on hours.');
console.log('-d - Show date box.');
2015-01-28 04:39:00 +00:00
console.log('--skinny - Skinny text.');
2013-10-16 11:27:03 +00:00
return process.exit(0);
}
2013-10-14 15:02:08 +00:00
var blessed = require('blessed');
2013-10-14 14:40:17 +00:00
var screen = blessed.screen({
2013-10-14 15:06:20 +00:00
autoPadding: true
2013-10-14 14:40:17 +00:00
});
var positions = {};
var container = blessed.box({
parent: screen,
top: 'center',
left: 'center',
width: 'shrink',
2013-10-18 09:33:14 +00:00
height: 9,
2013-10-16 11:06:45 +00:00
//padding: 2,
//border: {
// type: 'line',
// fg: 'black'
//}
2013-10-14 14:40:17 +00:00
});
2013-10-16 11:27:03 +00:00
// Workaround for centering shrunken box.
container.on('prerender', function() {
var lpos = container._getCoords(true);
if (lpos) {
container.rleft = (screen.width - (lpos.xl - lpos.xi)) / 2 | 0;
}
});
2013-10-14 14:40:17 +00:00
var date = blessed.box({
parent: screen,
top: 1,
left: 1,
2013-10-16 11:27:03 +00:00
//top: '80%',
//left: 'center',
2013-10-14 14:40:17 +00:00
width: 'shrink',
height: 'shrink',
border: {
type: 'line',
fg: 'black'
}
});
2013-10-16 11:27:03 +00:00
date.hide();
2013-10-17 04:16:02 +00:00
var wid = ~argv.indexOf('--skinny') ? 1 : 2;
2015-01-28 04:39:00 +00:00
// var bch = ' ';
var bch = '│';
2013-10-16 19:01:53 +00:00
var inverse = true;
// var bch = '*';
// var bch = '·';
// var bch = '│';
// var bch = '◆';
// var bch = '▪';
// var inverse = false;
2013-10-17 04:16:02 +00:00
// TODO: Potentially make height of each char 9 instead
// of 8 so we can vertically center horizontal lines
// in 4, 8, etc.
2013-10-14 14:40:17 +00:00
for (var i = 0; i < 10; i++) {
var symbols = positions[i] = {};
/**
* Zero
*/
symbols[0] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[0],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[0],
top: 0,
left: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[0],
top: 0,
right: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[0],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[0].hide();
/**
* One
*/
symbols[1] = blessed.box({
parent: container,
top: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[1],
top: 0,
left: 'center',
width: 2,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[1].hide();
/**
* Two
*/
symbols[2] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[2],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[2],
top: 0,
right: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[2],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[2],
top: 4,
left: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[2],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[2].hide();
/**
* Three
*/
symbols[3] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[3],
top: 0,
bottom: 0,
right: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-18 09:33:14 +00:00
height: 9,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[3],
top: 0,
right: 0,
left: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[3],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
right: 0,
left: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[3],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
right: 0,
left: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[3].hide();
/**
* Four
*/
symbols[4] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[4],
top: 0,
bottom: 0,
right: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-18 09:33:14 +00:00
height: 9,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[4],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
right: 0,
left: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[4],
top: 0,
left: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-14 14:40:17 +00:00
height: 4,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[4].hide();
/**
* Five
*/
symbols[5] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[5],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[5],
top: 0,
left: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[5],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[5],
top: 4,
right: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[5],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[5].hide();
/**
* Six
*/
symbols[6] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[6],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[6],
top: 0,
left: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[6],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[6],
top: 4,
right: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[6],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[6].hide();
/**
* Seven
*/
symbols[7] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[7],
top: 0,
bottom: 0,
right: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-18 09:33:14 +00:00
height: 9,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[7],
top: 0,
right: 0,
left: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[7].hide();
/**
* Eight
*/
symbols[8] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[8],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[8],
top: 0,
left: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[8],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[8],
top: 0,
right: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[8],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[8].hide();
/**
* Nine
*/
symbols[9] = blessed.box({
parent: container,
top: 0,
left: 0,
width: 10,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[9],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[9],
top: 0,
left: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[9],
2013-10-18 09:33:14 +00:00
top: 4,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[9],
top: 0,
right: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[9],
2013-10-18 09:33:14 +00:00
top: 8,
2013-10-14 14:40:17 +00:00
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'default',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[9].hide();
/**
* Colon
*/
symbols[':'] = blessed.box({
parent: container,
top: 0,
left: 0,
2013-10-16 11:06:45 +00:00
width: 5,
2013-10-18 09:33:14 +00:00
height: 9
2013-10-14 14:40:17 +00:00
});
blessed.box({
parent: symbols[':'],
2013-10-18 09:33:14 +00:00
top: 3,
2013-10-16 11:06:45 +00:00
left: 'center',
width: 2,
2013-10-14 14:40:17 +00:00
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'black',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols[':'],
2013-10-18 09:33:14 +00:00
top: 6,
2013-10-16 11:06:45 +00:00
left: 'center',
width: 2,
2013-10-14 14:40:17 +00:00
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'black',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols[':'].hide();
/**
* A
*/
symbols['a'] = blessed.box({
parent: container,
2013-10-18 09:33:14 +00:00
top: 2,
2013-10-14 14:40:17 +00:00
left: 0,
width: 10,
height: 7
});
blessed.box({
parent: symbols['a'],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['a'],
top: 0,
left: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['a'],
top: 3,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['a'],
top: 0,
right: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols['a'].hide();
/**
* P
*/
symbols['p'] = blessed.box({
parent: container,
2013-10-18 09:33:14 +00:00
top: 2,
2013-10-14 14:40:17 +00:00
left: 0,
width: 10,
height: 7
});
blessed.box({
parent: symbols['p'],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['p'],
top: 0,
right: 0,
height: 4,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['p'],
top: 0,
left: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['p'],
top: 3,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'blue',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols['p'].hide();
/**
* M
*/
symbols['m'] = blessed.box({
parent: container,
2013-10-18 09:33:14 +00:00
top: 2,
2013-10-14 14:40:17 +00:00
left: 0,
width: 10,
height: 7
});
blessed.box({
parent: symbols['m'],
top: 0,
left: 0,
right: 0,
height: 1,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'black',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['m'],
top: 0,
left: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'black',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['m'],
top: 0,
right: 0,
bottom: 0,
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'black',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
blessed.box({
parent: symbols['m'],
top: 0,
bottom: 0,
left: 'center',
2013-10-17 04:16:02 +00:00
width: wid,
2013-10-16 19:01:53 +00:00
ch: bch,
2013-10-14 14:40:17 +00:00
style: {
2013-10-16 19:01:53 +00:00
fg: 'black',
inverse: inverse
2013-10-14 14:40:17 +00:00
}
});
symbols['m'].hide();
}
function updateTime() {
2013-10-14 15:02:08 +00:00
var pos = 0
, d = new Date
2013-10-14 14:40:17 +00:00
, im = 'am'
, time
, h
, m
, s;
h = d.getHours();
2013-10-14 15:06:20 +00:00
if (h >= 12) {
2013-10-14 14:40:17 +00:00
im = 'pm';
2013-10-14 15:06:20 +00:00
}
if (h > 12) {
2013-10-14 14:40:17 +00:00
h -= 12;
}
2013-10-18 09:33:14 +00:00
if (h === 0) h = 12;
2013-10-14 14:40:17 +00:00
if (h < 10) {
h = '0' + h;
}
m = d.getMinutes();
if (m < 10) {
m = '0' + m;
}
s = d.getSeconds();
if (s < 10) {
s = '0' + s;
}
2013-10-16 11:27:03 +00:00
time = ~argv.indexOf('-s')
2013-10-14 15:06:20 +00:00
? h + ':' + m + ':' + s + im
: h + ':' + m + im;
2013-10-14 14:40:17 +00:00
time = time.split('');
2013-10-16 11:27:03 +00:00
if (~argv.indexOf('-n')) {
if (time[0] === '0') time[0] = ' ';
}
2013-10-14 14:40:17 +00:00
Object.keys(positions).forEach(function(key) {
var symbols = positions[key];
Object.keys(symbols).forEach(function(key) {
symbols[key].hide();
});
});
time.forEach(function(ch, i) {
2013-10-14 15:06:20 +00:00
var symbols = positions[i]
, symbol = symbols[ch];
2013-10-16 11:27:03 +00:00
if (!symbol) return;
2013-10-14 14:40:17 +00:00
symbol.rleft = pos;
2013-10-16 11:06:45 +00:00
pos += symbol.width + 2;
2013-10-14 15:06:20 +00:00
2013-10-14 14:40:17 +00:00
symbol.show();
});
2013-10-16 11:27:03 +00:00
if (~argv.indexOf('-d')) {
date.show();
2015-01-28 04:39:00 +00:00
date.setContent(d.toISOString().replace(/\.\d+/, ''));
2013-10-16 11:27:03 +00:00
}
2013-10-14 14:40:17 +00:00
screen.render();
}
2013-10-17 04:16:02 +00:00
setInterval(updateTime, 950);
2013-10-14 15:02:08 +00:00
2013-10-14 14:40:17 +00:00
updateTime();
screen.key('q', function() {
process.exit(0);
});