spacex-cli/constants.js

135 lines
4.5 KiB
JavaScript
Raw Permalink Normal View History

2021-01-08 03:11:49 +08:00
const os = require('os');
2021-01-06 03:13:05 +08:00
const clc = require('cli-color');
const arguments = require('./tools/process-args').arguments;
2021-01-08 03:11:49 +08:00
if (!arguments.dump) {
if (arguments.color) {
this.STYLES = {scrollbar: {bg: 'blue'}};
} else {
this.STYLES = {scrollbar: {bg: 'white'}};
};
2021-01-06 03:13:05 +08:00
} else {
2021-01-08 03:11:49 +08:00
this.STYLES = {scrollbar: null};
2021-01-06 03:13:05 +08:00
};
const override_deep = (o,v) => {
var o_ = {}
Object.keys(o).forEach(k => {
if (typeof o[k] === 'object') {
o_[k] = override_deep(o[k],v);
} else {
o_[k] = v;
}
})
return o_
};
2021-01-08 03:11:49 +08:00
this.CONTROL_MAX_WIDTH = 0;
const registerKeys = ((keys, actions) => {
var strArr = [];
for (i = 0; i < keys.length; ++i) {
if (arguments.color) {
strArr.push(keys[i]+' '+clc.underline(actions[i]));
} else {
strArr.push(keys[i]+' '+actions[i]);
};
};
const str = strArr.join(' | ');
const d = arguments.color ? 9 : 0;
if (str.length - i*d > this.CONTROL_MAX_WIDTH) {
this.CONTROL_MAX_WIDTH = str.length - i*d;
};
return str;
});
2021-01-06 03:13:05 +08:00
this.CONSTANT_VALUES = {
2021-01-08 03:11:49 +08:00
TIME_NOTIFY: arguments.notify_time,//60*60*24*7,
TIME_BLINK: arguments.highlight_time,
DATA_PATH: arguments.path.replace('~',os.homedir),
2021-01-06 03:13:05 +08:00
}
this.GETCOLORS = ((clc_) => {
var COLOR = {
NONE: ((t) => {return t}),
2021-01-08 03:11:49 +08:00
BLINK: clc_.blink,
2021-01-06 03:13:05 +08:00
GENERIC: clc_.cyan,
SUCCESS: clc_.green,
HUGE_SUCCESS: clc_.green.bold,
WARNING: clc_.yellow,
DANGER: clc_.red.bold,
INVALID: clc_.blackBright.bold,
PROGRESS: clc_.yellow,
2021-01-08 03:11:49 +08:00
HEADER: clc_.magentaBright.underline,
2021-01-06 03:13:05 +08:00
TIME: {
LT1: clc_.green,
LTD: clc_.green,
LTM: clc_.yellow,
LTQ: clc_.blackBright.bold,
LTH: clc_.blackBright.bold
2021-01-08 03:11:49 +08:00
},
2021-01-06 03:13:05 +08:00
};
if (!arguments.color) {
COLOR = override_deep(COLOR, ((t) => {return t}))
};
return COLOR
});
this.GETSTRING = ((COLOR_) => {
return {
HEADERS: {
FLIGHT_NUMBER: COLOR_.HEADER("Flight №"),
NAME: COLOR_.HEADER("Launch name"),
DATE_H: COLOR_.HEADER("Date"),
DT: COLOR_.HEADER("Time remaining until launch"),
PRECISION: COLOR_.HEADER("Precision"),
FLAGS: COLOR_.HEADER("Flags"),
ROCKET: COLOR_.HEADER("Rocket type"),
2021-01-08 03:11:49 +08:00
CORE: COLOR_.HEADER("Core(№ of reuses)"),
2021-01-06 03:13:05 +08:00
LAUNCHPAD: COLOR_.HEADER("Launchpad"),
LAUNCHPAD_REG: COLOR_.HEADER("Launch region"),
PAYLOAD_NAME: COLOR_.HEADER("Payloads"),
PAYLOAD_CUSTOMERS: COLOR_.HEADER("Payload customers"),
2021-01-08 03:11:49 +08:00
JSON: COLOR_.HEADER('Key/Value'),
KEY: COLOR_.HEADER('Property'),
VALUE: COLOR_.HEADER('Value'),
2021-01-06 03:13:05 +08:00
},
CONTROLS: {
2021-01-08 03:11:49 +08:00
TABLE: registerKeys(['↑↓', '↵ →', 'r', 'q', 'd' ],
['Scroll and select', 'Select launch', 'Refresh', 'Quit', 'Diff']),
INFORMATION: registerKeys(['↑↓', 'q ↵ ←', 'j' ],
['Scroll', 'Return to table', 'Toggle JSON view']),
DIFF: registerKeys(['↑↓', 'q ↵ ←' ],
['Scroll', 'Return to table'])
2021-01-06 03:13:05 +08:00
},
2021-01-08 03:11:49 +08:00
CORE_UNASSIGNED: COLOR_.INVALID("Unknown"),
CORE_UNASSIGNED_: "Unknown",
2021-01-06 03:13:05 +08:00
DOWNLOADING: COLOR_.PROGRESS("Downloading new data from spacex api . . .",),
DOWNLOADING_STAR: COLOR_.PROGRESS("*"),
OK_GENERIC: COLOR_.SUCCESS("OK."),
2021-01-08 03:11:49 +08:00
OK_SCROLL: COLOR_.SUCCESS("OK. [!] Scroll to view more"),
LAST_DELTA: COLOR_.GENERIC('Last Δ: '),
2021-01-06 03:13:05 +08:00
H_WARNING: "SpaceX launches imminent!",
2021-01-08 03:11:49 +08:00
NEW_DATA: "New SpaceX data downloaded!",
2021-01-06 03:13:05 +08:00
APPID: 'spacex-cli',
SCREEN_TITLE: 'Spacex - Upcoming lunches',
2021-01-08 03:11:49 +08:00
DIFF: {
PREVIOUS: 'prev',
CURRENT: 'curr',
PREVIOUS_SYMBOL: '[-]',
CURRENT_SYMBOL: '[+]',
BOTH_SYMBOL: '[±]',
UNCHANGED_SYMBOL: '[=]',
UNCHANGED_SYMBOL_: ' '
}
2021-01-06 03:13:05 +08:00
};
})