Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit 88924aa

Browse files
committed
Merge branch 'master' into panel_class
2 parents 07b9a7b + dfeaec1 commit 88924aa

14 files changed

+647
-0
lines changed

lib/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var AGGREGATE_TIME_LEVELS = [
2323
"3600000"
2424
];
2525

26+
var MILLISECONDS_PER_SECOND = 1000;
27+
2628
// this array object is used to reduce ms to its highest human-readable form
2729
// see lib/providers/metrics-provider.js::getTimeIndexLabel
2830
var TIME_SCALES = [
@@ -49,5 +51,6 @@ var TIME_SCALES = [
4951

5052
module.exports = {
5153
AGGREGATE_TIME_LEVELS: AGGREGATE_TIME_LEVELS,
54+
MILLISECONDS_PER_SECOND: MILLISECONDS_PER_SECOND,
5255
TIME_SCALES: TIME_SCALES
5356
};

lib/layout-config-schema.json

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
"$ref": "#/definitions/lineGraphView"
3030
}, {
3131
"$ref": "#/definitions/customView"
32+
}, {
33+
"$ref": "#/definitions/cpuDetailsView"
34+
}, {
35+
"$ref": "#/definitions/envDetailsView"
36+
}, {
37+
"$ref": "#/definitions/nodeDetailsView"
38+
}, {
39+
"$ref": "#/definitions/systemDetailsView"
40+
}, {
41+
"$ref": "#/definitions/userDetailsView"
3242
}]
3343
}
3444
}
@@ -127,6 +137,96 @@
127137
},
128138
"required": ["module"]
129139
},
140+
"cpuDetailsView": {
141+
"type": "object",
142+
"properties": {
143+
"title": {
144+
"type": "string"
145+
},
146+
"borderColor": {
147+
"type": "string"
148+
},
149+
"type": {
150+
"enum": ["cpuDetails"]
151+
},
152+
"position": {
153+
"$ref": "#/definitions/position"
154+
}
155+
},
156+
"required": ["type"]
157+
},
158+
"envDetailsView": {
159+
"type": "object",
160+
"properties": {
161+
"title": {
162+
"type": "string"
163+
},
164+
"borderColor": {
165+
"type": "string"
166+
},
167+
"type": {
168+
"enum": ["envDetails"]
169+
},
170+
"position": {
171+
"$ref": "#/definitions/position"
172+
}
173+
},
174+
"required": ["type"]
175+
},
176+
"nodeDetailsView": {
177+
"type": "object",
178+
"properties": {
179+
"title": {
180+
"type": "string"
181+
},
182+
"borderColor": {
183+
"type": "string"
184+
},
185+
"type": {
186+
"enum": ["nodeDetails"]
187+
},
188+
"position": {
189+
"$ref": "#/definitions/position"
190+
}
191+
},
192+
"required": ["type"]
193+
},
194+
"systemDetailsView": {
195+
"type": "object",
196+
"properties": {
197+
"title": {
198+
"type": "string"
199+
},
200+
"borderColor": {
201+
"type": "string"
202+
},
203+
"type": {
204+
"enum": ["systemDetails"]
205+
},
206+
"position": {
207+
"$ref": "#/definitions/position"
208+
}
209+
},
210+
"required": ["type"]
211+
},
212+
"userDetailsView": {
213+
"type": "object",
214+
"properties": {
215+
"title": {
216+
"type": "string"
217+
},
218+
"borderColor": {
219+
"type": "string"
220+
},
221+
"type": {
222+
"enum": ["userDetails"]
223+
},
224+
"position": {
225+
"$ref": "#/definitions/position"
226+
}
227+
},
228+
"required": ["type"]
229+
},
130230
"position": {
131231
"oneOf": [{
132232
"type": "object",

lib/views/base-details-view.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use strict";
2+
3+
var blessed = require("blessed");
4+
var _ = require("lodash");
5+
var BaseView = require("./base-view");
6+
7+
var BaseDetailsView = function BaseDetailsView(options) {
8+
BaseView.call(this, options);
9+
10+
this.screen = options.parent.screen;
11+
this.node = blessed.box(this.layoutConfig);
12+
this.parent.append(this.node);
13+
14+
this.refreshContent();
15+
this.recalculatePosition();
16+
};
17+
18+
BaseDetailsView.prototype = Object.create(BaseView.prototype);
19+
20+
BaseDetailsView.prototype.refreshContent = function () {
21+
this.node.setContent(this._getBoxContent(this.getDetails()));
22+
this.screen.render();
23+
};
24+
25+
BaseDetailsView.prototype.getDetails = function () {
26+
return [];
27+
};
28+
29+
/**
30+
* Given data and optional filters, return the content for a box.
31+
*
32+
* @param {Object[]} data
33+
* This is the array of label/data objects that define each data
34+
* point for the box.
35+
*
36+
* @returns {String}
37+
* The content string for the box is returned.
38+
*/
39+
BaseDetailsView.prototype._getBoxContent = function (data) {
40+
var longestLabel = _.reduce(data, function (prev, detail) {
41+
return Math.max(prev, detail.label.length);
42+
}, 0);
43+
44+
var getFormattedContent = function (prev, details) {
45+
prev += "{cyan-fg}{bold}" + details.label + "{/}"
46+
+ _.repeat(" ", longestLabel - details.label.length + 1)
47+
+ "{green-fg}" + details.data + "{/}\n";
48+
return prev;
49+
};
50+
51+
return _.trimEnd(_.reduce(data, getFormattedContent, ""), "\n");
52+
};
53+
54+
module.exports = BaseDetailsView;

lib/views/cpu-details-view.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use strict";
2+
3+
var os = require("os");
4+
var _ = require("lodash");
5+
var BaseDetailsView = require("./base-details-view");
6+
7+
var CpuDetailsView = function CpuDetailsView(options) {
8+
BaseDetailsView.call(this, options);
9+
};
10+
11+
CpuDetailsView.prototype = Object.create(BaseDetailsView.prototype);
12+
13+
CpuDetailsView.prototype.getDetails = function () {
14+
var cpuInfo = os.cpus();
15+
16+
return _.map(cpuInfo, function (info, index) {
17+
return {
18+
label: "[" + index + "]",
19+
data: info.model + " " + info.speed
20+
};
21+
});
22+
};
23+
24+
CpuDetailsView.prototype.getDefaultLayoutConfig = function () {
25+
return {
26+
label: " CPU(s) ",
27+
border: "line",
28+
tags: true,
29+
style: {
30+
border: {
31+
fg: "white"
32+
}
33+
}
34+
};
35+
};
36+
37+
module.exports = CpuDetailsView;

lib/views/env-details-view.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use strict";
2+
3+
var _ = require("lodash");
4+
var BaseDetailsView = require("./base-details-view");
5+
6+
var EnvDetailsView = function EnvDetailsView(options) {
7+
BaseDetailsView.call(this, options);
8+
};
9+
10+
EnvDetailsView.prototype = Object.create(BaseDetailsView.prototype);
11+
12+
EnvDetailsView.prototype.getDefaultLayoutConfig = function () {
13+
return {
14+
label: " Environment Variables ",
15+
border: "line",
16+
style: {
17+
border: {
18+
fg: "white"
19+
}
20+
},
21+
tags: true,
22+
scrollable: true,
23+
keys: true,
24+
input: true,
25+
scrollbar: {
26+
style: {
27+
fg: "white",
28+
inverse: true
29+
},
30+
track: {
31+
ch: ":",
32+
fg: "cyan"
33+
}
34+
}
35+
};
36+
};
37+
38+
EnvDetailsView.prototype.getDetails = function () {
39+
return _.map(process.env, function (value, key) {
40+
return {
41+
label: key,
42+
data: value
43+
};
44+
});
45+
};
46+
47+
module.exports = EnvDetailsView;

lib/views/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ var MemoryGaugeView = require("./memory-gauge-view");
77
var MemoryGraphView = require("./memory-graph-view");
88
var CpuView = require("./cpu-view");
99
var BaseView = require("./base-view");
10+
var CpuDetailsView = require("./cpu-details-view");
11+
var EnvDetailsView = require("./env-details-view");
12+
var NodeDetailsView = require("./node-details-view");
13+
var SystemDetailsView = require("./system-details-view");
14+
var UserDetailsView = require("./user-details-view");
1015
var Panel = require("./panel");
1116

1217
var VIEW_MAP = {
18+
cpuDetails: CpuDetailsView,
19+
envDetails: EnvDetailsView,
20+
nodeDetails: NodeDetailsView,
21+
systemDetails: SystemDetailsView,
22+
userDetails: UserDetailsView,
1323
log: StreamView,
1424
cpu: CpuView,
1525
memory: MemoryGaugeView,

lib/views/node-details-view.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";
2+
3+
var BaseDetailsView = require("./base-details-view");
4+
var time = require("../time");
5+
var MILLISECONDS_PER_SECOND = require("../constants").MILLISECONDS_PER_SECOND;
6+
var UPTIME_INTERVAL_MS = MILLISECONDS_PER_SECOND;
7+
8+
var NodeDetailsView = function NodeDetailsView(options) {
9+
BaseDetailsView.call(this, options);
10+
11+
this.setupdate();
12+
this.node.on("attach", this.setupdate.bind(this));
13+
14+
this.node.on("detach", function () {
15+
if (this.uptimeInterval) {
16+
clearInterval(this.uptimeInterval);
17+
delete this.uptimeInterval;
18+
}
19+
}.bind(this));
20+
};
21+
22+
NodeDetailsView.prototype = Object.create(BaseDetailsView.prototype);
23+
24+
NodeDetailsView.prototype.setupdate = function () {
25+
this.uptimeInterval = this.uptimeInterval || setInterval(function () {
26+
this.refreshContent();
27+
}.bind(this), UPTIME_INTERVAL_MS);
28+
};
29+
30+
NodeDetailsView.prototype.getDetails = function () {
31+
return [
32+
{
33+
label: "Version",
34+
data: process.version
35+
}, {
36+
label: "LTS",
37+
data: process.release.lts
38+
}, {
39+
label: "Uptime",
40+
data: time.getLabel(process.uptime() * MILLISECONDS_PER_SECOND)
41+
}
42+
];
43+
};
44+
45+
NodeDetailsView.prototype.getDefaultLayoutConfig = function () {
46+
return {
47+
label: " Node ",
48+
border: "line",
49+
tags: true,
50+
height: "shrink",
51+
style: {
52+
border: {
53+
fg: "white"
54+
}
55+
}
56+
};
57+
};
58+
59+
module.exports = NodeDetailsView;

0 commit comments

Comments
 (0)