update CliUX display to something more compact

This commit is contained in:
tknew2 2014-04-09 16:12:47 +08:00
parent 2726eb92e1
commit 72fca4e7a5

View File

@ -1,7 +1,8 @@
var Table = require('cli-table');
var Table = require('cli-table');
var sprintf = require('util').format;
var p = require('path');
var UX = module.exports = {};
var p = require('path');
var UX = module.exports = {};
require('colors');
UX.miniDisplay = function(list) {
@ -31,8 +32,9 @@ UX.miniDisplay = function(list) {
UX.dispAsTable = function(list) {
var table = new Table({
head: ["App Name", "id", "mode","PID","status", "port", "Restarted", "Uptime", "memory", "err logs"],
colAligns : ['left', 'left', 'left', 'left','left', 'left', 'right', 'left', 'right']
head: ['app name', 'id', 'mode','pid','status', 'port', 'restarted', 'uptime', 'memory', 'error logs'],
colAligns : ['left', 'left', 'left', 'left','left', 'left', 'left', 'left', 'left'],
style : {'padding-left' : 1, head : ['cyan', 'bold'], border : ['white'], compact : true}
});
list.forEach(function(l) {
@ -71,38 +73,6 @@ UX.processing = {
}
};
// UX.processing = {
// start : function() {
// // Code grabbed from Mocha by Visionmedia/Tj
// // https://github.com/visionmedia/mocha/blob/master/bin/_mocha
// var spinner = 'win32' == process.platform
// ? ['|','/','-','\\']
// : ['◜','◠','◝','◞','◡','◟'];
// function play(arr, interval) {
// var len = arr.length
// , interval = interval || 100
// , i = 0;
// timer = setInterval(function(){
// var str = arr[i++ % len];
// process.stdout.write('\u001b[0G' + str);
// }, interval);
// }
// var frames = spinner.map(function(c) {
// return sprintf(' \u001b[96m%s \u001b[90mProcessing...\u001b[0m', c);
// });
// play(frames, 70);
// },
// stop : function() {
// process.stdout.write('\u001b[0G\u001b[2K');
// clearInterval(timer);
// }
// };
UX.bytesToSize = function(bytes, precision) {
var kilobyte = 1024;
var megabyte = kilobyte * 1024;
@ -131,23 +101,23 @@ function timeSince(date) {
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return interval + "y";
return interval + 'y';
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return interval + "m";
return interval + 'm';
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return interval + "d";
return interval + 'd';
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return interval + "h";
return interval + 'h';
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return interval + "m";
return interval + 'm';
}
return Math.floor(seconds) + "s";
return Math.floor(seconds) + 's';
}