fix clock centering.

This commit is contained in:
Christopher Jeffrey 2013-10-16 06:27:03 -05:00
parent 3e12897b31
commit c8116f6569
2 changed files with 39 additions and 4 deletions

View File

@ -6,6 +6,18 @@
* https://github.com/chjj/blessed
*/
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.');
return process.exit(0);
}
var blessed = require('blessed');
var screen = blessed.screen({
@ -27,10 +39,20 @@ var container = blessed.box({
//}
});
// 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;
}
});
var date = blessed.box({
parent: screen,
top: 1,
left: 1,
//top: '80%',
//left: 'center',
width: 'shrink',
height: 'shrink',
border: {
@ -39,6 +61,8 @@ var date = blessed.box({
}
});
date.hide();
for (var i = 0; i < 10; i++) {
var symbols = positions[i] = {};
@ -853,12 +877,16 @@ function updateTime() {
s = '0' + s;
}
time = process.argv[2] === '-s'
time = ~argv.indexOf('-s')
? h + ':' + m + ':' + s + im
: h + ':' + m + im;
time = time.split('');
if (~argv.indexOf('-n')) {
if (time[0] === '0') time[0] = ' ';
}
Object.keys(positions).forEach(function(key) {
var symbols = positions[key];
Object.keys(symbols).forEach(function(key) {
@ -870,19 +898,22 @@ function updateTime() {
var symbols = positions[i]
, symbol = symbols[ch];
if (!symbol) return;
symbol.rleft = pos;
pos += symbol.width + 2;
symbol.show();
});
date.setContent(d.toISOString());
if (~argv.indexOf('-d')) {
date.show();
date.setContent(d.toISOString());
}
screen.render();
}
screen.render();
setInterval(updateTime, 1000);
updateTime();

View File

@ -818,6 +818,8 @@ Screen.prototype.cleanSides = function(el) {
};
Screen.prototype.draw = function(start, end) {
// this.emit('predraw');
var x
, y
, line
@ -1109,6 +1111,8 @@ Screen.prototype.draw = function(start, end) {
// this.program.output.write(pre + main + post);
this.program._write(pre + main + post);
}
// this.emit('draw');
};
Screen.prototype._reduceColor = function(col) {