smartlog-destination-local/ts/beautylog.classes.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-02-23 13:34:40 +00:00
/// <reference path="./typings/main.d.ts" />
import plugins = require("./beautylog.plugins");
2015-12-20 22:14:22 +00:00
var tableHelpers = {
makeRow: function(cellCounterArg:number = 2,colorArg:string = "cyan"){
var rowArray = [];
for (var i = 0; i < (cellCounterArg); i++) {
rowArray.push(String(i + 1).cyan);
}
return rowArray;
}
};
2015-11-15 05:15:20 +00:00
2016-02-23 13:34:40 +00:00
export class ConsoleTable {
2015-11-15 05:15:20 +00:00
tableHead:string[];
rows;
type:string;
2015-12-20 22:14:22 +00:00
constructor(tableTypeArg:string,tableHeadArrayArg:string[] = tableHelpers.makeRow()) {
switch (tableTypeArg) {
2015-11-15 05:15:20 +00:00
case "checks":
this.tableHead = ['Check Item:'.cyan,'Status:'.cyan];
break;
2015-12-20 22:14:22 +00:00
case "custom":
this.tableHead = tableHeadArrayArg;
break;
2015-11-15 05:15:20 +00:00
default:
break;
}
this.rows = [];
2015-12-20 22:14:22 +00:00
this.type = tableTypeArg;
2015-11-15 05:15:20 +00:00
}
push(row:string[]){
this.rows.push(row);
}
2015-11-13 21:53:28 +00:00
print() {
2016-02-23 13:34:40 +00:00
var table = new plugins.cliTable({
2015-12-20 22:14:22 +00:00
head: this.tableHead
2015-11-15 05:15:20 +00:00
});
for (var row in this.rows){
if(this.rows[row][1] == "success"){
this.rows[row][1] = ' '.bgGreen + ' ' + this.rows[row][1];
} else if (this.rows[row][1] == "error") {
this.rows[row][1] = ' '.bgRed + ' ' + this.rows[row][1];
}
table.push(this.rows[row]);
};
console.log(table.toString());
2015-11-13 21:53:28 +00:00
}
2015-11-15 05:15:20 +00:00
}