-
Notifications
You must be signed in to change notification settings - Fork 141
/
index.js
executable file
·68 lines (59 loc) · 2.14 KB
/
index.js
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
#!/usr/bin/env node
'use strict';
const { theme, TERM } = require('./lib/ui/theme');
// theming, it has to be the first to hack into blessed Node module
if (!['xterm-color', 'xterm-16color', 'xterm-256color'].includes(TERM)) {
// skip Blessed Node constructor interception as it is done by Webpack
if (typeof WEBPACK === 'undefined' || !WEBPACK) {
const Module = require('module');
const _require = Module.prototype.require;
Module.prototype.require = function (path) {
const module = _require.apply(this, arguments);
if (path === './node') {
const Node = function (options) {
theme(this, options);
return module.call(this, options);
}
Node.prototype = module.prototype;
return Node;
}
return module;
}
};
// override tags parsing
const blessed = require('blessed');
const _parseTags = blessed.Element.prototype._parseTags;
blessed.Element.prototype._parseTags = function (text) {
if (!this.parseTags) return text;
if (!/{\/?[\w\-,;!#]*}/.test(text)) return text;
return _parseTags.call(this, text.replace(/\{(\/)?grey-fg\}/g, '{$1white-fg}'));
}
}
const blessed = require('blessed'),
cancellations = require('./lib/task'),
Context = require('./lib/config/context'),
fs = require('fs'),
Kubebox = require('./lib/kubebox');
const screen = blessed.screen({
ignoreLocked : ['C-q'],
fullUnicode : true,
dockBorders : true,
autoPadding : false,
});
screen.key(['q', 'C-q'], (ch, key) => {
cancellations.runAll();
process.exit(0);
});
let server;
if (process.env.KUBERNETES_SERVICE_HOST && process.env.KUBERNETES_SERVICE_PORT) {
const host = process.env.KUBERNETES_SERVICE_HOST;
const port = process.env.KUBERNETES_SERVICE_PORT;
const ca = fs.readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt');
const token = fs.readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/token');
server = Context.getBaseMasterApi(`https://${host}:${port}`);
server.ca = ca;
server.headers = {
Authorization: `Bearer ${token.toString('ascii')}`,
};
}
new Kubebox(screen, server);