@prozilla-os/terminal 1.0.1 → 1.0.2
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/dist/assets/main.css +1 -0
- package/dist/cat-D7jaxwX3.js +17 -0
- package/dist/cat-D7jaxwX3.js.map +1 -0
- package/dist/cd-dBbWy_6c.js +14 -0
- package/dist/cd-dBbWy_6c.js.map +1 -0
- package/dist/clear-DtYBxmDr.js +14 -0
- package/dist/clear-DtYBxmDr.js.map +1 -0
- package/dist/cmatrix-rPy0d9Qt.js +59 -0
- package/dist/cmatrix-rPy0d9Qt.js.map +1 -0
- package/dist/command-nBL1aO7T.js +43 -0
- package/dist/command-nBL1aO7T.js.map +1 -0
- package/dist/compgen-BDZekcp1.js +14 -0
- package/dist/compgen-BDZekcp1.js.map +1 -0
- package/dist/cowsay-BqminmDW.js +50 -0
- package/dist/cowsay-BqminmDW.js.map +1 -0
- package/dist/dir-BlrznBqV.js +11 -0
- package/dist/dir-BlrznBqV.js.map +1 -0
- package/dist/echo-PyZ6XYF6.js +11 -0
- package/dist/echo-PyZ6XYF6.js.map +1 -0
- package/dist/exit-CizX3N_u.js +11 -0
- package/dist/exit-CizX3N_u.js.map +1 -0
- package/dist/fortune-DNnPar5a.js +59 -0
- package/dist/fortune-DNnPar5a.js.map +1 -0
- package/dist/help-Bj19kBqx.js +18 -0
- package/dist/help-Bj19kBqx.js.map +1 -0
- package/dist/hostname-BBOQWx6L.js +11 -0
- package/dist/hostname-BBOQWx6L.js.map +1 -0
- package/dist/lolcat-DtXOVEIh.js +36 -0
- package/dist/lolcat-DtXOVEIh.js.map +1 -0
- package/dist/ls-DiXv7los.js +19 -0
- package/dist/ls-DiXv7los.js.map +1 -0
- package/dist/main-B0XCFHus.js +904 -0
- package/dist/main-B0XCFHus.js.map +1 -0
- package/dist/main.d.ts +11 -0
- package/dist/main.js +6 -0
- package/dist/main.js.map +1 -0
- package/dist/make-Bg6DStEK.js +10 -0
- package/dist/make-Bg6DStEK.js.map +1 -0
- package/dist/man-CvHWF3E_.js +48 -0
- package/dist/man-CvHWF3E_.js.map +1 -0
- package/dist/mkdir-BTSAC1PK.js +11 -0
- package/dist/mkdir-BTSAC1PK.js.map +1 -0
- package/dist/neofetch-BDZJVYlF.js +39 -0
- package/dist/neofetch-BDZJVYlF.js.map +1 -0
- package/dist/pwd-CSapfDtw.js +11 -0
- package/dist/pwd-CSapfDtw.js.map +1 -0
- package/dist/reboot-Bwxhoa8q.js +11 -0
- package/dist/reboot-Bwxhoa8q.js.map +1 -0
- package/dist/reload-C-07Q8ce.js +11 -0
- package/dist/reload-C-07Q8ce.js.map +1 -0
- package/dist/rev-C8qQIyj_.js +11 -0
- package/dist/rev-C8qQIyj_.js.map +1 -0
- package/dist/rm-CenNYCS_.js +13 -0
- package/dist/rm-CenNYCS_.js.map +1 -0
- package/dist/rmdir-7-udpooP.js +12 -0
- package/dist/rmdir-7-udpooP.js.map +1 -0
- package/dist/sl-B5Yqxs1W.js +167 -0
- package/dist/sl-B5Yqxs1W.js.map +1 -0
- package/dist/touch-BcjKUZ_T.js +20 -0
- package/dist/touch-BcjKUZ_T.js.map +1 -0
- package/dist/uptime-BYmCcOUM.js +11 -0
- package/dist/uptime-BYmCcOUM.js.map +1 -0
- package/dist/whatis-DLaPchWe.js +14 -0
- package/dist/whatis-DLaPchWe.js.map +1 -0
- package/dist/whoami-CQNGmqxL.js +11 -0
- package/dist/whoami-CQNGmqxL.js.map +1 -0
- package/package.json +16 -6
- package/src/components/Ansi.tsx +0 -174
- package/src/components/InputLine.tsx +0 -55
- package/src/components/OutputLine.tsx +0 -17
- package/src/components/Terminal.module.css +0 -126
- package/src/components/Terminal.tsx +0 -369
- package/src/constants/terminal.const.ts +0 -43
- package/src/core/_utils/terminal.utils.ts +0 -10
- package/src/core/command.ts +0 -95
- package/src/core/commands/cat.ts +0 -33
- package/src/core/commands/cd.ts +0 -20
- package/src/core/commands/clear.ts +0 -15
- package/src/core/commands/cmatrix.ts +0 -101
- package/src/core/commands/compgen.ts +0 -14
- package/src/core/commands/cowsay.ts +0 -108
- package/src/core/commands/dir.ts +0 -15
- package/src/core/commands/echo.ts +0 -10
- package/src/core/commands/exit.ts +0 -11
- package/src/core/commands/fortune.ts +0 -63
- package/src/core/commands/help.ts +0 -28
- package/src/core/commands/hostname.ts +0 -10
- package/src/core/commands/lolcat.ts +0 -54
- package/src/core/commands/ls.ts +0 -31
- package/src/core/commands/make.ts +0 -9
- package/src/core/commands/man.ts +0 -86
- package/src/core/commands/mkdir.ts +0 -17
- package/src/core/commands/neofetch.ts +0 -69
- package/src/core/commands/pwd.ts +0 -15
- package/src/core/commands/reboot.ts +0 -11
- package/src/core/commands/reload.ts +0 -11
- package/src/core/commands/rev.ts +0 -10
- package/src/core/commands/rm.ts +0 -21
- package/src/core/commands/rmdir.ts +0 -19
- package/src/core/commands/sl.ts +0 -220
- package/src/core/commands/touch.ts +0 -27
- package/src/core/commands/uptime.ts +0 -10
- package/src/core/commands/whatis.ts +0 -22
- package/src/core/commands/whoami.ts +0 -10
- package/src/core/commands.ts +0 -52
- package/src/core/stream.ts +0 -38
- package/src/index.ts +0 -7
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { f as p, S as g } from "./main-B0XCFHus.js";
|
|
2
|
+
import { C as w } from "./command-nBL1aO7T.js";
|
|
3
|
+
const I = 1.25, i = [
|
|
4
|
+
[
|
|
5
|
+
" (@@) ( ) (@) ( ) @@ () @ o @ o",
|
|
6
|
+
" ( )",
|
|
7
|
+
" (@@@@)",
|
|
8
|
+
" ( )",
|
|
9
|
+
"",
|
|
10
|
+
" (@@@)"
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
" ( ) (@@) ( ) (@) () @@ o @ o @",
|
|
14
|
+
" (@@@)",
|
|
15
|
+
" ( )",
|
|
16
|
+
" (@@@@)",
|
|
17
|
+
"",
|
|
18
|
+
" ( )"
|
|
19
|
+
]
|
|
20
|
+
], u = [
|
|
21
|
+
" ==== ________ ___________",
|
|
22
|
+
" _D _| |_______/ \\__I_I_____===__|_________|",
|
|
23
|
+
" |(_)--- | H\\________/ | | =|___ ___| ",
|
|
24
|
+
" / | | H | | | | ||_| |_|| ",
|
|
25
|
+
" | | | H |__--------------------| [___] | ",
|
|
26
|
+
" | ________|___H__/__|_____/[][]~\\_______| | ",
|
|
27
|
+
" |/ | |-----------I_____I [][] [] D |=======|__"
|
|
28
|
+
], m = [
|
|
29
|
+
[
|
|
30
|
+
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__",
|
|
31
|
+
" |/-=|___|= || || || |_____/~\\___/ ",
|
|
32
|
+
" \\_/ \\O=====O=====O=====O_/ \\_/ "
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__",
|
|
36
|
+
" |/-=|___|=O=====O=====O=====O |_____/~\\___/ ",
|
|
37
|
+
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
"__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__",
|
|
41
|
+
" |/-=|___|= || || || |_____/~\\___/ ",
|
|
42
|
+
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
"__/ =| o |=-~O=====O=====O=====O\\ ____Y___________|__",
|
|
46
|
+
" |/-=|___|= || || || |_____/~\\___/ ",
|
|
47
|
+
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__",
|
|
51
|
+
" |/-=|___|= O=====O=====O=====O|_____/~\\___/ ",
|
|
52
|
+
" \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
"__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__",
|
|
56
|
+
" |/-=|___|= || || || |_____/~\\___/ ",
|
|
57
|
+
" \\_/ \\_O=====O=====O=====O/ \\_/ "
|
|
58
|
+
]
|
|
59
|
+
].reverse(), f = [
|
|
60
|
+
" ",
|
|
61
|
+
" _________________ ",
|
|
62
|
+
" _| \\_____A ",
|
|
63
|
+
" =| | ",
|
|
64
|
+
" -| | ",
|
|
65
|
+
"__|________________________|_",
|
|
66
|
+
"|__________________________|_",
|
|
67
|
+
" |_D__D__D_| |_D__D__D_| ",
|
|
68
|
+
" \\_/ \\_/ \\_/ \\_/ "
|
|
69
|
+
], h = [
|
|
70
|
+
[
|
|
71
|
+
" _______================_______ ",
|
|
72
|
+
" | | ___ ___ ___ ___ | | ",
|
|
73
|
+
" | | | | | | | | | | | | ",
|
|
74
|
+
" | | |_| |_| |_| |_| | | ",
|
|
75
|
+
" | | | | ",
|
|
76
|
+
"__|__|____________________|__|__",
|
|
77
|
+
"_|____________________________|_",
|
|
78
|
+
" |_D__D__D_| |_D__D__D_| ",
|
|
79
|
+
" \\_/ \\_/ \\_/ \\_/ "
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
" ",
|
|
83
|
+
" ________========__HH____ ",
|
|
84
|
+
" / HH \\ ",
|
|
85
|
+
"/ HH \\ ",
|
|
86
|
+
"\\ HH / ",
|
|
87
|
+
"_\\__________________HH____/__",
|
|
88
|
+
"|__________________________|_",
|
|
89
|
+
" |_D__D__D_| |_D__D__D_| ",
|
|
90
|
+
" \\_/ \\_/ \\_/ \\_/ "
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
" ",
|
|
94
|
+
" ",
|
|
95
|
+
" ",
|
|
96
|
+
" ",
|
|
97
|
+
" ",
|
|
98
|
+
"_____________________________",
|
|
99
|
+
"|__________________________|_",
|
|
100
|
+
" |_D__D__D_| |_D__D__D_| ",
|
|
101
|
+
" \\_/ \\_/ \\_/ \\_/ "
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
" ",
|
|
105
|
+
" _|__|___________|__|___ ",
|
|
106
|
+
" (_|__|___________|__|___) ",
|
|
107
|
+
" _(|__|___________|__|__)_ ",
|
|
108
|
+
" (__|__|___________|__|____)",
|
|
109
|
+
"_(___|__|___________|__|__)__",
|
|
110
|
+
"|__________________________|_",
|
|
111
|
+
" |_D__D__D_| |_D__D__D_| ",
|
|
112
|
+
" \\_/ \\_/ \\_/ \\_/ "
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
" ",
|
|
116
|
+
" ___________________________ ",
|
|
117
|
+
" \\ | | / ",
|
|
118
|
+
" \\ | | / ",
|
|
119
|
+
" |\\ | | /| ",
|
|
120
|
+
"__|_\\___|___________|___/_|__",
|
|
121
|
+
"|__________________________|_",
|
|
122
|
+
" |_D__D__D_| |_D__D__D_| ",
|
|
123
|
+
" \\_/ \\_/ \\_/ \\_/ "
|
|
124
|
+
]
|
|
125
|
+
];
|
|
126
|
+
function E(s, r = 1) {
|
|
127
|
+
const o = i[0].length, e = u.length + m[0].length, _ = f.length, n = o + e - _, c = i[Math.round(s / 4) % i.length], a = u, H = m[s % m.length], O = 50 - s;
|
|
128
|
+
return `
|
|
129
|
+
${c.concat(a, H).map((t, l) => {
|
|
130
|
+
if (l >= n && r > 0)
|
|
131
|
+
for (let D = 0; D < r; D++)
|
|
132
|
+
D === 0 ? t += f[l - n] : t += h[(D - 1) % h.length][l - n];
|
|
133
|
+
return O === 0 ? t : O > 0 ? " ".repeat(O) + t : (t = t.slice(-O), t);
|
|
134
|
+
}).join(`
|
|
135
|
+
`)}
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
const M = new w().setManual({
|
|
139
|
+
purpose: "Show animations aimed to correct users who accidentally enter sl instead of ls. SL stands for Steam Locomotive.",
|
|
140
|
+
usage: `sl
|
|
141
|
+
sl -w number`,
|
|
142
|
+
options: {
|
|
143
|
+
"-w number": "Set the amount of wagons (defaults to 1)"
|
|
144
|
+
}
|
|
145
|
+
}).addOption({
|
|
146
|
+
short: "w",
|
|
147
|
+
long: "wagons",
|
|
148
|
+
isInput: !0
|
|
149
|
+
}).setExecute(function(s, r) {
|
|
150
|
+
const { inputs: o } = r;
|
|
151
|
+
let e = 1;
|
|
152
|
+
if (o != null && o.w && (e = parseInt(o.w), !e || e < 0))
|
|
153
|
+
return p(this.name, "Please specify a valid amount of wagons");
|
|
154
|
+
const _ = new g();
|
|
155
|
+
let n = 0;
|
|
156
|
+
const c = setInterval(() => {
|
|
157
|
+
const a = E(n, e);
|
|
158
|
+
_.send(a), n++, a.trim().length === 0 && _.stop();
|
|
159
|
+
}, 100 / I);
|
|
160
|
+
return _.on(g.EVENT_NAMES.stop, () => {
|
|
161
|
+
clearInterval(c);
|
|
162
|
+
}), _.start(), _;
|
|
163
|
+
});
|
|
164
|
+
export {
|
|
165
|
+
M as sl
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=sl-B5Yqxs1W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sl-B5Yqxs1W.js","sources":["../src/core/commands/sl.ts"],"sourcesContent":["import { formatError } from \"../_utils/terminal.utils\";\r\nimport { Command, ExecuteParams } from \"../command\";\r\nimport { Stream } from \"../stream\";\r\n\r\nconst ANIMATION_SPEED = 1.25;\r\n\r\nconst LOCOMOTIVE_SMOKE = [\r\n\t[\r\n\t\t\" (@@) ( ) (@) ( ) @@ () @ o @ o\",\r\n\t\t\" ( )\",\r\n\t\t\" (@@@@)\",\r\n\t\t\" ( )\",\r\n\t\t\"\",\r\n\t\t\" (@@@)\",\r\n\t],\r\n\t[\r\n\t\t\" ( ) (@@) ( ) (@) () @@ o @ o @\",\r\n\t\t\" (@@@)\",\r\n\t\t\" ( )\",\r\n\t\t\" (@@@@)\",\r\n\t\t\"\",\r\n\t\t\" ( )\",\r\n\t]\r\n];\r\n\r\nconst LOCOMOTIVE_TOP = [\r\n\t\" ==== ________ ___________\",\r\n\t\" _D _| |_______/ \\\\__I_I_____===__|_________|\",\r\n\t\" |(_)--- | H\\\\________/ | | =|___ ___| \",\r\n\t\" / | | H | | | | ||_| |_|| \",\r\n\t\" | | | H |__--------------------| [___] | \",\r\n\t\" | ________|___H__/__|_____/[][]~\\\\_______| | \",\r\n\t\" |/ | |-----------I_____I [][] [] D |=======|__\",\r\n];\r\n\r\nconst LOCOMOTIVE_BOTTOM = [\r\n\t[\r\n\t\t\"__/ =| o |=-~~\\\\ /~~\\\\ /~~\\\\ /~~\\\\ ____Y___________|__\",\r\n\t\t\" |/-=|___|= || || || |_____/~\\\\___/ \",\r\n\t\t\" \\\\_/ \\\\O=====O=====O=====O_/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\"__/ =| o |=-~~\\\\ /~~\\\\ /~~\\\\ /~~\\\\ ____Y___________|__\",\r\n\t\t\" |/-=|___|=O=====O=====O=====O |_____/~\\\\___/ \",\r\n\t\t\" \\\\_/ \\\\__/ \\\\__/ \\\\__/ \\\\__/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\"__/ =| o |=-O=====O=====O=====O \\\\ ____Y___________|__\",\r\n\t\t\" |/-=|___|= || || || |_____/~\\\\___/ \",\r\n\t\t\" \\\\_/ \\\\__/ \\\\__/ \\\\__/ \\\\__/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\"__/ =| o |=-~O=====O=====O=====O\\\\ ____Y___________|__\",\r\n\t\t\" |/-=|___|= || || || |_____/~\\\\___/ \",\r\n\t\t\" \\\\_/ \\\\__/ \\\\__/ \\\\__/ \\\\__/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\"__/ =| o |=-~~\\\\ /~~\\\\ /~~\\\\ /~~\\\\ ____Y___________|__\",\r\n\t\t\" |/-=|___|= O=====O=====O=====O|_____/~\\\\___/ \",\r\n\t\t\" \\\\_/ \\\\__/ \\\\__/ \\\\__/ \\\\__/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\"__/ =| o |=-~~\\\\ /~~\\\\ /~~\\\\ /~~\\\\ ____Y___________|__\",\r\n\t\t\" |/-=|___|= || || || |_____/~\\\\___/ \",\r\n\t\t\" \\\\_/ \\\\_O=====O=====O=====O/ \\\\_/ \",\r\n\t]\r\n].reverse();\r\n\r\nconst COAL_WAGON = [\r\n\t\" \",\r\n\t\" _________________ \",\r\n\t\" _| \\\\_____A \",\r\n\t\" =| | \",\r\n\t\" -| | \",\r\n\t\"__|________________________|_\",\r\n\t\"|__________________________|_\",\r\n\t\" |_D__D__D_| |_D__D__D_| \",\r\n\t\" \\\\_/ \\\\_/ \\\\_/ \\\\_/ \",\r\n];\r\n\r\nconst EXTRA_WAGONS = [\r\n\t[\r\n\t\t\" _______================_______ \",\r\n\t\t\" | | ___ ___ ___ ___ | | \",\r\n\t\t\" | | | | | | | | | | | | \",\r\n\t\t\" | | |_| |_| |_| |_| | | \",\r\n\t\t\" | | | | \",\r\n\t\t\"__|__|____________________|__|__\",\r\n\t\t\"_|____________________________|_\",\r\n\t\t\" |_D__D__D_| |_D__D__D_| \",\r\n\t\t\" \\\\_/ \\\\_/ \\\\_/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\" \",\r\n\t\t\" ________========__HH____ \",\r\n\t\t\" / HH \\\\ \",\r\n\t\t\"/ HH \\\\ \",\r\n\t\t\"\\\\ HH / \",\r\n\t\t\"_\\\\__________________HH____/__\",\r\n\t\t\"|__________________________|_\",\r\n\t\t\" |_D__D__D_| |_D__D__D_| \",\r\n\t\t\" \\\\_/ \\\\_/ \\\\_/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\" \",\r\n\t\t\" \",\r\n\t\t\" \",\r\n\t\t\" \",\r\n\t\t\" \",\r\n\t\t\"_____________________________\",\r\n\t\t\"|__________________________|_\",\r\n\t\t\" |_D__D__D_| |_D__D__D_| \",\r\n\t\t\" \\\\_/ \\\\_/ \\\\_/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\" \",\r\n\t\t\" _|__|___________|__|___ \",\r\n\t\t\" (_|__|___________|__|___) \",\r\n\t\t\" _(|__|___________|__|__)_ \",\r\n\t\t\" (__|__|___________|__|____)\",\r\n\t\t\"_(___|__|___________|__|__)__\",\r\n\t\t\"|__________________________|_\",\r\n\t\t\" |_D__D__D_| |_D__D__D_| \",\r\n\t\t\" \\\\_/ \\\\_/ \\\\_/ \\\\_/ \",\r\n\t],\r\n\t[\r\n\t\t\" \",\r\n\t\t\" ___________________________ \",\r\n\t\t\" \\\\ | | / \",\r\n\t\t\" \\\\ | | / \",\r\n\t\t\" |\\\\ | | /| \",\r\n\t\t\"__|_\\\\___|___________|___/_|__\",\r\n\t\t\"|__________________________|_\",\r\n\t\t\" |_D__D__D_| |_D__D__D_| \",\r\n\t\t\" \\\\_/ \\\\_/ \\\\_/ \\\\_/ \",\r\n\t],\r\n];\r\n\r\nfunction generateLocomotive(frame: number, wagonCount = 1) {\r\n\tconst smokeHeight = LOCOMOTIVE_SMOKE[0].length;\r\n\tconst locomotiveHeight = LOCOMOTIVE_TOP.length + LOCOMOTIVE_BOTTOM[0].length;\r\n\tconst wagonHeight = COAL_WAGON.length;\r\n\r\n\tconst wagonStart = smokeHeight + locomotiveHeight - wagonHeight;\r\n\r\n\tconst smoke = LOCOMOTIVE_SMOKE[Math.round(frame / 4) % LOCOMOTIVE_SMOKE.length];\r\n\tconst top = LOCOMOTIVE_TOP;\r\n\tconst bottom = LOCOMOTIVE_BOTTOM[frame % LOCOMOTIVE_BOTTOM.length];\r\n\r\n\tconst distance = 50 - frame;\r\n\tconst locomotive = smoke.concat(top, bottom).map((line, index) => {\r\n\t\tif (index >= wagonStart && wagonCount > 0) {\r\n\t\t\tfor (let i = 0; i < wagonCount; i++) {\r\n\t\t\t\tif (i === 0) {\r\n\t\t\t\t\tline += COAL_WAGON[index - wagonStart];\r\n\t\t\t\t} else {\r\n\t\t\t\t\tline += EXTRA_WAGONS[(i - 1) % EXTRA_WAGONS.length][index - wagonStart];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (distance === 0) {\r\n\t\t\treturn line;\r\n\t\t} else if (distance > 0) {\r\n\t\t\treturn \" \".repeat(distance) + line;\r\n\t\t} else {\r\n\t\t\tline = line.slice(-distance);\r\n\t\t\treturn line;\r\n\t\t}\r\n\t}).join(\"\\n\");\r\n\r\n\treturn `\\n${locomotive}\\n`;\r\n}\r\n\r\nexport const sl = new Command()\r\n\t.setManual({\r\n\t\tpurpose: \"Show animations aimed to correct users who accidentally enter sl instead of ls. SL stands for Steam Locomotive.\",\r\n\t\tusage: \"sl\\n\"\r\n\t\t\t+ \"sl -w number\",\r\n\t\toptions: {\r\n\t\t\t\"-w number\": \"Set the amount of wagons (defaults to 1)\"\r\n\t\t}\r\n\t})\r\n\t.addOption({\r\n\t\tshort: \"w\",\r\n\t\tlong: \"wagons\",\r\n\t\tisInput: true\r\n\t})\r\n\t.setExecute(function(this: Command, args, params) {\r\n\t\tconst { inputs } = params as ExecuteParams;\r\n\t\tlet wagonCount = 1;\r\n\r\n\t\tif (inputs?.w) {\r\n\t\t\twagonCount = parseInt(inputs.w);\r\n\r\n\t\t\tif (!wagonCount || wagonCount < 0) {\r\n\t\t\t\treturn formatError(this.name, \"Please specify a valid amount of wagons\"); \r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst stream = new Stream();\r\n\r\n\t\tlet frame = 0;\r\n\t\tconst interval = setInterval(() => {\r\n\t\t\tconst text = generateLocomotive(frame, wagonCount);\r\n\t\t\tstream.send(text);\r\n\t\t\tframe++;\r\n\r\n\t\t\tif (text.trim().length === 0)\r\n\t\t\t\tstream.stop();\r\n\t\t}, 100 / ANIMATION_SPEED);\r\n\r\n\t\tstream.on(Stream.EVENT_NAMES.stop, () => {\r\n\t\t\tclearInterval(interval);\r\n\t\t});\r\n\r\n\t\tstream.start();\r\n\r\n\t\treturn stream;\r\n\t});"],"names":["ANIMATION_SPEED","LOCOMOTIVE_SMOKE","LOCOMOTIVE_TOP","LOCOMOTIVE_BOTTOM","COAL_WAGON","EXTRA_WAGONS","generateLocomotive","frame","wagonCount","smokeHeight","locomotiveHeight","wagonHeight","wagonStart","smoke","top","bottom","distance","line","index","i","sl","Command","args","params","inputs","formatError","stream","Stream","interval","text"],"mappings":";;AAIA,MAAMA,IAAkB,MAElBC,IAAmB;AAAA,EACxB;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD,GAEMC,IAAiB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAEMC,IAAoB;AAAA,EACzB;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD,EAAE,QAAQ,GAEJC,IAAa;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAEMC,IAAe;AAAA,EACpB;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAASC,EAAmBC,GAAeC,IAAa,GAAG;AACpD,QAAAC,IAAcR,EAAiB,CAAC,EAAE,QAClCS,IAAmBR,EAAe,SAASC,EAAkB,CAAC,EAAE,QAChEQ,IAAcP,EAAW,QAEzBQ,IAAaH,IAAcC,IAAmBC,GAE9CE,IAAQZ,EAAiB,KAAK,MAAMM,IAAQ,CAAC,IAAIN,EAAiB,MAAM,GACxEa,IAAMZ,GACNa,IAASZ,EAAkBI,IAAQJ,EAAkB,MAAM,GAE3Da,IAAW,KAAKT;AAsBf,SAAA;AAAA,EArBYM,EAAM,OAAOC,GAAKC,CAAM,EAAE,IAAI,CAACE,GAAMC,MAAU;AAC7D,QAAAA,KAASN,KAAcJ,IAAa;AACvC,eAASW,IAAI,GAAGA,IAAIX,GAAYW;AAC/B,QAAIA,MAAM,IACDF,KAAAb,EAAWc,IAAQN,CAAU,IAErCK,KAAQZ,GAAcc,IAAI,KAAKd,EAAa,MAAM,EAAEa,IAAQN,CAAU;AAKzE,WAAII,MAAa,IACTC,IACGD,IAAW,IACd,IAAI,OAAOA,CAAQ,IAAIC,KAEvBA,IAAAA,EAAK,MAAM,CAACD,CAAQ,GACpBC;AAAA,EACR,CACA,EAAE,KAAK;AAAA,CAAI,CAEU;AAAA;AACvB;AAEO,MAAMG,IAAK,IAAIC,EAAQ,EAC5B,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA;AAAA,EAEP,SAAS;AAAA,IACR,aAAa;AAAA,EACd;AACD,CAAC,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACV,CAAC,EACA,WAAW,SAAwBC,GAAMC,GAAQ;AAC3C,QAAA,EAAE,QAAAC,EAAW,IAAAD;AACnB,MAAIf,IAAa;AAEjB,MAAIgB,KAAA,QAAAA,EAAQ,MACEhB,IAAA,SAASgB,EAAO,CAAC,GAE1B,CAAChB,KAAcA,IAAa;AACxB,WAAAiB,EAAY,KAAK,MAAM,yCAAyC;AAInE,QAAAC,IAAS,IAAIC;AAEnB,MAAIpB,IAAQ;AACN,QAAAqB,IAAW,YAAY,MAAM;AAC5B,UAAAC,IAAOvB,EAAmBC,GAAOC,CAAU;AACjD,IAAAkB,EAAO,KAAKG,CAAI,GAChBtB,KAEIsB,EAAK,OAAO,WAAW,KAC1BH,EAAO,KAAK;AAAA,EAAA,GACX,MAAM1B,CAAe;AAExB,SAAA0B,EAAO,GAAGC,EAAO,YAAY,MAAM,MAAM;AACxC,kBAAcC,CAAQ;AAAA,EAAA,CACtB,GAEDF,EAAO,MAAM,GAENA;AACR,CAAC;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { VirtualFile as s } from "@prozilla-os/core";
|
|
2
|
+
import { f as a } from "./main-B0XCFHus.js";
|
|
3
|
+
import { C as c } from "./command-nBL1aO7T.js";
|
|
4
|
+
const l = new c().setRequireArgs(!0).setManual({
|
|
5
|
+
purpose: "Change file timestamps",
|
|
6
|
+
usage: "touch [options] files",
|
|
7
|
+
description: `Update the access and modification times of each FILE to the current time.
|
|
8
|
+
|
|
9
|
+
A file argument that does not exist is created empty.`
|
|
10
|
+
}).setExecute(function(e, n) {
|
|
11
|
+
const { currentDirectory: t } = n, i = e[0];
|
|
12
|
+
if (i === "girls\\" && e[1] === "boo**")
|
|
13
|
+
return a(this.name, "Cannot touch 'girls boo**': Permission denied");
|
|
14
|
+
const { name: o, extension: r } = s.splitId(i);
|
|
15
|
+
return t.findFile(o, r) ? { blank: !0 } : (t.createFile(o, r), { blank: !0 });
|
|
16
|
+
});
|
|
17
|
+
export {
|
|
18
|
+
l as touch
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=touch-BcjKUZ_T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touch-BcjKUZ_T.js","sources":["../src/core/commands/touch.ts"],"sourcesContent":["import { VirtualFile } from \"@prozilla-os/core\";\r\nimport { formatError } from \"../_utils/terminal.utils\";\r\nimport { Command, ExecuteParams } from \"../command\";\r\n\r\nexport const touch = new Command()\r\n\t.setRequireArgs(true)\r\n\t.setManual({\r\n\t\tpurpose: \"Change file timestamps\",\r\n\t\tusage: \"touch [options] files\",\r\n\t\tdescription: \"Update the access and modification times of each FILE to the current time.\\n\\n\"\r\n\t\t\t+ \"A file argument that does not exist is created empty.\"\r\n\t})\r\n\t.setExecute(function(this: Command, args, params) {\r\n\t\tconst { currentDirectory } = params as ExecuteParams;\r\n\t\tconst fileId = (args as string[])[0];\r\n\r\n\t\tif (fileId === \"girls\\\\\" && (args as string[])[1] === \"boo**\")\r\n\t\t\treturn formatError((this).name, \"Cannot touch 'girls boo**': Permission denied\");\r\n\t\r\n\t\tconst { name, extension } = VirtualFile.splitId(fileId);\r\n\t\r\n\t\tif (currentDirectory.findFile(name, extension))\r\n\t\t\treturn { blank: true };\r\n\t\r\n\t\tcurrentDirectory.createFile(name, extension as string | undefined);\r\n\t\treturn { blank: true };\r\n\t});"],"names":["touch","Command","args","params","currentDirectory","fileId","formatError","name","extension","VirtualFile"],"mappings":";;;AAIO,MAAMA,IAAQ,IAAIC,IACvB,eAAe,EAAI,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,OAAO;AAAA,EACP,aAAa;AAAA;AAAA;AAEd,CAAC,EACA,WAAW,SAAwBC,GAAMC,GAAQ;AAC3C,QAAA,EAAE,kBAAAC,EAAqB,IAAAD,GACvBE,IAAUH,EAAkB,CAAC;AAEnC,MAAIG,MAAW,aAAcH,EAAkB,CAAC,MAAM;AAC9C,WAAAI,EAAa,KAAM,MAAM,+CAA+C;AAEhF,QAAM,EAAE,MAAAC,GAAM,WAAAC,EAAA,IAAcC,EAAY,QAAQJ,CAAM;AAElD,SAAAD,EAAiB,SAASG,GAAMC,CAAS,IACrC,EAAE,OAAO,QAEAJ,EAAA,WAAWG,GAAMC,CAA+B,GAC1D,EAAE,OAAO;AACjB,CAAC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { C as s } from "./command-nBL1aO7T.js";
|
|
2
|
+
const r = new s().setManual({
|
|
3
|
+
purpose: "Display the current uptime of the system"
|
|
4
|
+
}).setExecute(function(m, e) {
|
|
5
|
+
const { systemManager: t } = e;
|
|
6
|
+
return `Uptime: ${t.getUptime(2)}`;
|
|
7
|
+
});
|
|
8
|
+
export {
|
|
9
|
+
r as uptime
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=uptime-BYmCcOUM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uptime-BYmCcOUM.js","sources":["../src/core/commands/uptime.ts"],"sourcesContent":["import { Command, ExecuteParams } from \"../command\";\r\n\r\nexport const uptime = new Command()\r\n\t.setManual({\r\n\t\tpurpose: \"Display the current uptime of the system\"\r\n\t})\r\n\t.setExecute(function(args, params) {\r\n\t\tconst { systemManager } = params as ExecuteParams;\r\n\t\treturn `Uptime: ${systemManager.getUptime(2)}`;\r\n\t});"],"names":["uptime","Command","args","params","systemManager"],"mappings":";AAEO,MAAMA,IAAS,IAAIC,EAAQ,EAChC,UAAU;AAAA,EACV,SAAS;AACV,CAAC,EACA,WAAW,SAASC,GAAMC,GAAQ;AAC5B,QAAA,EAAE,eAAAC,EAAkB,IAAAD;AAC1B,SAAO,WAAWC,EAAc,UAAU,CAAC,CAAC;AAC7C,CAAC;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ANSI as t } from "@prozilla-os/core";
|
|
2
|
+
import { C as e, f as a } from "./main-B0XCFHus.js";
|
|
3
|
+
import { C as s } from "./command-nBL1aO7T.js";
|
|
4
|
+
const p = new s().setRequireArgs(!0).setManual({
|
|
5
|
+
purpose: "Show information about a command"
|
|
6
|
+
}).setExecute(function(m) {
|
|
7
|
+
var r;
|
|
8
|
+
const o = m[0].toLowerCase(), n = e.find(o);
|
|
9
|
+
return n ? (r = n.manual) != null && r.purpose ? `${o} - ${t.fg.green}${n.manual.purpose}` : a(this.name, `${o}: No information found`) : a(this.name, `${o}: Command not found`);
|
|
10
|
+
});
|
|
11
|
+
export {
|
|
12
|
+
p as whatis
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=whatis-DLaPchWe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whatis-DLaPchWe.js","sources":["../src/core/commands/whatis.ts"],"sourcesContent":["import { ANSI } from \"@prozilla-os/core\";\r\nimport { formatError } from \"../_utils/terminal.utils\";\r\nimport { Command } from \"../command\";\r\nimport { CommandsManager } from \"../commands\";\r\n\r\nexport const whatis = new Command()\r\n\t.setRequireArgs(true)\r\n\t.setManual({\r\n\t\tpurpose: \"Show information about a command\"\r\n\t})\r\n\t.setExecute(function(this: Command, args) {\r\n\t\tconst commandName = (args as string[])[0].toLowerCase();\r\n\t\tconst command = CommandsManager.find(commandName);\r\n\r\n\t\tif (!command)\r\n\t\t\treturn formatError(this.name, `${commandName}: Command not found`);\r\n\r\n\t\tif (!command.manual?.purpose)\r\n\t\t\treturn formatError(this.name, `${commandName}: No information found`);\r\n\r\n\t\treturn `${commandName} - ${ANSI.fg.green}${command.manual.purpose}`;\r\n\t});"],"names":["whatis","Command","args","commandName","command","CommandsManager","_a","ANSI","formatError"],"mappings":";;;AAKO,MAAMA,IAAS,IAAIC,IACxB,eAAe,EAAI,EACnB,UAAU;AAAA,EACV,SAAS;AACV,CAAC,EACA,WAAW,SAAwBC,GAAM;;AACzC,QAAMC,IAAeD,EAAkB,CAAC,EAAE,YAAY,GAChDE,IAAUC,EAAgB,KAAKF,CAAW;AAEhD,SAAKC,KAGAE,IAAAF,EAAQ,WAAR,QAAAE,EAAgB,UAGd,GAAGH,CAAW,MAAMI,EAAK,GAAG,KAAK,GAAGH,EAAQ,OAAO,OAAO,KAFzDI,EAAY,KAAK,MAAM,GAAGL,CAAW,wBAAwB,IAH7DK,EAAY,KAAK,MAAM,GAAGL,CAAW,qBAAqB;AAMnE,CAAC;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { C as a } from "./command-nBL1aO7T.js";
|
|
2
|
+
const n = new a().setManual({
|
|
3
|
+
purpose: "Display the username"
|
|
4
|
+
}).setExecute((r, e) => {
|
|
5
|
+
const { username: s } = e;
|
|
6
|
+
return s;
|
|
7
|
+
});
|
|
8
|
+
export {
|
|
9
|
+
n as whoami
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=whoami-CQNGmqxL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami-CQNGmqxL.js","sources":["../src/core/commands/whoami.ts"],"sourcesContent":["import { Command, ExecuteParams } from \"../command\";\r\n\r\nexport const whoami = new Command()\r\n\t.setManual({\r\n\t\tpurpose: \"Display the username\"\r\n\t})\r\n\t.setExecute((args, params) => {\r\n\t\tconst { username } = params as ExecuteParams;\r\n\t\treturn username;\r\n\t});"],"names":["whoami","Command","args","params","username"],"mappings":";AAEO,MAAMA,IAAS,IAAIC,EAAQ,EAChC,UAAU;AAAA,EACV,SAAS;AACV,CAAC,EACA,WAAW,CAACC,GAAMC,MAAW;AACvB,QAAA,EAAE,UAAAC,EAAa,IAAAD;AACd,SAAAC;AACR,CAAC;"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prozilla-os/terminal",
|
|
3
3
|
"description": "A terminal/shell application for ProzillaOS.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"homepage": "https://os.prozilla.dev/terminal",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Prozilla",
|
|
8
8
|
"email": "business@prozilla.dev",
|
|
9
9
|
"url": "https://prozilla.dev/"
|
|
10
10
|
},
|
|
11
|
-
"main": "src/index.ts",
|
|
12
11
|
"type": "module",
|
|
12
|
+
"main": "dist/main.js",
|
|
13
|
+
"types": "dist/main.d.ts",
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
15
16
|
"url": "git+https://github.com/prozilla-os/ProzillaOS.git",
|
|
@@ -20,19 +21,28 @@
|
|
|
20
21
|
"anser": "^2.1.1",
|
|
21
22
|
"escape-carriage": "^1.3.1",
|
|
22
23
|
"react": "^18.3.1",
|
|
23
|
-
"@prozilla-os/core": "1.0.
|
|
24
|
+
"@prozilla-os/core": "1.0.12"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"
|
|
27
|
+
"@types/node": "^20.14.5",
|
|
28
|
+
"@types/react": "^18.3.3",
|
|
29
|
+
"@vitejs/plugin-react-swc": "^3.7.0",
|
|
30
|
+
"typescript": "^5.4.5",
|
|
31
|
+
"vite": "^5.3.1",
|
|
32
|
+
"vite-plugin-dts": "^3.9.1",
|
|
33
|
+
"vite-plugin-lib-inject-css": "^2.1.1"
|
|
27
34
|
},
|
|
28
35
|
"files": [
|
|
29
|
-
"
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": [
|
|
39
|
+
"**/*.css"
|
|
30
40
|
],
|
|
31
41
|
"publishConfig": {
|
|
32
42
|
"registry": "https://registry.npmjs.org/",
|
|
33
43
|
"access": "public"
|
|
34
44
|
},
|
|
35
45
|
"scripts": {
|
|
36
|
-
"
|
|
46
|
+
"build": "tsc && vite build"
|
|
37
47
|
}
|
|
38
48
|
}
|
package/src/components/Ansi.tsx
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import Anser, { AnserJsonEntry } from "anser";
|
|
2
|
-
import { escapeCarriageReturn } from "escape-carriage";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import styles from "./Terminal.module.css";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Source:
|
|
8
|
-
* https://github.com/nteract/ansi-to-react/blob/master/src/index.ts
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Converts ANSI strings into JSON output.
|
|
13
|
-
* @param input - The input string.
|
|
14
|
-
* @param use_classes - If `true`, HTML classes will be appended
|
|
15
|
-
* to the HTML output.
|
|
16
|
-
* @returns The parsed input.
|
|
17
|
-
*/
|
|
18
|
-
function ansiToJSON(input: string, use_classes: boolean | undefined): AnserJsonEntry[] {
|
|
19
|
-
input = escapeCarriageReturn(fixBackspace(input));
|
|
20
|
-
return Anser.ansiToJson(input, {
|
|
21
|
-
json: true,
|
|
22
|
-
remove_empty: true,
|
|
23
|
-
use_classes,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Create a class string.
|
|
29
|
-
* @returns class name(s)
|
|
30
|
-
*/
|
|
31
|
-
function createClass(bundle: AnserJsonEntry): string | null {
|
|
32
|
-
const classNames = [];
|
|
33
|
-
|
|
34
|
-
if (bundle.bg) {
|
|
35
|
-
classNames.push(styles[`${bundle.bg}-bg`]);
|
|
36
|
-
}
|
|
37
|
-
if (bundle.fg) {
|
|
38
|
-
classNames.push(styles[`${bundle.fg}-fg`]);
|
|
39
|
-
}
|
|
40
|
-
if (bundle.decoration) {
|
|
41
|
-
classNames.push(styles[`ansi-${bundle.decoration}`]);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (classNames.length === 0) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return classNames.join(" ");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Create the style attribute.
|
|
53
|
-
* @param bundle
|
|
54
|
-
* @returns returns the style object
|
|
55
|
-
*/
|
|
56
|
-
function createStyle(bundle: AnserJsonEntry): object {
|
|
57
|
-
const style: Record<string, string> = {};
|
|
58
|
-
if (bundle.bg) {
|
|
59
|
-
style.backgroundColor = `rgb(${bundle.bg})`;
|
|
60
|
-
}
|
|
61
|
-
if (bundle.fg) {
|
|
62
|
-
style.color = `rgb(${bundle.fg})`;
|
|
63
|
-
}
|
|
64
|
-
switch (bundle.decoration) {
|
|
65
|
-
case "bold":
|
|
66
|
-
style.fontWeight = "bold";
|
|
67
|
-
break;
|
|
68
|
-
case "dim":
|
|
69
|
-
style.opacity = "0.5";
|
|
70
|
-
break;
|
|
71
|
-
case "italic":
|
|
72
|
-
style.fontStyle = "italic";
|
|
73
|
-
break;
|
|
74
|
-
case "hidden":
|
|
75
|
-
style.visibility = "hidden";
|
|
76
|
-
break;
|
|
77
|
-
case "strikethrough":
|
|
78
|
-
style.textDecoration = "line-through";
|
|
79
|
-
break;
|
|
80
|
-
case "underline":
|
|
81
|
-
style.textDecoration = "underline";
|
|
82
|
-
break;
|
|
83
|
-
case "blink":
|
|
84
|
-
style.textDecoration = "blink";
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
return style;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Converts an Anser bundle into a React Node.
|
|
94
|
-
* @param linkify - whether links should be converting into clickable anchor tags.
|
|
95
|
-
* @param useClasses - should render the span with a class instead of style.
|
|
96
|
-
* @param bundle - Anser output.
|
|
97
|
-
*/
|
|
98
|
-
function convertBundleIntoReact(linkify: boolean, useClasses: boolean, bundle: AnserJsonEntry, key: number) {
|
|
99
|
-
const style = useClasses ? null : createStyle(bundle);
|
|
100
|
-
const className = useClasses ? createClass(bundle) : null;
|
|
101
|
-
|
|
102
|
-
if (!linkify) {
|
|
103
|
-
return React.createElement(
|
|
104
|
-
"pre",
|
|
105
|
-
{ style, key, className },
|
|
106
|
-
bundle.content
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const content = [];
|
|
111
|
-
const linkRegex = /(\s|^)(https?:\/\/(?:www\.|(?!www))[^\s.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g;
|
|
112
|
-
|
|
113
|
-
let index = 0;
|
|
114
|
-
let match: RegExpExecArray | null;
|
|
115
|
-
while ((match = linkRegex.exec(bundle.content)) !== null) {
|
|
116
|
-
const [, pre, url] = match;
|
|
117
|
-
|
|
118
|
-
const startIndex = match.index + pre.length;
|
|
119
|
-
if (startIndex > index) {
|
|
120
|
-
content.push(bundle.content.substring(index, startIndex));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Make sure the href we generate from the link is fully qualified. We assume http
|
|
124
|
-
// if it starts with a www because many sites don't support https
|
|
125
|
-
const href = url.startsWith("www.") ? `http://${url}` : url;
|
|
126
|
-
content.push(
|
|
127
|
-
React.createElement(
|
|
128
|
-
"a",
|
|
129
|
-
{
|
|
130
|
-
key: index,
|
|
131
|
-
href,
|
|
132
|
-
target: "_blank",
|
|
133
|
-
},
|
|
134
|
-
`${url}`
|
|
135
|
-
)
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
index = linkRegex.lastIndex;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (index < bundle.content.length) {
|
|
142
|
-
content.push(bundle.content.substring(index));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return React.createElement("span", { style, key, className }, content);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function Ansi(props: { children?: string | undefined; linkify?: boolean | undefined; className?: string | undefined; useClasses?: boolean | undefined; }) {
|
|
149
|
-
const { className, useClasses, children, linkify } = props;
|
|
150
|
-
return React.createElement(
|
|
151
|
-
"code",
|
|
152
|
-
{ className },
|
|
153
|
-
ansiToJSON(children ?? "", useClasses ?? false).map(
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
155
|
-
convertBundleIntoReact.bind(null, linkify ?? false, useClasses ?? false)
|
|
156
|
-
)
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// This is copied from the Jupyter Classic source code
|
|
161
|
-
// notebook/static/base/js/utils.js to handle \b in a way
|
|
162
|
-
// that is **compatible with Jupyter classic**. One can
|
|
163
|
-
// argue that this behavior is questionable:
|
|
164
|
-
// https://stackoverflow.com/questions/55440152/multiple-b-doesnt-work-as-expected-in-jupyter#
|
|
165
|
-
function fixBackspace(txt: string) {
|
|
166
|
-
let tmp = txt;
|
|
167
|
-
do {
|
|
168
|
-
txt = tmp;
|
|
169
|
-
// Cancel out anything-but-newline followed by backspace
|
|
170
|
-
// eslint-disable-next-line no-control-regex
|
|
171
|
-
tmp = txt.replace(/[^\n]\x08/gm, "");
|
|
172
|
-
} while (tmp.length < txt.length);
|
|
173
|
-
return txt;
|
|
174
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { CSSProperties, MutableRefObject, useState } from "react";
|
|
2
|
-
import styles from "./Terminal.module.css";
|
|
3
|
-
import { Ansi } from "./Ansi";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface InputLineProps {
|
|
7
|
-
value: string;
|
|
8
|
-
prefix: string;
|
|
9
|
-
onChange: Function;
|
|
10
|
-
onKeyUp?: Function;
|
|
11
|
-
onKeyDown?: Function;
|
|
12
|
-
inputRef: MutableRefObject<HTMLInputElement>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function InputLine({ value, prefix, onChange, onKeyUp, onKeyDown, inputRef }: InputLineProps) {
|
|
16
|
-
const [cursorPosition, setCursorPosition] = useState(0);
|
|
17
|
-
|
|
18
|
-
const checkCursorPosition = () => {
|
|
19
|
-
const selectionStart = inputRef.current?.selectionStart;
|
|
20
|
-
if (selectionStart != null) setCursorPosition(selectionStart);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<span className={styles.Input}>
|
|
25
|
-
{prefix && <Ansi className={styles.Prefix} useClasses>{prefix}</Ansi>}
|
|
26
|
-
<span className={styles["Input-container"]} style={{ "--cursor-offset": cursorPosition } as CSSProperties}>
|
|
27
|
-
<span aria-hidden="true">{value}</span>
|
|
28
|
-
<input
|
|
29
|
-
id="input"
|
|
30
|
-
value={value}
|
|
31
|
-
aria-label="Command input"
|
|
32
|
-
onChange={(event) => {
|
|
33
|
-
onChange(event);
|
|
34
|
-
checkCursorPosition();
|
|
35
|
-
}}
|
|
36
|
-
ref={inputRef}
|
|
37
|
-
onKeyUp={(event) => { onKeyUp?.(event); }}
|
|
38
|
-
onKeyDown={(event) => {
|
|
39
|
-
onKeyDown?.(event);
|
|
40
|
-
checkCursorPosition();
|
|
41
|
-
}}
|
|
42
|
-
onClick={checkCursorPosition}
|
|
43
|
-
onTouchEnd={checkCursorPosition}
|
|
44
|
-
onSelect={checkCursorPosition}
|
|
45
|
-
onCut={checkCursorPosition}
|
|
46
|
-
onCopy={checkCursorPosition}
|
|
47
|
-
onPaste={checkCursorPosition}
|
|
48
|
-
spellCheck={false}
|
|
49
|
-
autoComplete="off"
|
|
50
|
-
autoFocus
|
|
51
|
-
/>
|
|
52
|
-
</span>
|
|
53
|
-
</span>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { FC, forwardRef } from "react";
|
|
2
|
-
import { Ansi } from "./Ansi";
|
|
3
|
-
import styles from "./Terminal.module.css";
|
|
4
|
-
|
|
5
|
-
interface OutputLineProps {
|
|
6
|
-
text?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const OutputLine: FC<OutputLineProps> = forwardRef<HTMLDivElement>(({ text }: OutputLineProps, ref) => {
|
|
10
|
-
const lines = text?.split("\n");
|
|
11
|
-
|
|
12
|
-
return <div ref={ref}>
|
|
13
|
-
{lines?.map((line, index) =>
|
|
14
|
-
<Ansi key={index} className={styles.Output} useClasses>{line === "" ? " " : line}</Ansi>
|
|
15
|
-
)}
|
|
16
|
-
</div>;
|
|
17
|
-
}) as FC;
|