forked from mlndz28/time-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.js
More file actions
137 lines (111 loc) · 4.57 KB
/
Copy pathoutput.js
File metadata and controls
137 lines (111 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.cliSuccess = exports.cliError = exports.outputVertical = exports.outputConfig = exports.sumarize = undefined;
var _moment = require('moment');
var _moment2 = _interopRequireDefault(_moment);
var _cliTable = require('cli-table2');
var _cliTable2 = _interopRequireDefault(_cliTable);
var _colors = require('colors');
var _colors2 = _interopRequireDefault(_colors);
var _utils = require('./utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var sumarize = exports.sumarize = function sumarize(search, tasks, rate, full, format) {
var table = new _cliTable2.default({
head: ['Name', 'Description', 'Dates', 'Duration'],
colAligns: ['left', 'center', 'center', 'left'],
chars: {
'top': '═',
'top-mid': '╤',
'top-left': '╔',
'top-right': '╗',
'bottom': '═',
'bottom-mid': '╧',
'bottom-left': '╚',
'bottom-right': '╝',
'left': '║',
'left-mid': '╟',
'right': '║',
'right-mid': '╢'
},
style: { head: ['green'] }
});
var total = 0;
var head = 'Search: ' + search + ' \n';
tasks.forEach(function (task, index) {
var description = task.task.description() && task.task.description() !== '' ? task.task.description() : '-';
var name = task.name;
task = task.task;
var duration = task.getSeconds();
total += duration;
// Avoid excesive width for proper console fit
var splitWidth = function splitWidth(str, len) {
var arr = [];
while (str != '') {
if (str.length > len) {
arr.push(str.substring(0, len));
str = str.substring(len);
} else {
arr.push(str);
break;
}
}
return arr.join('\n');
};
description = splitWidth(description, 51);
name = splitWidth(name, 40);
table.push([name, description, (0, _moment2.default)(task.getStartDate()).format(format), (0, _utils.humanParseDiff)(duration)]);
});
if (full) {
table.push([]);
if (rate) {
table.push([{ rowSpan: 2, content: _colors2.default.red('Search:') + ' "' + search + '"', vAlign: 'center' }, _colors2.default.red('Total time'), (0, _utils.humanParseDiff)(total)], [_colors2.default.red('Rate'), (0, _utils.calcRate)(rate, total)]);
} else {
table.push([{ rowSpan: 2, content: _colors2.default.red('Search:') + ' "' + search + '"', vAlign: 'center' }, { rowSpan: 2, content: '', vAlign: 'center' }, { rowSpan: 2, content: _colors2.default.red('Total time'), vAlign: 'center' }, { rowSpan: 2, content: (0, _utils.humanParseDiff)(total), vAlign: 'center' }], []);
}
}
console.log(table.toString());
};
var outputConfig = exports.outputConfig = function outputConfig(config) {
var table = new _cliTable2.default({
head: ['Key', 'value'],
chars: {
'top': '═',
'top-mid': '╤',
'top-left': '╔',
'top-right': '╗',
'bottom': '═',
'bottom-mid': '╧',
'bottom-left': '╚',
'bottom-right': '╝',
'left': '║',
'left-mid': '╟',
'right': '║',
'right-mid': '╢'
},
colAligns: ['center', 'center'],
style: { head: ['green'] }
});
Object.keys(config).map(function (e) {
return table.push([e, config[e]]);
});
console.log(table.toString());
};
var outputVertical = exports.outputVertical = function outputVertical() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var table2 = new _cliTable2.default();
var key = args.splice(0, 1);
table2.push(_defineProperty({}, key, args));
return table2.toString();
};
var cliError = exports.cliError = function cliError(err) {
console.error(_colors2.default.red('Error: ' + err));
};
var cliSuccess = exports.cliSuccess = function cliSuccess(err) {
console.log(_colors2.default.green(err));
};
//# sourceMappingURL=output.js.map