@phasn/prototyping-cli 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -3
- package/examples/interactive.js +7 -0
- package/index.js +3 -0
- package/package.json +25 -5
- package/util.console/index.js +218 -0
- package/util.console/interactive.api.js +190 -0
- package/util.console/interactive.js +6 -0
- package/util.readline/api.base.js +74 -0
- package/util.readline/index.js +96 -0
- package/util.readline/interactive.api.js +45 -0
- package/util.readline/interactive.js +6 -0
- package/util.readline/resolveCommand.js +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 phasn <phasn@proton.me> (https://github.com/phasn)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {API as readlineAPI} from '../util.readline/interactive.api.js';
|
|
2
|
+
import {API as consoleAPI} from '../util.console/interactive.api.js';
|
|
3
|
+
import {initRL, useAPIs} from '../index.js';
|
|
4
|
+
|
|
5
|
+
let API = {moduleName:'Readline&Console Utils'};
|
|
6
|
+
API = useAPIs(API, readlineAPI, consoleAPI);
|
|
7
|
+
initRL(API);
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@phasn/prototyping-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Modular CLI base for rapidly setting up interactive test and example scripts",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository":{
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://git@github.com/phasn/Prototyping-CLI.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/phasn/Prototyping-CLI",
|
|
12
|
+
"scripts":{
|
|
13
|
+
"console": "node ./util.console/interactive.js",
|
|
14
|
+
"readline": "node ./util.readline/interactive.js",
|
|
15
|
+
"start": "node ./examples/interactive.js"
|
|
16
|
+
},
|
|
17
|
+
"author": "phasn <phasn@proton.me> (https://github.com/phasn)",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"keywords":[
|
|
20
|
+
"interactive",
|
|
21
|
+
"test",
|
|
22
|
+
"cli",
|
|
23
|
+
"console",
|
|
24
|
+
"readline"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
export const codes = {
|
|
2
|
+
// terms should always be imperativem', not descriptive
|
|
3
|
+
// e.g. 'underline' not 'underlined'
|
|
4
|
+
// 'blink' not 'blinking'
|
|
5
|
+
// 'hide' not 'hidden'
|
|
6
|
+
// abbreviations for 'un_' should be 'x_' rather than 'u_'
|
|
7
|
+
|
|
8
|
+
r: '\x1b[0m', reset: '\x1b[0m',
|
|
9
|
+
x: '\x1b[0m',
|
|
10
|
+
res: '\x1b[0m',
|
|
11
|
+
b: '\x1b[1m', bold: '\x1b[1m',
|
|
12
|
+
bright: '\x1b[1m',// not a good idea to think of this code as bright because it leads to messy format interactions, but most terminals implement it as this
|
|
13
|
+
'**': '\x1b[1m',
|
|
14
|
+
f: '\x1b[2m', faint: '\x1b[2m',
|
|
15
|
+
d: '\x1b[2m', dim: '\x1b[2m',
|
|
16
|
+
i: '\x1b[3m', italic: '\x1b[3m',
|
|
17
|
+
'*': '\x1b[3m',
|
|
18
|
+
u: '\x1b[4m', underline: '\x1b[4m',
|
|
19
|
+
'_': '\x1b[4m',
|
|
20
|
+
blnk: '\x1b[5m', blink: '\x1b[5m',
|
|
21
|
+
sblnk: '\x1b[5m', slowblink: '\x1b[5m',
|
|
22
|
+
fblnk: '\x1b[6m', fastblink: '\x1b[6m',
|
|
23
|
+
rblnk: '\x1b[6m', rapidblink: '\x1b[6m',
|
|
24
|
+
rev: '\x1b[7m', reverse: '\x1b[7m',
|
|
25
|
+
hid: '\x1b[8m', hide: '\x1b[8m',
|
|
26
|
+
str: '\x1b[9m', strikethrough: '\x1b[9m',
|
|
27
|
+
stt: '\x1b[9m',
|
|
28
|
+
stk: '\x1b[9m', strike: '\x1b[9m',
|
|
29
|
+
co: '\x1b[9m', crossout: '\x1b[9m',
|
|
30
|
+
cross: '\x1b[9m',
|
|
31
|
+
f0: '\x1b[10m', defaultfont: '\x1b[10m',// reverts 11-20
|
|
32
|
+
fx: '\x1b[10m', revertfont: '\x1b[10m',
|
|
33
|
+
xfx: '\x1b[10m',
|
|
34
|
+
f1: '\x1b[11m', font1: '\x1b[11m',
|
|
35
|
+
f2: '\x1b[12m', font2: '\x1b[12m',
|
|
36
|
+
f3: '\x1b[13m', font3: '\x1b[13m',
|
|
37
|
+
f4: '\x1b[14m', font4: '\x1b[14m',
|
|
38
|
+
f5: '\x1b[15m', font5: '\x1b[15m',
|
|
39
|
+
f6: '\x1b[16m', font6: '\x1b[16m',
|
|
40
|
+
f7: '\x1b[17m', font7: '\x1b[17m',
|
|
41
|
+
f8: '\x1b[18m', font8: '\x1b[18m',
|
|
42
|
+
f9: '\x1b[19m', font9: '\x1b[19m',
|
|
43
|
+
f10: '\x1b[20m', fraktur: '\x1b[20m',
|
|
44
|
+
ff: '\x1b[20m', fontfraktur: '\x1b[20m',
|
|
45
|
+
gothic: '\x1b[20m',
|
|
46
|
+
fg: '\x1b[20m', fontgothic: '\x1b[20m',
|
|
47
|
+
du: '\x1b[21m', doubleunderline: '\x1b[21m',// * some terminals incorrectly use this to revert 1
|
|
48
|
+
uu: '\x1b[21m',
|
|
49
|
+
nrm: '\x1b[22m', normal: '\x1b[22m',// reverts 1 and 2
|
|
50
|
+
xb: '\x1b[22m', unbold: '\x1b[22m',
|
|
51
|
+
xf: '\x1b[22m', unfaint: '\x1b[22m',
|
|
52
|
+
xd: '\x1b[22m', undim: '\x1b[22m',
|
|
53
|
+
reg: '\x1b[22m', regular: '\x1b[22m',
|
|
54
|
+
xi: '\x1b[23m', unitalic: '\x1b[23m',// reverts 3
|
|
55
|
+
xu: '\x1b[24m', ununderline: '\x1b[24m',// reverts 4 and 21 (* see note by 21)
|
|
56
|
+
xblnk: '\x1b[25m', unblink: '\x1b[25m',// reverts 5 and 6
|
|
57
|
+
// ?: '\x1b[26m', unused: '\x1b[26m',
|
|
58
|
+
xrev: '\x1b[27m', unreverse: '\x1b[27m',// reverts 7
|
|
59
|
+
rvl: '\x1b[28m', reveal: '\x1b[28m',// reverts 8
|
|
60
|
+
xhid: '\x1b[28m', unhide: '\x1b[28m',
|
|
61
|
+
xstr: '\x1b[29m', unstrikethrough: '\x1b[29m',// reverts 9
|
|
62
|
+
xstt: '\x1b[29m',
|
|
63
|
+
xstk: '\x1b[29m', unstrike: '\x1b[29m',
|
|
64
|
+
xco: '\x1b[29m', uncrossout: '\x1b[29m',
|
|
65
|
+
uncross: '\x1b[29m',
|
|
66
|
+
blk: '\x1b[30m', black: '\x1b[30m',
|
|
67
|
+
red: '\x1b[31m',
|
|
68
|
+
grn: '\x1b[32m', green: '\x1b[32m',
|
|
69
|
+
ylw: '\x1b[33m', yellow: '\x1b[33m',
|
|
70
|
+
blu: '\x1b[34m', blue: '\x1b[34m',
|
|
71
|
+
mgt: '\x1b[35m', magenta: '\x1b[35m',
|
|
72
|
+
ppl: '\x1b[35m', purple: '\x1b[35m',
|
|
73
|
+
cyn: '\x1b[36m', cyan: '\x1b[36m',
|
|
74
|
+
wht: '\x1b[37m', white: '\x1b[37m',
|
|
75
|
+
// # '\x1b[38m', customcolor '\x1b[38m',
|
|
76
|
+
for: '\x1b[39m', foreground: '\x1b[39m',// reverts 30-38 & 90-97
|
|
77
|
+
bgblk: '\x1b[40m', bgblack: '\x1b[40m',
|
|
78
|
+
bgred: '\x1b[41m', bgred: '\x1b[41m',
|
|
79
|
+
bggrn: '\x1b[42m', bggreen: '\x1b[42m',
|
|
80
|
+
bgylw: '\x1b[43m', bgyellow: '\x1b[43m',
|
|
81
|
+
bgblu: '\x1b[44m', bgblue: '\x1b[44m',
|
|
82
|
+
bgmgt: '\x1b[45m', bgmagenta: '\x1b[45m',
|
|
83
|
+
bgppl: '\x1b[45m', bgpurple: '\x1b[45m',
|
|
84
|
+
bgcyn: '\x1b[46m', bgcyan: '\x1b[46m',
|
|
85
|
+
bgwht: '\x1b[47m', bgwhite: '\x1b[47m',
|
|
86
|
+
// bg# '\x1b[48m', custombgcolor '\x1b[48m',
|
|
87
|
+
|
|
88
|
+
// u# '\x1b[58m', customunderlinecolor '\x1b[58m',
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
lblk: '\x1b[90m', lightblack: '\x1b[90m',
|
|
92
|
+
lred: '\x1b[91m', lightred: '\x1b[91m',
|
|
93
|
+
lgrn: '\x1b[92m', lightgreen: '\x1b[92m',
|
|
94
|
+
lylw: '\x1b[93m', lightyellow: '\x1b[93m',
|
|
95
|
+
lblu: '\x1b[94m', lightblue: '\x1b[94m',
|
|
96
|
+
lmgt: '\x1b[95m', lightmagenta: '\x1b[95m',
|
|
97
|
+
lppl: '\x1b[95m', lightpurple: '\x1b[95m',
|
|
98
|
+
lcyn: '\x1b[96m', lightcyan: '\x1b[96m',
|
|
99
|
+
lwht: '\x1b[97m', lightwhite: '\x1b[97m',
|
|
100
|
+
|
|
101
|
+
bglblk: '\x1b[100m', bglightblack: '\x1b[100m',
|
|
102
|
+
bglred: '\x1b[101m', bglightred: '\x1b[101m',
|
|
103
|
+
bglgrn: '\x1b[102m', bglightgreen: '\x1b[102m',
|
|
104
|
+
bglylw: '\x1b[103m', bglightyellow: '\x1b[103m',
|
|
105
|
+
bglblu: '\x1b[104m', bglightblue: '\x1b[104m',
|
|
106
|
+
bglmgt: '\x1b[105m', bglightmagenta: '\x1b[105m',
|
|
107
|
+
bglppl: '\x1b[105m', bglightpurple: '\x1b[105m',
|
|
108
|
+
bglcyn: '\x1b[106m', bglightcyan: '\x1b[106m',
|
|
109
|
+
bglwht: '\x1b[107m', bglightwhite: '\x1b[107m',
|
|
110
|
+
|
|
111
|
+
bblk: '\x1b[90m', brightblack: '\x1b[90m',
|
|
112
|
+
bred: '\x1b[91m', brightred: '\x1b[91m',
|
|
113
|
+
bgrn: '\x1b[92m', brightgreen: '\x1b[92m',
|
|
114
|
+
bylw: '\x1b[93m', brightyellow: '\x1b[93m',
|
|
115
|
+
bblu: '\x1b[94m', brightblue: '\x1b[94m',
|
|
116
|
+
bmgt: '\x1b[95m', brightmagenta: '\x1b[95m',
|
|
117
|
+
bppl: '\x1b[95m', brightpurple: '\x1b[95m',
|
|
118
|
+
bcyn: '\x1b[96m', brightcyan: '\x1b[96m',
|
|
119
|
+
bwht: '\x1b[97m', brightwhite: '\x1b[97m',
|
|
120
|
+
|
|
121
|
+
bgbblk: '\x1b[100m', bgbrightblack: '\x1b[100m',
|
|
122
|
+
bgbred: '\x1b[101m', bgbrightred: '\x1b[101m',
|
|
123
|
+
bgbgrn: '\x1b[102m', bgbrightgreen: '\x1b[102m',
|
|
124
|
+
bgbylw: '\x1b[103m', bgbrightyellow: '\x1b[103m',
|
|
125
|
+
bgbblu: '\x1b[104m', bgbrightblue: '\x1b[104m',
|
|
126
|
+
bgbmgt: '\x1b[105m', bgbrightmagenta: '\x1b[105m',
|
|
127
|
+
bgbppl: '\x1b[105m', bgbrightpurple: '\x1b[105m',
|
|
128
|
+
bgbcyn: '\x1b[106m', bgbrightcyan: '\x1b[106m',
|
|
129
|
+
bgbwht: '\x1b[107m', bgbrightwhite: '\x1b[107m',
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
// Temp for compatibility with older things because I haven't added the toLowerCase thing in this version
|
|
134
|
+
BGblk: '\x1b[40m', BGblack: '\x1b[40m',
|
|
135
|
+
BGred: '\x1b[41m', BGred: '\x1b[41m',
|
|
136
|
+
BGgrn: '\x1b[42m', BGgreen: '\x1b[42m',
|
|
137
|
+
BGylw: '\x1b[43m', BGyellow: '\x1b[43m',
|
|
138
|
+
BGblu: '\x1b[44m', BGblue: '\x1b[44m',
|
|
139
|
+
BGmgt: '\x1b[45m', BGmagenta: '\x1b[45m',
|
|
140
|
+
BGppl: '\x1b[45m', BGpurple: '\x1b[45m',
|
|
141
|
+
BGcyn: '\x1b[46m', BGcyan: '\x1b[46m',
|
|
142
|
+
BGwht: '\x1b[47m', BGwhite: '\x1b[47m',
|
|
143
|
+
BGbblk: '\x1b[100m', BGbrightblack: '\x1b[100m',
|
|
144
|
+
BGbred: '\x1b[101m', BGbrightred: '\x1b[101m',
|
|
145
|
+
BGbgrn: '\x1b[102m', BGbrightgreen: '\x1b[102m',
|
|
146
|
+
BGbylw: '\x1b[103m', BGbrightyellow: '\x1b[103m',
|
|
147
|
+
BGbblu: '\x1b[104m', BGbrightblue: '\x1b[104m',
|
|
148
|
+
BGbmgt: '\x1b[105m', BGbrightmagenta: '\x1b[105m',
|
|
149
|
+
BGbppl: '\x1b[105m', BGbrightpurple: '\x1b[105m',
|
|
150
|
+
BGbcyn: '\x1b[106m', BGbrightcyan: '\x1b[106m',
|
|
151
|
+
BGbwht: '\x1b[107m', BGbrightwhite: '\x1b[107m',
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const r = codes.r;// Don't manually export this. It gets exported in '...codes'
|
|
155
|
+
|
|
156
|
+
export const br = () => console.log(`${r}\n`);
|
|
157
|
+
export const hr = (a,b) => {
|
|
158
|
+
let color = codes.cyan;
|
|
159
|
+
let char = '-';
|
|
160
|
+
if(a){
|
|
161
|
+
if(codes[a] && typeof codes[a]==='string') color = codes[a];
|
|
162
|
+
if(typeof a==='string' && a.length<=2) char = a;
|
|
163
|
+
}
|
|
164
|
+
if(b){
|
|
165
|
+
if(codes[b] && typeof codes[b]==='string') color = codes[b];
|
|
166
|
+
if(typeof b==='string' && b.length<=2) char = b;
|
|
167
|
+
}
|
|
168
|
+
let str = `${r}${color}--------------------------------${r}`.replaceAll('-', char);
|
|
169
|
+
|
|
170
|
+
console.log(str);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const __desc = (str) => `${r} ${codes.brightmagenta}${str}${r}`;
|
|
174
|
+
export const __sntx = (str) => `${r} ${codes.blue}>${codes.yellow} ${str}${r}`;
|
|
175
|
+
export const __cmd = (str) => `${r}${codes.brightgreen}${str}${r}`;
|
|
176
|
+
export const __arg = (str) => `${r}${codes.brightyellow}<${r}${codes.yellow}${str}${r}${codes.brightyellow}>${r}`;
|
|
177
|
+
|
|
178
|
+
// These shouldn't need to be exported
|
|
179
|
+
console.br = console.break = console.newline = console.n = console.nl = console.enter = br;
|
|
180
|
+
console.hr = console.line = console.break = console.bar = console.divider = console.div = hr;
|
|
181
|
+
|
|
182
|
+
// Default Methods: White text on dark background
|
|
183
|
+
console.info = (str) => console.log(`${r}${codes.f}${codes.bglightwhite}${codes.blue}${codes.rev} `, str, ` ${r}`);//
|
|
184
|
+
console.warn = (str) => console.log(`${r}${codes.f}${codes.bglightwhite}${codes.yellow}${codes.rev} `, str, ` ${r}`);//
|
|
185
|
+
console.error = (str) => console.log(`${r}${codes.bglightwhite}${codes.red}${codes.rev} `, str, ` ${r}`);//
|
|
186
|
+
console.debug = (str) => console.log(`${r}${codes.f}${codes.bglightwhite}${codes.magenta}${codes.rev} `, str, ` ${r}`);//
|
|
187
|
+
|
|
188
|
+
// Custom Methods: Light text on no background
|
|
189
|
+
console.alert = (str) => console.log(`${r}${codes.b}${codes.lightyellow} `, str, ` ${r}`);//
|
|
190
|
+
console.danger = (str) => console.log(`${r}${codes.b}${codes.lightred} `, str, ` ${r}`);//
|
|
191
|
+
console.success = (str) => console.log(`${r}${codes.b}${codes.lightgreen} `, str, ` ${r}`);//
|
|
192
|
+
console.help = (str) => console.log(`${r}${codes.b}${codes.lightmagenta} `, str, ` ${r}`);//
|
|
193
|
+
|
|
194
|
+
// Custom Methods: Black text on light background
|
|
195
|
+
// console.alert = (str) => console.log(`${r}${codes.black}${codes.bglightyellow} `, str, ` ${r}`);//
|
|
196
|
+
// console.danger = (str) => console.log(`${r}${codes.black}${codes.bglightred} `, str, ` ${r}`);//
|
|
197
|
+
// console.success = (str) => console.log(`${r}${codes.black}${codes.bglightgreen} `, str, ` ${r}`);//
|
|
198
|
+
// console.help = (str) => console.log(`${r}${codes.black}${codes.bglightmagenta} `, str, ` ${r}`);//
|
|
199
|
+
|
|
200
|
+
// let errorfg = '255, 0, 0'
|
|
201
|
+
// let errorbg = '252, 235, 235'
|
|
202
|
+
// let warnfg = '92, 60, 0'
|
|
203
|
+
// let warnbg = '254, 243, 220'
|
|
204
|
+
|
|
205
|
+
console.warning = console.alert;
|
|
206
|
+
// No this isn't a typo. The Bootstrap name is 'warning'.
|
|
207
|
+
// It should reflect the format of the custom method, not the default method.
|
|
208
|
+
|
|
209
|
+
export default{
|
|
210
|
+
codes,
|
|
211
|
+
...codes,
|
|
212
|
+
br,
|
|
213
|
+
hr,
|
|
214
|
+
__desc,
|
|
215
|
+
__sntx,
|
|
216
|
+
__cmd,
|
|
217
|
+
__arg,
|
|
218
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import uC, {__cmd} from './index.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const API = {
|
|
5
|
+
commands:{
|
|
6
|
+
// =========================
|
|
7
|
+
// <<<<<<<< methods >>>>>>>>
|
|
8
|
+
// =========================
|
|
9
|
+
methods:{
|
|
10
|
+
description: 'Displays each type of console logging method',
|
|
11
|
+
syntax:[`${__cmd('methods')}`],
|
|
12
|
+
execute(){
|
|
13
|
+
console.log('\n\t Modified Console Methods:');
|
|
14
|
+
console.info('console.info()');
|
|
15
|
+
console.warn('console.warn()');
|
|
16
|
+
console.error('console.error()');
|
|
17
|
+
console.debug('console.debug()');
|
|
18
|
+
|
|
19
|
+
console.log('\n\t New Console Methods:')
|
|
20
|
+
console.alert('console.alert()');
|
|
21
|
+
console.danger('console.danger()');
|
|
22
|
+
console.success('console.success()');
|
|
23
|
+
console.help('console.help()');
|
|
24
|
+
|
|
25
|
+
return console.br();
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
// ======================
|
|
30
|
+
// <<<<<<<< ansi >>>>>>>>
|
|
31
|
+
// ======================
|
|
32
|
+
ansi:{
|
|
33
|
+
description: 'Display how each ANSI code from 0-130 is rendered in the current terminal',
|
|
34
|
+
syntax:[`${__cmd('ansi')}`],
|
|
35
|
+
execute(){
|
|
36
|
+
for(let i=0; i<11; i++){
|
|
37
|
+
let str = '';
|
|
38
|
+
for(let j=0; j<10; j++){
|
|
39
|
+
let n = 10 * i + j;
|
|
40
|
+
if(n>130) break;
|
|
41
|
+
str += `\x1b[0\;${n}m${n.toString().padStart(3)}`;
|
|
42
|
+
}
|
|
43
|
+
console.log(str);
|
|
44
|
+
str = '';
|
|
45
|
+
}
|
|
46
|
+
return console.br();
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// ==========================
|
|
51
|
+
// <<<<<<<< keywords >>>>>>>>
|
|
52
|
+
// ==========================
|
|
53
|
+
keywords:{
|
|
54
|
+
description: 'Lists all available formatting and color keywords',
|
|
55
|
+
syntax:[`${__cmd('keywords')}`],
|
|
56
|
+
execute(){
|
|
57
|
+
for(let col in uC.codes){
|
|
58
|
+
console.log(`${uC.r}${col.padEnd(16,' ')}${uC.codes[col]}${col.padEnd(16,' ')}\\x1b${uC.codes[col].substring(1)}${uC.r}`);
|
|
59
|
+
}
|
|
60
|
+
return console.br();
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
// =========================
|
|
64
|
+
// <<<<<<<< formats >>>>>>>>
|
|
65
|
+
// =========================
|
|
66
|
+
formats:{
|
|
67
|
+
description: 'Displays the effects of each formatting code',
|
|
68
|
+
syntax:[`${__cmd('formats')}`],
|
|
69
|
+
execute(){
|
|
70
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
71
|
+
let testStr = `${uC.r}
|
|
72
|
+
${uC.b}bold/bright${uC.r}
|
|
73
|
+
${uC.f}faint/dim${uC.r}
|
|
74
|
+
${uC.i}italicized${uC.r}
|
|
75
|
+
${uC.u}underscore${uC.r}
|
|
76
|
+
${uC.blnk}blink${uC.r}
|
|
77
|
+
${uC.fblnk}fast blink${uC.r}
|
|
78
|
+
${uC.rev}reverse${uC.r}
|
|
79
|
+
${uC.hid}hidden${uC.r}<--(hidden)
|
|
80
|
+
${uC.str}strikethrough${uC.r}
|
|
81
|
+
${uC.du}double underscore${uC.r}\n`;
|
|
82
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
83
|
+
return console.log(testStr);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// ========================
|
|
88
|
+
// <<<<<<<< colors >>>>>>>>
|
|
89
|
+
// ========================
|
|
90
|
+
colors:{
|
|
91
|
+
description: 'Misc. color test 1',
|
|
92
|
+
syntax:[`${__cmd('colors')}`],
|
|
93
|
+
aliases:[
|
|
94
|
+
'colors0',
|
|
95
|
+
'colors1',
|
|
96
|
+
],
|
|
97
|
+
execute(){
|
|
98
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
99
|
+
let testStr = `${uC.r}
|
|
100
|
+
${uC.b}${uC.red}red░█${uC.r} ${uC.red}red░█${uC.r} ${uC.f}${uC.red}red░█${uC.r}
|
|
101
|
+
${uC.b}${uC.yellow}yellow░█${uC.r} ${uC.yellow}yellow░█${uC.r} ${uC.f}${uC.yellow}yellow░█${uC.r}
|
|
102
|
+
${uC.b}${uC.green}green░█${uC.r} ${uC.green}green░█${uC.r} ${uC.f}${uC.green}green░█${uC.r}
|
|
103
|
+
${uC.b}${uC.cyan}cyan░█${uC.r} ${uC.cyan}cyan░█${uC.r} ${uC.f}${uC.cyan}cyan░█${uC.r}
|
|
104
|
+
${uC.b}${uC.blue}blue░█${uC.r} ${uC.blue}blue░█${uC.r} ${uC.f}${uC.blue}blue░█${uC.r}
|
|
105
|
+
${uC.b}${uC.magenta}magenta░█${uC.r} ${uC.magenta}magenta░█${uC.r} ${uC.f}${uC.magenta}magenta░█${uC.r}
|
|
106
|
+
${uC.b}${uC.black}black░█${uC.r} ${uC.black}black░█${uC.r} ${uC.f}${uC.black}black░█${uC.r}
|
|
107
|
+
${uC.b}${uC.white}white░█${uC.r} ${uC.white}white░█${uC.r} ${uC.f}${uC.white}white░█${uC.r}
|
|
108
|
+
|
|
109
|
+
${uC.b}${uC.bgred}BGred░█${uC.r} ${uC.bgred}BGred░█${uC.r} ${uC.f}${uC.bgred}BGred░█${uC.r}
|
|
110
|
+
${uC.b}${uC.bgyellow}BGyellow░█${uC.r} ${uC.bgyellow}BGyellow░█${uC.r} ${uC.f}${uC.bgyellow}BGyellow░█${uC.r}
|
|
111
|
+
${uC.b}${uC.bggreen}BGgreen░█${uC.r} ${uC.bggreen}BGgreen░█${uC.r} ${uC.f}${uC.bggreen}BGgreen░█${uC.r}
|
|
112
|
+
${uC.b}${uC.bgcyan}BGcyan░█${uC.r} ${uC.bgcyan}BGcyan░█${uC.r} ${uC.f}${uC.bgcyan}BGcyan░█${uC.r}
|
|
113
|
+
${uC.b}${uC.bgblue}BGblue░█${uC.r} ${uC.bgblue}BGblue░█${uC.r} ${uC.f}${uC.bgblue}BGblue░█${uC.r}
|
|
114
|
+
${uC.b}${uC.bgmagenta}BGmagenta░█${uC.r} ${uC.bgmagenta}BGmagenta░█${uC.r} ${uC.f}${uC.bgmagenta}BGmagenta░█${uC.r}
|
|
115
|
+
${uC.b}${uC.bgblack}BGblack░█${uC.r} ${uC.bgblack}BGblack░█${uC.r} ${uC.f}${uC.bgblack}BGblack░█${uC.r}
|
|
116
|
+
${uC.b}${uC.bgwhite}BGwhite░█${uC.r} ${uC.bgwhite}BGwhite░█${uC.r} ${uC.f}${uC.bgwhite}BGwhite░█${uC.r}\n`;
|
|
117
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
118
|
+
return console.log(testStr);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// =========================
|
|
123
|
+
// <<<<<<<< colors2 >>>>>>>>
|
|
124
|
+
// =========================
|
|
125
|
+
colors2:{
|
|
126
|
+
description: 'Misc. color test 2',
|
|
127
|
+
syntax:[`${__cmd('colors2')}`],
|
|
128
|
+
execute(){
|
|
129
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
130
|
+
let testStr = `${uC.r}
|
|
131
|
+
${uC.b}${uC.red}░${uC.r}${uC.red}░${uC.r}${uC.f}${uC.red}░${uC.r}${uC.b}${uC.bgred}░${uC.r}${uC.bgred}░${uC.r}${uC.f}${uC.bgred}░${uC.r}${uC.b}${uC.reverse}${uC.red}░${uC.r}${uC.reverse}${uC.red}░${uC.r}${uC.f}${uC.reverse}${uC.red}░${uC.r}${uC.b}${uC.reverse}${uC.bgred}░${uC.r}${uC.reverse}${uC.bgred}░${uC.r}${uC.f}${uC.reverse}${uC.bgred}░${uC.r}
|
|
132
|
+
${uC.b}${uC.yellow}░${uC.r}${uC.yellow}░${uC.r}${uC.f}${uC.yellow}░${uC.r}${uC.b}${uC.bgyellow}░${uC.r}${uC.bgyellow}░${uC.r}${uC.f}${uC.bgyellow}░${uC.r}${uC.b}${uC.reverse}${uC.yellow}░${uC.r}${uC.reverse}${uC.yellow}░${uC.r}${uC.f}${uC.reverse}${uC.yellow}░${uC.r}${uC.b}${uC.reverse}${uC.bgyellow}░${uC.r}${uC.reverse}${uC.bgyellow}░${uC.r}${uC.f}${uC.reverse}${uC.bgyellow}░${uC.r}
|
|
133
|
+
${uC.b}${uC.green}░${uC.r}${uC.green}░${uC.r}${uC.f}${uC.green}░${uC.r}${uC.b}${uC.bggreen}░${uC.r}${uC.bggreen}░${uC.r}${uC.f}${uC.bggreen}░${uC.r}${uC.b}${uC.reverse}${uC.green}░${uC.r}${uC.reverse}${uC.green}░${uC.r}${uC.f}${uC.reverse}${uC.green}░${uC.r}${uC.b}${uC.reverse}${uC.bggreen}░${uC.r}${uC.reverse}${uC.bggreen}░${uC.r}${uC.f}${uC.reverse}${uC.bggreen}░${uC.r}
|
|
134
|
+
${uC.b}${uC.cyan}░${uC.r}${uC.cyan}░${uC.r}${uC.f}${uC.cyan}░${uC.r}${uC.b}${uC.bgcyan}░${uC.r}${uC.bgcyan}░${uC.r}${uC.f}${uC.bgcyan}░${uC.r}${uC.b}${uC.reverse}${uC.cyan}░${uC.r}${uC.reverse}${uC.cyan}░${uC.r}${uC.f}${uC.reverse}${uC.cyan}░${uC.r}${uC.b}${uC.reverse}${uC.bgcyan}░${uC.r}${uC.reverse}${uC.bgcyan}░${uC.r}${uC.f}${uC.reverse}${uC.bgcyan}░${uC.r}
|
|
135
|
+
${uC.b}${uC.blue}░${uC.r}${uC.blue}░${uC.r}${uC.f}${uC.blue}░${uC.r}${uC.b}${uC.bgblue}░${uC.r}${uC.bgblue}░${uC.r}${uC.f}${uC.bgblue}░${uC.r}${uC.b}${uC.reverse}${uC.blue}░${uC.r}${uC.reverse}${uC.blue}░${uC.r}${uC.f}${uC.reverse}${uC.blue}░${uC.r}${uC.b}${uC.reverse}${uC.bgblue}░${uC.r}${uC.reverse}${uC.bgblue}░${uC.r}${uC.f}${uC.reverse}${uC.bgblue}░${uC.r}
|
|
136
|
+
${uC.b}${uC.magenta}░${uC.r}${uC.magenta}░${uC.r}${uC.f}${uC.magenta}░${uC.r}${uC.b}${uC.bgmagenta}░${uC.r}${uC.bgmagenta}░${uC.r}${uC.f}${uC.bgmagenta}░${uC.r}${uC.b}${uC.reverse}${uC.magenta}░${uC.r}${uC.reverse}${uC.magenta}░${uC.r}${uC.f}${uC.reverse}${uC.magenta}░${uC.r}${uC.b}${uC.reverse}${uC.bgmagenta}░${uC.r}${uC.reverse}${uC.bgmagenta}░${uC.r}${uC.f}${uC.reverse}${uC.bgmagenta}░${uC.r}
|
|
137
|
+
${uC.b}${uC.black}░${uC.r}${uC.black}░${uC.r}${uC.f}${uC.black}░${uC.r}${uC.b}${uC.bgblack}░${uC.r}${uC.bgblack}░${uC.r}${uC.f}${uC.bgblack}░${uC.r}${uC.b}${uC.reverse}${uC.black}░${uC.r}${uC.reverse}${uC.black}░${uC.r}${uC.f}${uC.reverse}${uC.black}░${uC.r}${uC.b}${uC.reverse}${uC.bgblack}░${uC.r}${uC.reverse}${uC.bgblack}░${uC.r}${uC.f}${uC.reverse}${uC.bgblack}░${uC.r}
|
|
138
|
+
${uC.b}${uC.white}░${uC.r}${uC.white}░${uC.r}${uC.f}${uC.white}░${uC.r}${uC.b}${uC.bgwhite}░${uC.r}${uC.bgwhite}░${uC.r}${uC.f}${uC.bgwhite}░${uC.r}${uC.b}${uC.reverse}${uC.white}░${uC.r}${uC.reverse}${uC.white}░${uC.r}${uC.f}${uC.reverse}${uC.white}░${uC.r}${uC.b}${uC.reverse}${uC.bgwhite}░${uC.r}${uC.reverse}${uC.bgwhite}░${uC.r}${uC.f}${uC.reverse}${uC.bgwhite}░${uC.r}\n`;
|
|
139
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
140
|
+
return console.log(testStr);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
// =========================
|
|
145
|
+
// <<<<<<<< colors3 >>>>>>>>
|
|
146
|
+
// =========================
|
|
147
|
+
colors3:{
|
|
148
|
+
description: 'Misc. color test 3 (same as #2 but with solid block characters)',
|
|
149
|
+
syntax:[`${__cmd('colors3')}`],
|
|
150
|
+
execute(){
|
|
151
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
152
|
+
let testStr = `${uC.r}
|
|
153
|
+
${uC.b}${uC.red}█${uC.r}${uC.red}█${uC.r}${uC.f}${uC.red}█${uC.r}${uC.b}${uC.bgred}█${uC.r}${uC.bgred}█${uC.r}${uC.f}${uC.bgred}█${uC.r}${uC.b}${uC.reverse}${uC.red}█${uC.r}${uC.reverse}${uC.red}█${uC.r}${uC.f}${uC.reverse}${uC.red}█${uC.r}${uC.b}${uC.reverse}${uC.bgred}█${uC.r}${uC.reverse}${uC.bgred}█${uC.r}${uC.f}${uC.reverse}${uC.bgred}█${uC.r}
|
|
154
|
+
${uC.b}${uC.yellow}█${uC.r}${uC.yellow}█${uC.r}${uC.f}${uC.yellow}█${uC.r}${uC.b}${uC.bgyellow}█${uC.r}${uC.bgyellow}█${uC.r}${uC.f}${uC.bgyellow}█${uC.r}${uC.b}${uC.reverse}${uC.yellow}█${uC.r}${uC.reverse}${uC.yellow}█${uC.r}${uC.f}${uC.reverse}${uC.yellow}█${uC.r}${uC.b}${uC.reverse}${uC.bgyellow}█${uC.r}${uC.reverse}${uC.bgyellow}█${uC.r}${uC.f}${uC.reverse}${uC.bgyellow}█${uC.r}
|
|
155
|
+
${uC.b}${uC.green}█${uC.r}${uC.green}█${uC.r}${uC.f}${uC.green}█${uC.r}${uC.b}${uC.bggreen}█${uC.r}${uC.bggreen}█${uC.r}${uC.f}${uC.bggreen}█${uC.r}${uC.b}${uC.reverse}${uC.green}█${uC.r}${uC.reverse}${uC.green}█${uC.r}${uC.f}${uC.reverse}${uC.green}█${uC.r}${uC.b}${uC.reverse}${uC.bggreen}█${uC.r}${uC.reverse}${uC.bggreen}█${uC.r}${uC.f}${uC.reverse}${uC.bggreen}█${uC.r}
|
|
156
|
+
${uC.b}${uC.cyan}█${uC.r}${uC.cyan}█${uC.r}${uC.f}${uC.cyan}█${uC.r}${uC.b}${uC.bgcyan}█${uC.r}${uC.bgcyan}█${uC.r}${uC.f}${uC.bgcyan}█${uC.r}${uC.b}${uC.reverse}${uC.cyan}█${uC.r}${uC.reverse}${uC.cyan}█${uC.r}${uC.f}${uC.reverse}${uC.cyan}█${uC.r}${uC.b}${uC.reverse}${uC.bgcyan}█${uC.r}${uC.reverse}${uC.bgcyan}█${uC.r}${uC.f}${uC.reverse}${uC.bgcyan}█${uC.r}
|
|
157
|
+
${uC.b}${uC.blue}█${uC.r}${uC.blue}█${uC.r}${uC.f}${uC.blue}█${uC.r}${uC.b}${uC.bgblue}█${uC.r}${uC.bgblue}█${uC.r}${uC.f}${uC.bgblue}█${uC.r}${uC.b}${uC.reverse}${uC.blue}█${uC.r}${uC.reverse}${uC.blue}█${uC.r}${uC.f}${uC.reverse}${uC.blue}█${uC.r}${uC.b}${uC.reverse}${uC.bgblue}█${uC.r}${uC.reverse}${uC.bgblue}█${uC.r}${uC.f}${uC.reverse}${uC.bgblue}█${uC.r}
|
|
158
|
+
${uC.b}${uC.magenta}█${uC.r}${uC.magenta}█${uC.r}${uC.f}${uC.magenta}█${uC.r}${uC.b}${uC.bgmagenta}█${uC.r}${uC.bgmagenta}█${uC.r}${uC.f}${uC.bgmagenta}█${uC.r}${uC.b}${uC.reverse}${uC.magenta}█${uC.r}${uC.reverse}${uC.magenta}█${uC.r}${uC.f}${uC.reverse}${uC.magenta}█${uC.r}${uC.b}${uC.reverse}${uC.bgmagenta}█${uC.r}${uC.reverse}${uC.bgmagenta}█${uC.r}${uC.f}${uC.reverse}${uC.bgmagenta}█${uC.r}
|
|
159
|
+
${uC.b}${uC.black}█${uC.r}${uC.black}█${uC.r}${uC.f}${uC.black}█${uC.r}${uC.b}${uC.bgblack}█${uC.r}${uC.bgblack}█${uC.r}${uC.f}${uC.bgblack}█${uC.r}${uC.b}${uC.reverse}${uC.black}█${uC.r}${uC.reverse}${uC.black}█${uC.r}${uC.f}${uC.reverse}${uC.black}█${uC.r}${uC.b}${uC.reverse}${uC.bgblack}█${uC.r}${uC.reverse}${uC.bgblack}█${uC.r}${uC.f}${uC.reverse}${uC.bgblack}█${uC.r}
|
|
160
|
+
${uC.b}${uC.white}█${uC.r}${uC.white}█${uC.r}${uC.f}${uC.white}█${uC.r}${uC.b}${uC.bgwhite}█${uC.r}${uC.bgwhite}█${uC.r}${uC.f}${uC.bgwhite}█${uC.r}${uC.b}${uC.reverse}${uC.white}█${uC.r}${uC.reverse}${uC.white}█${uC.r}${uC.f}${uC.reverse}${uC.white}█${uC.r}${uC.b}${uC.reverse}${uC.bgwhite}█${uC.r}${uC.reverse}${uC.bgwhite}█${uC.r}${uC.f}${uC.reverse}${uC.bgwhite}█${uC.r}\n`;
|
|
161
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
162
|
+
return console.log(testStr);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
// ==============================
|
|
167
|
+
// <<<<<<<< duplicateCmd >>>>>>>>
|
|
168
|
+
// ==============================
|
|
169
|
+
duplicateCmd:{
|
|
170
|
+
description: 'Both util.readline and util.console api files have a command with this name. The order you listed the APIs to use/merge will determine which one is kept and which will be overwritten.',
|
|
171
|
+
syntax:[`${__cmd('duplicateCmd')}`],
|
|
172
|
+
aliases:[
|
|
173
|
+
'duplicate',
|
|
174
|
+
'dupe',
|
|
175
|
+
'dupeCmd'
|
|
176
|
+
],
|
|
177
|
+
execute(){
|
|
178
|
+
console.log(uC.r);
|
|
179
|
+
console.info(`Both util.readline and util.console command API files include a command with this name.${uC.r}\n`);
|
|
180
|
+
console.info(`In the example script that uses both command APIs, the order in which the APIs are listed in the include/merge function will determine which one is kept and which will be overwritten.${uC.r}\n`);
|
|
181
|
+
|
|
182
|
+
console.log(`This version of the command originated from ${uC.bcyn}${uC.i}interactive.api.js${uC.r} in ${uC.bgrn}${uC.i}${uC.b}util.console${uC.r}.${uC.r}`);
|
|
183
|
+
console.log(`The version from ${uC.bmgt}${uC.i}interactive.api.js${uC.r} in ${uC.bred}${uC.i}util.readline${uC.r} either wasn't included or was overwritten by this version.${uC.r}\n`);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
export default API;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import uC, {__desc, __sntx, __cmd, __arg} from '../util.console/index.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const API = {
|
|
5
|
+
get(arg){return this[arg];},
|
|
6
|
+
|
|
7
|
+
commands:{
|
|
8
|
+
// ======================
|
|
9
|
+
// <<<<<<<< help >>>>>>>>
|
|
10
|
+
// ======================
|
|
11
|
+
help:{
|
|
12
|
+
description: 'Return a list of commands if no command name is specified.\n\tIf a command is specified, returns information about that command.',
|
|
13
|
+
syntax:[
|
|
14
|
+
`${__cmd('help')}`,
|
|
15
|
+
`${__cmd('help')} ${__arg('COMMAND')}`,
|
|
16
|
+
],
|
|
17
|
+
aliases:[
|
|
18
|
+
'-h',
|
|
19
|
+
'--help',
|
|
20
|
+
],
|
|
21
|
+
execute(cmdName){
|
|
22
|
+
let commands = API.get('commands');
|
|
23
|
+
let tab = API.get('tab');
|
|
24
|
+
let moduleName = API.get('moduleName');
|
|
25
|
+
|
|
26
|
+
if(cmdName){
|
|
27
|
+
let match = commands[Object.keys(commands).find(key => key.toLowerCase() === cmdName.toLowerCase())];
|
|
28
|
+
if(match){
|
|
29
|
+
if(!match.description) match.description = 'No description provided';
|
|
30
|
+
console.log(__desc(match.description));
|
|
31
|
+
console.log(`${tab()}${uC.cyan}${uC.u}Syntax${uC.xu}:${uC.r}`);
|
|
32
|
+
for(let line of match.syntax) console.log(`${tab()}${__sntx(line)}`);
|
|
33
|
+
console.br();
|
|
34
|
+
return;
|
|
35
|
+
}else{
|
|
36
|
+
return console.error(`ERROR: '${uC.u}${cmdName}${uC.xu}' is not a known command.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let line2 = 'Commands';
|
|
41
|
+
|
|
42
|
+
let width = Math.max(moduleName.length, line2.length);
|
|
43
|
+
for(let cmdName in commands) width = Math.max(width, cmdName.length);
|
|
44
|
+
width += 4;
|
|
45
|
+
|
|
46
|
+
const center = (str, lineWidth) => str.padStart(str.length + (Math.floor((lineWidth - str.length) / 2)), ' ');
|
|
47
|
+
|
|
48
|
+
const divider = `${tab()}${uC.lcyn}${''.padStart(width, '-')}${uC.r}`;
|
|
49
|
+
|
|
50
|
+
console.log(divider);
|
|
51
|
+
console.log(`${tab()}${uC.lgrn}${center(moduleName, width)}${uC.r}`);
|
|
52
|
+
console.log(`${tab()}${center(line2, width)}:`);
|
|
53
|
+
console.log(divider);
|
|
54
|
+
// for(let cmdName in commands) if(!commands[cmdName].alias) console.log(`${tab()}${uC.r}${uC.ylw}> ${uC.b}${cmdName}${uC.r}`);
|
|
55
|
+
for(let cmdName in commands) console.log(`${tab()}${uC.r}${uC.ylw}> ${uC.b}${cmdName}${uC.r}`);
|
|
56
|
+
console.log(divider);
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// =======================
|
|
61
|
+
// <<<<<<<< clear >>>>>>>>
|
|
62
|
+
// =======================
|
|
63
|
+
clear:{
|
|
64
|
+
description: 'Clears the console',
|
|
65
|
+
syntax:[`${__cmd('clear')}`,],
|
|
66
|
+
execute(){
|
|
67
|
+
console.clear();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
export default API;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import uC from '../util.console/index.js';
|
|
6
|
+
import {API as BaseAPI} from './api.base.js';
|
|
7
|
+
import {resolveCommand} from './resolveCommand.js';
|
|
8
|
+
|
|
9
|
+
const tabSize = 4;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const tab = () => ''.padStart(tabSize, ' ');
|
|
13
|
+
|
|
14
|
+
const getPackageJSON = () => {
|
|
15
|
+
let cwd = process.cwd();
|
|
16
|
+
let filePath = path.join(cwd, 'package.json');
|
|
17
|
+
if(fs.existsSync(filePath)){
|
|
18
|
+
let packageJSON = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
19
|
+
if(packageJSON.config){
|
|
20
|
+
if(packageJSON.config.cli_name) packageJSON.cli_name = packageJSON.config.cli_name;
|
|
21
|
+
if(packageJSON.config.cli_prefix) packageJSON.cli_prefix = packageJSON.config.cli_prefix;
|
|
22
|
+
}
|
|
23
|
+
return packageJSON;
|
|
24
|
+
}
|
|
25
|
+
return {};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getContexts = (ImportedAPI) => {
|
|
29
|
+
let packageJSON = getPackageJSON();
|
|
30
|
+
|
|
31
|
+
let moduleName = ImportedAPI.moduleName || ImportedAPI.name || process.env.CLI_NAME || process.env.npm_package_config_cli_name || process.env.npm_package_name || packageJSON.cli_name || packageJSON.name || 'Name not found';
|
|
32
|
+
let prefix = process.env.CLI_PREFIX || process.env.npm_package_config_cli_prefix || packageJSON.cli_prefix || '/';// || undefined;
|
|
33
|
+
if(prefix==='help') throw new Error(`ERROR: API prefixes cannot be ${uC.u}'help'${uC.xu}`);
|
|
34
|
+
|
|
35
|
+
return {moduleName, prefix};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export const initRL = (ImportedAPI) => {
|
|
40
|
+
console.log(uC.r);
|
|
41
|
+
if(ImportedAPI.commands.help || ImportedAPI.commands.clear || ImportedAPI.commands['-h'] || ImportedAPI.commands['--help']) throw new Error(`ERROR: Test API commands cannot be named ${uC.u}'help'${uC.xu} or ${uC.u}'clear'${uC.xu} or share their aliases`);
|
|
42
|
+
|
|
43
|
+
let {moduleName, prefix} = getContexts(ImportedAPI);
|
|
44
|
+
|
|
45
|
+
BaseAPI.tab = tab;
|
|
46
|
+
BaseAPI.moduleName = moduleName;
|
|
47
|
+
BaseAPI.commands = {
|
|
48
|
+
...BaseAPI.commands,
|
|
49
|
+
...ImportedAPI.commands,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const rl = readline.createInterface({
|
|
53
|
+
input: process.stdin,
|
|
54
|
+
output: process.stdout,
|
|
55
|
+
prompt: `${uC.r}${uC.lgrn}${moduleName}${uC.wht}:${uC.blu}~${uC.r}${uC.for}$ `,
|
|
56
|
+
terminal: true, tabSize
|
|
57
|
+
});
|
|
58
|
+
//rl.setPrompt(`${uC.r}${uC.lgrn}${moduleName}${uC.wht}:${uC.blu}~${uC.r}${uC.for}$ `);
|
|
59
|
+
|
|
60
|
+
rl.prompt();
|
|
61
|
+
|
|
62
|
+
rl.on('line', (line) => {
|
|
63
|
+
// If there is a prefix, but the user does not use it (possibly because they don't know it), this will return a fallback message
|
|
64
|
+
if(prefix && line.startsWith('help')) console.info(`Prefix lines with '${prefix}' to execute a command.\nFor a list of commands, enter "${uC.i}/help${uC.xi}".\nYou can also enter "${uC.i}/help ${uC.b}<COMMAND>${uC.xb}${uC.xi}" for info about a specific command.`);
|
|
65
|
+
resolveCommand(line, BaseAPI.commands, prefix);
|
|
66
|
+
rl.prompt();
|
|
67
|
+
})
|
|
68
|
+
.on('close', () => {
|
|
69
|
+
console.log(`Closing CLI...${uC.r}`);
|
|
70
|
+
if(ImportedAPI.overrideProcessExit!==false) process.exit(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return rl;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
export const useAPIs = (...APIsToInclude) => {
|
|
78
|
+
if(!Array.isArray(APIsToInclude)) APIsToInclude = [APIsToInclude];
|
|
79
|
+
|
|
80
|
+
const compiledAPI = {};
|
|
81
|
+
|
|
82
|
+
Object.assign(compiledAPI, ...APIsToInclude);
|
|
83
|
+
for(let API of APIsToInclude){
|
|
84
|
+
if(API.commands!==undefined) Object.assign(compiledAPI.commands, API.commands);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for(let cmdName in compiledAPI.commands){
|
|
88
|
+
let cmd = compiledAPI.commands[cmdName];
|
|
89
|
+
cmd.execute = cmd.execute.bind(compiledAPI);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return compiledAPI;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export default initRL;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import uC, {__cmd} from '../util.console/index.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const API = {
|
|
5
|
+
commands:{
|
|
6
|
+
// ============================
|
|
7
|
+
// <<<<<<<< importTest >>>>>>>>
|
|
8
|
+
// ============================
|
|
9
|
+
importTest:{
|
|
10
|
+
description: 'Test function to see if this gets imported correctly',
|
|
11
|
+
syntax:[`${__cmd('importTest')}`],
|
|
12
|
+
execute(){
|
|
13
|
+
console.br();
|
|
14
|
+
console.line();
|
|
15
|
+
console.log('Command was imported successfully');
|
|
16
|
+
console.line();
|
|
17
|
+
console.br();
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
// ==============================
|
|
22
|
+
// <<<<<<<< duplicateCmd >>>>>>>>
|
|
23
|
+
// ==============================
|
|
24
|
+
duplicateCmd:{
|
|
25
|
+
description: 'Both util.readline and util.console api files have a command with this name. The order you listed the APIs to use/merge will determine which one is kept and which will be overwritten.',
|
|
26
|
+
syntax:[`${__cmd('duplicateCmd')}`],
|
|
27
|
+
aliases:[
|
|
28
|
+
'duplicate',
|
|
29
|
+
'dupe',
|
|
30
|
+
'dupeCmd'
|
|
31
|
+
],
|
|
32
|
+
execute(){
|
|
33
|
+
console.log(uC.r);
|
|
34
|
+
console.info(`Both util.readline and util.console command API files include a command with this name.${uC.r}\n`);
|
|
35
|
+
console.info(`In the example script that uses both command APIs, the order in which the APIs are listed in the include/merge function will determine which one is kept and which will be overwritten.${uC.r}\n`);
|
|
36
|
+
|
|
37
|
+
console.log(`This version of the command originated from ${uC.bcyn}${uC.i}interactive.api.js${uC.r} in ${uC.bgrn}${uC.i}${uC.b}util.readline${uC.r}.${uC.r}`);
|
|
38
|
+
console.log(`The version from ${uC.bmgt}${uC.i}interactive.api.js${uC.r} in ${uC.bred}${uC.i}util.console${uC.r} either wasn't included or was overwritten by this version.${uC.r}\n`);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export default API;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import uC from '../util.console/index.js';
|
|
2
|
+
|
|
3
|
+
export const resolveCommand = (line, commands, prefix='') => {
|
|
4
|
+
// If there is a prefix, remove it from the input before continuing
|
|
5
|
+
if(line.startsWith(prefix)){
|
|
6
|
+
let [cmd, ...args] = line.trim().substring(prefix.length).split(/\s+/);
|
|
7
|
+
|
|
8
|
+
// If cmd is blank, but there are args (i.e. if someone puts a space after the prefix), set cmd to the first arg and shift all args down one
|
|
9
|
+
if(cmd === '' && args.length){
|
|
10
|
+
cmd = args[0];
|
|
11
|
+
args.shift();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if(cmd){
|
|
15
|
+
let match = commands[
|
|
16
|
+
Object.keys(commands)
|
|
17
|
+
.find(key => {
|
|
18
|
+
return(
|
|
19
|
+
key.toLowerCase() === cmd.toLowerCase() ||
|
|
20
|
+
( commands[key].aliases && commands[key].aliases.find(alias => alias.toLowerCase() === cmd.toLowerCase()) )
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
if(match) match.execute(...args);
|
|
26
|
+
else console.error(`ERROR: '${uC.u}${cmd}${uC.xu}' is not a known command.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default resolveCommand;
|