@prozilla-os/terminal 1.0.1 → 1.0.3
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-Dp7MxLJO.js +17 -0
- package/dist/cat-Dp7MxLJO.js.map +1 -0
- package/dist/cd-zk1UnOo7.js +14 -0
- package/dist/cd-zk1UnOo7.js.map +1 -0
- package/dist/clear-DtYBxmDr.js +14 -0
- package/dist/clear-DtYBxmDr.js.map +1 -0
- package/dist/cmatrix-O49Zkqb8.js +59 -0
- package/dist/cmatrix-O49Zkqb8.js.map +1 -0
- package/dist/command-nBL1aO7T.js +43 -0
- package/dist/command-nBL1aO7T.js.map +1 -0
- package/dist/compgen-CA_GMRpy.js +14 -0
- package/dist/compgen-CA_GMRpy.js.map +1 -0
- package/dist/cowsay-BAYsU72K.js +50 -0
- package/dist/cowsay-BAYsU72K.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-CYIno6WY.js +18 -0
- package/dist/help-CYIno6WY.js.map +1 -0
- package/dist/hostname-BBOQWx6L.js +11 -0
- package/dist/hostname-BBOQWx6L.js.map +1 -0
- package/dist/lolcat-LdzLGQur.js +36 -0
- package/dist/lolcat-LdzLGQur.js.map +1 -0
- package/dist/ls-Csd6ypmW.js +19 -0
- package/dist/ls-Csd6ypmW.js.map +1 -0
- package/dist/main-tAp_mbfZ.js +904 -0
- package/dist/main-tAp_mbfZ.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-DOc--PtL.js +10 -0
- package/dist/make-DOc--PtL.js.map +1 -0
- package/dist/man-CZoHwxyo.js +48 -0
- package/dist/man-CZoHwxyo.js.map +1 -0
- package/dist/mkdir-BTSAC1PK.js +11 -0
- package/dist/mkdir-BTSAC1PK.js.map +1 -0
- package/dist/neofetch-KcdwHJSJ.js +39 -0
- package/dist/neofetch-KcdwHJSJ.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-zi8L0xNG.js +11 -0
- package/dist/reload-zi8L0xNG.js.map +1 -0
- package/dist/rev-C8qQIyj_.js +11 -0
- package/dist/rev-C8qQIyj_.js.map +1 -0
- package/dist/rm-KQ9gM6fT.js +13 -0
- package/dist/rm-KQ9gM6fT.js.map +1 -0
- package/dist/rmdir-UqUqHZTI.js +12 -0
- package/dist/rmdir-UqUqHZTI.js.map +1 -0
- package/dist/sl-BOyfa7Iu.js +167 -0
- package/dist/sl-BOyfa7Iu.js.map +1 -0
- package/dist/touch-D_kKTiUQ.js +20 -0
- package/dist/touch-D_kKTiUQ.js.map +1 -0
- package/dist/uptime-BYmCcOUM.js +11 -0
- package/dist/uptime-BYmCcOUM.js.map +1 -0
- package/dist/whatis-CYD52uq2.js +14 -0
- package/dist/whatis-CYD52uq2.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
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { ANSI, randomFromArray, randomRange, removeFromArray, Vector2 } from "@prozilla-os/core";
|
|
2
|
-
import { Command } from "../command";
|
|
3
|
-
import { Stream } from "../stream";
|
|
4
|
-
|
|
5
|
-
const ANIMATION_SPEED = 1.25;
|
|
6
|
-
const SCREEN_WIDTH = 75;
|
|
7
|
-
const SCREEN_HEIGHT = 20;
|
|
8
|
-
const CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.*\\/()#@&$!?%°:<>[]";
|
|
9
|
-
|
|
10
|
-
const PARTICLES = {
|
|
11
|
-
framesBetweenSpawn: 30,
|
|
12
|
-
fallSpeed: 1,
|
|
13
|
-
minSize: 5,
|
|
14
|
-
maxSize: 25
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type Particle = {
|
|
18
|
-
position: Vector2,
|
|
19
|
-
size: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function generateScreen(frame: number, screen: string[][], particles: Particle[]): string {
|
|
23
|
-
// Spawn new particles
|
|
24
|
-
if (frame % PARTICLES.framesBetweenSpawn) {
|
|
25
|
-
const newParticle: Particle = {
|
|
26
|
-
position: new Vector2(randomRange(0, SCREEN_WIDTH), SCREEN_HEIGHT).round(),
|
|
27
|
-
size: Math.round(randomRange(PARTICLES.minSize, PARTICLES.maxSize))
|
|
28
|
-
};
|
|
29
|
-
particles.push(newParticle);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Move and render particles
|
|
33
|
-
particles.forEach((particle) => {
|
|
34
|
-
particle.position.y -= PARTICLES.fallSpeed;
|
|
35
|
-
|
|
36
|
-
// Clean previous render
|
|
37
|
-
for (let i = 0; i < PARTICLES.fallSpeed; i++) {
|
|
38
|
-
const positionX = particle.position.x;
|
|
39
|
-
const positionY = particle.position.y + i + particle.size;
|
|
40
|
-
|
|
41
|
-
if (positionY < SCREEN_HEIGHT && positionY >= 0)
|
|
42
|
-
screen[positionY][positionX] = " ";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Remove offscreen particles
|
|
46
|
-
if (particle.position.y + particle.size <= 0 || particle.position.x >= SCREEN_WIDTH)
|
|
47
|
-
return removeFromArray(particle, particles);
|
|
48
|
-
|
|
49
|
-
for (let i = 0; i < particle.size; i++) {
|
|
50
|
-
const character = randomFromArray(CHARACTERS.split(""));
|
|
51
|
-
let color = i == 0 ? ANSI.fg.white : ANSI.fg.green;
|
|
52
|
-
|
|
53
|
-
if (i > particle.size / 2)
|
|
54
|
-
color = ANSI.fg.green + ANSI.decoration.dim;
|
|
55
|
-
|
|
56
|
-
const positionX = particle.position.x;
|
|
57
|
-
const positionY = particle.position.y + i;
|
|
58
|
-
|
|
59
|
-
if (positionX < SCREEN_WIDTH && positionY < SCREEN_HEIGHT && positionY >= 0) {
|
|
60
|
-
screen[positionY][positionX] = color + character + ANSI.reset;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return [...screen.map((row) => row.join(""))].reverse().join("\n");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const cmatrix = new Command()
|
|
69
|
-
.setManual({
|
|
70
|
-
purpose: "Show a scrolling 'Matrix' like screen",
|
|
71
|
-
usage: "cmatrix",
|
|
72
|
-
})
|
|
73
|
-
.setExecute(function() {
|
|
74
|
-
const stream = new Stream();
|
|
75
|
-
const particles: Particle[] = [];
|
|
76
|
-
|
|
77
|
-
// Create screen
|
|
78
|
-
const screen: string[][] = [];
|
|
79
|
-
for (let y = 0; y < SCREEN_HEIGHT; y++) {
|
|
80
|
-
const row: string[] = [];
|
|
81
|
-
for (let x = 0; x < SCREEN_WIDTH; x++) {
|
|
82
|
-
row.push(" ");
|
|
83
|
-
}
|
|
84
|
-
screen.push(row);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let frame = 0;
|
|
88
|
-
const interval = setInterval(() => {
|
|
89
|
-
const text = generateScreen(frame, screen, particles);
|
|
90
|
-
stream.send(text);
|
|
91
|
-
frame++;
|
|
92
|
-
}, 100 / ANIMATION_SPEED);
|
|
93
|
-
|
|
94
|
-
stream.on(Stream.EVENT_NAMES.stop, () => {
|
|
95
|
-
clearInterval(interval);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
stream.start();
|
|
99
|
-
|
|
100
|
-
return stream;
|
|
101
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
import { CommandsManager } from "../commands";
|
|
3
|
-
|
|
4
|
-
export const compgen = new Command()
|
|
5
|
-
.setManual({
|
|
6
|
-
purpose: "Display a list of all commands"
|
|
7
|
-
})
|
|
8
|
-
.setRequireOptions(true)
|
|
9
|
-
.setExecute(function(args, params) {
|
|
10
|
-
const { options } = params as ExecuteParams;
|
|
11
|
-
if (options?.includes("c")) {
|
|
12
|
-
return CommandsManager.COMMANDS.map((command) => command.name).sort().join("\n");
|
|
13
|
-
}
|
|
14
|
-
});
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { MAX_WIDTH } from "../../constants/terminal.const";
|
|
2
|
-
import { Command, ExecuteParams } from "../command";
|
|
3
|
-
|
|
4
|
-
const COW = `
|
|
5
|
-
\\ ^__^
|
|
6
|
-
\\ (oo)\\_______
|
|
7
|
-
(__)\\ )\\/\\
|
|
8
|
-
||----w |
|
|
9
|
-
|| ||`;
|
|
10
|
-
|
|
11
|
-
export const cowsay = new Command()
|
|
12
|
-
.setRequireArgs(true)
|
|
13
|
-
.setManual({
|
|
14
|
-
purpose: "Show a cow saying something",
|
|
15
|
-
usage: "cowsay text",
|
|
16
|
-
description: "Show ASCII art of a cow saying something."
|
|
17
|
-
})
|
|
18
|
-
.setExecute(function(args, params) {
|
|
19
|
-
const { rawInputValue } = params as ExecuteParams;
|
|
20
|
-
|
|
21
|
-
// Separate input value into lines
|
|
22
|
-
const segments = rawInputValue?.split(" ");
|
|
23
|
-
const lines: string[] = [];
|
|
24
|
-
let currentLine = "";
|
|
25
|
-
let maxLineWidth = 0;
|
|
26
|
-
|
|
27
|
-
const addLine = (line: string) => {
|
|
28
|
-
line = line.trimEnd();
|
|
29
|
-
lines.push(line);
|
|
30
|
-
if (line.length > maxLineWidth)
|
|
31
|
-
maxLineWidth = line.length;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const nextLine = (word?: string) => {
|
|
35
|
-
addLine(currentLine);
|
|
36
|
-
|
|
37
|
-
if (word) {
|
|
38
|
-
currentLine = word + " ";
|
|
39
|
-
} else {
|
|
40
|
-
currentLine = "";
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
segments?.forEach((segment) => {
|
|
45
|
-
// Add empty spaces preceding lines
|
|
46
|
-
if (segment === "") {
|
|
47
|
-
currentLine += " ";
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const words = segment.split("\n");
|
|
52
|
-
for (let i = 0; i < words.length; i++) {
|
|
53
|
-
const word = words[i];
|
|
54
|
-
|
|
55
|
-
// Handle next lines
|
|
56
|
-
if (i > 0)
|
|
57
|
-
nextLine();
|
|
58
|
-
|
|
59
|
-
// Fit word on current line
|
|
60
|
-
if ((currentLine + word).length <= MAX_WIDTH) {
|
|
61
|
-
currentLine += word + " ";
|
|
62
|
-
} else if (word.length > MAX_WIDTH) {
|
|
63
|
-
const remainingSpaces = MAX_WIDTH - currentLine.length;
|
|
64
|
-
|
|
65
|
-
if (remainingSpaces >= 2) {
|
|
66
|
-
addLine(currentLine + word.substring(0, remainingSpaces - 1) + "-");
|
|
67
|
-
currentLine = word.substring(remainingSpaces - 1) + " ";
|
|
68
|
-
} else {
|
|
69
|
-
nextLine(word);
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
nextLine(word);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (currentLine.length > 0)
|
|
78
|
-
addLine(currentLine);
|
|
79
|
-
|
|
80
|
-
// Turn lines into speech bubble
|
|
81
|
-
const speechBubble = [` ${"_".repeat(maxLineWidth + 2)} `];
|
|
82
|
-
|
|
83
|
-
for (let i = 0; i < lines.length; i++) {
|
|
84
|
-
let line = lines[i];
|
|
85
|
-
const missingSpaces = maxLineWidth - line.length;
|
|
86
|
-
|
|
87
|
-
if (missingSpaces > 0)
|
|
88
|
-
line += " ".repeat(missingSpaces);
|
|
89
|
-
|
|
90
|
-
if (lines.length > 1) {
|
|
91
|
-
if (i === 0) {
|
|
92
|
-
line = `/ ${line} \\`;
|
|
93
|
-
} else if (i === lines.length - 1) {
|
|
94
|
-
line = `\\ ${line} /`;
|
|
95
|
-
} else {
|
|
96
|
-
line = `| ${line} |`;
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
line = `< ${line} >`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
speechBubble.push(line);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
speechBubble.push(` ${"-".repeat(maxLineWidth + 2)} `);
|
|
106
|
-
|
|
107
|
-
return speechBubble.join("\n") + COW;
|
|
108
|
-
});
|
package/src/core/commands/dir.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
|
|
3
|
-
export const dir = new Command()
|
|
4
|
-
.setManual({
|
|
5
|
-
purpose: "List all directories in the current directory"
|
|
6
|
-
})
|
|
7
|
-
.setExecute(function(args, params) {
|
|
8
|
-
const { currentDirectory } = params as ExecuteParams;
|
|
9
|
-
const folderNames = currentDirectory.subFolders.map((folder) => folder.id);
|
|
10
|
-
|
|
11
|
-
if (folderNames.length === 0)
|
|
12
|
-
return { blank: true };
|
|
13
|
-
|
|
14
|
-
return folderNames.sort((nameA, nameB) => nameA.localeCompare(nameB)).join(" ");
|
|
15
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
|
|
3
|
-
export const echo = new Command()
|
|
4
|
-
.setManual({
|
|
5
|
-
purpose: "Display text on the terminal screen"
|
|
6
|
-
})
|
|
7
|
-
.setExecute(function(args, params) {
|
|
8
|
-
const { rawInputValue } = params as ExecuteParams;
|
|
9
|
-
return rawInputValue;
|
|
10
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
|
|
3
|
-
export const exit = new Command()
|
|
4
|
-
.setManual({
|
|
5
|
-
purpose: "Quit terminal interface"
|
|
6
|
-
})
|
|
7
|
-
.setExecute(function(args, params) {
|
|
8
|
-
const { exit } = params as ExecuteParams;
|
|
9
|
-
exit?.();
|
|
10
|
-
return { blank: true };
|
|
11
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { randomFromArray } from "@prozilla-os/core";
|
|
2
|
-
import { Command } from "../command";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Source: https://github.com/shlomif/fortune-mod/blob/master/fortune-mod/datfiles/fortunes
|
|
6
|
-
*/
|
|
7
|
-
const FORTUNES = [
|
|
8
|
-
"Do not be afraid of competition.",
|
|
9
|
-
"An exciting opportunity lies ahead of you.",
|
|
10
|
-
"You love peace.",
|
|
11
|
-
"Get your mind set... confidence will lead you on.",
|
|
12
|
-
"You will always be surrounded by true friends.",
|
|
13
|
-
"Sell your ideas-they have exceptional merit.",
|
|
14
|
-
"You should be able to undertake and complete anything.",
|
|
15
|
-
"You are kind and friendly.",
|
|
16
|
-
"You are wise beyond your years.",
|
|
17
|
-
"Your ability to juggle many tasks will take you far.",
|
|
18
|
-
"A routine task will turn into an enchanting adventure.",
|
|
19
|
-
"Beware of all enterprises that require new clothes.",
|
|
20
|
-
"Be true to your work, your word, and your friend.",
|
|
21
|
-
"Goodness is the only investment that never fails.",
|
|
22
|
-
"A journey of a thousand miles begins with a single step.",
|
|
23
|
-
"Forget injuries; never forget kindnesses.",
|
|
24
|
-
"Respect yourself and others will respect you.",
|
|
25
|
-
"A man cannot be comfortable without his own approval.",
|
|
26
|
-
"Always do right. This will gratify some people and astonish the rest.",
|
|
27
|
-
"It is easier to stay out than to get out.",
|
|
28
|
-
"Sing everyday and chase the mean blues away.",
|
|
29
|
-
"You will receive money from an unexpected source.",
|
|
30
|
-
"Attitude is a little thing that makes a big difference.",
|
|
31
|
-
"Plan for many pleasures ahead.",
|
|
32
|
-
"Experience is the best teacher.",
|
|
33
|
-
"You will be happy with your spouse.",
|
|
34
|
-
"Expect the unexpected.",
|
|
35
|
-
"Stay healthy. Walk a mile.",
|
|
36
|
-
"The family that plays together stays together.",
|
|
37
|
-
"Eat chocolate to have a sweeter life.",
|
|
38
|
-
"Once you make a decision the universe conspires to make it happen.",
|
|
39
|
-
"Make yourself necessary to someone.",
|
|
40
|
-
"The only way to have a friend is to be one.",
|
|
41
|
-
"Nothing great was ever achieved without enthusiasm.",
|
|
42
|
-
"Dance as if no one is watching.",
|
|
43
|
-
"Live this day as if it were your last.",
|
|
44
|
-
"Your life will be happy and peaceful.",
|
|
45
|
-
"Reach for joy and all else will follow.",
|
|
46
|
-
"Move in the direction of your dreams.",
|
|
47
|
-
"Bloom where you are planted.",
|
|
48
|
-
"Appreciate. Appreciate. Appreciate.",
|
|
49
|
-
"Happy News is on its way.",
|
|
50
|
-
"A closed mouth gathers no feet.",
|
|
51
|
-
"He who throws dirt is losing ground.",
|
|
52
|
-
"Borrow money from a pessimist. They don't expect it back.",
|
|
53
|
-
"Life is what happens to you while you are busy making other plans.",
|
|
54
|
-
"Help! I'm being held prisoner in a fortune cookie factory.",
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
export const fortune = new Command()
|
|
58
|
-
.setManual({
|
|
59
|
-
purpose: "Tell fortune"
|
|
60
|
-
})
|
|
61
|
-
.setExecute(function() {
|
|
62
|
-
return randomFromArray(FORTUNES);
|
|
63
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ANSI } from "@prozilla-os/core";
|
|
2
|
-
import { formatError } from "../_utils/terminal.utils";
|
|
3
|
-
import { Command } from "../command";
|
|
4
|
-
import { CommandsManager } from "../commands";
|
|
5
|
-
|
|
6
|
-
export const help = new Command()
|
|
7
|
-
.setExecute(function(this: Command, args) {
|
|
8
|
-
if (args?.length === 0) {
|
|
9
|
-
return CommandsManager.COMMANDS.map((command) => {
|
|
10
|
-
if (command.manual?.purpose) {
|
|
11
|
-
return `${command.name} - ${ANSI.fg.green}${ANSI.decoration.dim}${command.manual.purpose}${ANSI.reset}`;
|
|
12
|
-
} else {
|
|
13
|
-
return command.name;
|
|
14
|
-
}
|
|
15
|
-
}).sort().join("\n");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const commandName = (args as string[])[0].toLowerCase();
|
|
19
|
-
const command = CommandsManager.find(commandName);
|
|
20
|
-
|
|
21
|
-
if (!command)
|
|
22
|
-
return formatError(this.name, `${commandName}: Command not found`);
|
|
23
|
-
|
|
24
|
-
if (!command.manual?.purpose)
|
|
25
|
-
return formatError(this.name, `${commandName}: No manual found`);
|
|
26
|
-
|
|
27
|
-
return command.manual.purpose;
|
|
28
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
|
|
3
|
-
export const hostname = new Command()
|
|
4
|
-
.setManual({
|
|
5
|
-
purpose: "Display the hostname"
|
|
6
|
-
})
|
|
7
|
-
.setExecute(function(args, params) {
|
|
8
|
-
const { hostname } = params as ExecuteParams;
|
|
9
|
-
return hostname;
|
|
10
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { ANSI } from "@prozilla-os/core";
|
|
2
|
-
import { removeAnsi } from "../_utils/terminal.utils";
|
|
3
|
-
import { Command, ExecuteParams } from "../command";
|
|
4
|
-
|
|
5
|
-
const COLUMN_WIDTH = 5;
|
|
6
|
-
const ROW_OFFSET = 2;
|
|
7
|
-
|
|
8
|
-
const RAINBOW = [
|
|
9
|
-
ANSI.fg.red,
|
|
10
|
-
ANSI.fg.yellow,
|
|
11
|
-
ANSI.fg.green,
|
|
12
|
-
ANSI.fg.cyan,
|
|
13
|
-
ANSI.fg.blue,
|
|
14
|
-
ANSI.fg.magenta,
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
export const lolcat = new Command()
|
|
18
|
-
.setManual({
|
|
19
|
-
purpose: "Display text with a rainbow effect"
|
|
20
|
-
})
|
|
21
|
-
.setExecute(function(args, params) {
|
|
22
|
-
const { rawInputValue, timestamp } = params as ExecuteParams;
|
|
23
|
-
if (rawInputValue == null) return;
|
|
24
|
-
let rows = removeAnsi(rawInputValue).split("\n");
|
|
25
|
-
const offset = timestamp / 100;
|
|
26
|
-
|
|
27
|
-
rows = rows.map((row, index) => {
|
|
28
|
-
const columns: string[] = [];
|
|
29
|
-
|
|
30
|
-
const rowIndex = index + offset;
|
|
31
|
-
const rowOffset = COLUMN_WIDTH - ((ROW_OFFSET * rowIndex) % COLUMN_WIDTH);
|
|
32
|
-
let rainbowIndex = Math.floor(rowIndex / (COLUMN_WIDTH / ROW_OFFSET));
|
|
33
|
-
|
|
34
|
-
const addColumn = (start: number, end: number) => {
|
|
35
|
-
const column = row.substring(start, end);
|
|
36
|
-
const color = RAINBOW[rainbowIndex++ % RAINBOW.length];
|
|
37
|
-
columns.push(color + column);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (rowOffset > 0)
|
|
41
|
-
addColumn(0, rowOffset);
|
|
42
|
-
|
|
43
|
-
for (let i = rowOffset; i < row.length; i += COLUMN_WIDTH + 1) {
|
|
44
|
-
addColumn(i, i + COLUMN_WIDTH + 1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (row.length === 0)
|
|
48
|
-
return "";
|
|
49
|
-
|
|
50
|
-
return columns.join("");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return rows.join("\n");
|
|
54
|
-
});
|
package/src/core/commands/ls.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ANSI, VirtualFolder } from "@prozilla-os/core";
|
|
2
|
-
import { formatError } from "../_utils/terminal.utils";
|
|
3
|
-
import { Command, ExecuteParams } from "../command";
|
|
4
|
-
|
|
5
|
-
export const ls = new Command()
|
|
6
|
-
.setManual({
|
|
7
|
-
purpose: "List directory contents",
|
|
8
|
-
usage: "ls [options] [files]",
|
|
9
|
-
description: "List information about directories or files (the current directory by default)."
|
|
10
|
-
})
|
|
11
|
-
.setExecute(function(this: Command, args, params) {
|
|
12
|
-
const { currentDirectory } = params as ExecuteParams;
|
|
13
|
-
let directory = currentDirectory;
|
|
14
|
-
|
|
15
|
-
if (args != null && args.length > 0) {
|
|
16
|
-
directory = currentDirectory.navigate((args)[0]) as VirtualFolder;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!directory)
|
|
20
|
-
return formatError(this.name, `Cannot access '${(args as string[])[0]}': No such file or directory`);
|
|
21
|
-
|
|
22
|
-
const folderNames = directory.subFolders.map((folder) => `${ANSI.fg.blue}${folder.id}${ANSI.reset}`);
|
|
23
|
-
const fileNames = directory.files.map((file) => file.id);
|
|
24
|
-
|
|
25
|
-
const contents = folderNames.concat(fileNames);
|
|
26
|
-
|
|
27
|
-
if (contents.length === 0)
|
|
28
|
-
return { blank: true };
|
|
29
|
-
|
|
30
|
-
return contents.sort().join(" ");
|
|
31
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { formatError } from "../_utils/terminal.utils";
|
|
2
|
-
import { Command } from "../command";
|
|
3
|
-
|
|
4
|
-
export const make = new Command()
|
|
5
|
-
.setRequireArgs(true)
|
|
6
|
-
.setExecute(function(this: Command, args) {
|
|
7
|
-
if ((args as string[])[0] === "love")
|
|
8
|
-
return formatError(this.name, "*** No rule to make target 'love'. Stop.");
|
|
9
|
-
});
|
package/src/core/commands/man.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { ANSI } from "@prozilla-os/core";
|
|
2
|
-
import { formatError } from "../_utils/terminal.utils";
|
|
3
|
-
import { Command, ExecuteParams } from "../command";
|
|
4
|
-
import { CommandsManager } from "../commands";
|
|
5
|
-
|
|
6
|
-
const MARGIN = 5;
|
|
7
|
-
|
|
8
|
-
export const man = new Command()
|
|
9
|
-
.setRequireArgs(true)
|
|
10
|
-
.setManual({
|
|
11
|
-
purpose: "Show system reference manuals",
|
|
12
|
-
usage: "man [options] page\n"
|
|
13
|
-
+ "man -k [options] regexp",
|
|
14
|
-
description: "Each page arguments given to man is normally the name of a command.\n"
|
|
15
|
-
+ "The manual page associated with this command is then found and displayed.",
|
|
16
|
-
options: {
|
|
17
|
-
"-k": "Search for manual page using regexp"
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
.setExecute(function(this: Command, args, params) {
|
|
21
|
-
const { options } = params as ExecuteParams;
|
|
22
|
-
|
|
23
|
-
// Search function
|
|
24
|
-
if (options?.includes("k")) {
|
|
25
|
-
const commands = CommandsManager.search((args as string[])[0].toLowerCase());
|
|
26
|
-
return commands.map((command) => {
|
|
27
|
-
if (command.manual?.purpose) {
|
|
28
|
-
return `${command.name} - ${command.manual.purpose}`;
|
|
29
|
-
} else {
|
|
30
|
-
return command.name;
|
|
31
|
-
}
|
|
32
|
-
}).sort().join("\n");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const commandName = (args as string[])[0].toLowerCase();
|
|
36
|
-
const command = CommandsManager.find(commandName);
|
|
37
|
-
|
|
38
|
-
if (!command)
|
|
39
|
-
return formatError(this.name, `${commandName}: Command not found`);
|
|
40
|
-
|
|
41
|
-
const manual = command.manual;
|
|
42
|
-
|
|
43
|
-
if (!manual)
|
|
44
|
-
return formatError(this.name, `${commandName}: No manual found`);
|
|
45
|
-
|
|
46
|
-
const formatText = (text: string) => {
|
|
47
|
-
const lines = text.split("\n").map((line) => " ".repeat(MARGIN) + line);
|
|
48
|
-
return lines.join("\n");
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const sections = [["NAME"]];
|
|
52
|
-
|
|
53
|
-
if (manual.purpose) {
|
|
54
|
-
sections[0].push(formatText(`${commandName} - ${ANSI.decoration.dim}${ANSI.fg.yellow}${manual.purpose}${ANSI.reset}`));
|
|
55
|
-
} else {
|
|
56
|
-
sections[0].push(formatText(commandName));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (manual.usage) {
|
|
60
|
-
sections.push([
|
|
61
|
-
"SYNOPSIS",
|
|
62
|
-
formatText(manual.usage)
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (manual.description) {
|
|
67
|
-
sections.push([
|
|
68
|
-
"DESCRIPTION",
|
|
69
|
-
formatText(manual.description)
|
|
70
|
-
]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (manual.options) {
|
|
74
|
-
sections.push([
|
|
75
|
-
"OPTIONS",
|
|
76
|
-
formatText(Object.entries(manual.options).map(([key, value]) => {
|
|
77
|
-
return `${key} ${ANSI.decoration.dim}${ANSI.fg.yellow}${value}${ANSI.reset}`;
|
|
78
|
-
}).join("\n"))
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return sections.map((section) => {
|
|
83
|
-
section[0] = ANSI.fg.yellow + section[0] + ANSI.reset;
|
|
84
|
-
return section.join("\n");
|
|
85
|
-
}).join("\n\n");
|
|
86
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
|
|
3
|
-
export const mkdir = new Command()
|
|
4
|
-
.setManual({
|
|
5
|
-
purpose: "Create a directory"
|
|
6
|
-
})
|
|
7
|
-
.setRequireArgs(true)
|
|
8
|
-
.setExecute(function(args, params) {
|
|
9
|
-
const { currentDirectory } = params as ExecuteParams;
|
|
10
|
-
const name = (args as string[])[0];
|
|
11
|
-
|
|
12
|
-
if (currentDirectory.findSubFolder(name))
|
|
13
|
-
return { blank: true };
|
|
14
|
-
|
|
15
|
-
currentDirectory.createFolder(name);
|
|
16
|
-
return { blank: true };
|
|
17
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ANSI, SettingsManager, THEMES } from "@prozilla-os/core";
|
|
2
|
-
import { ANSI_ASCII_LOGO, ANSI_LOGO_COLOR } from "../../constants/terminal.const";
|
|
3
|
-
import { Command, ExecuteParams } from "../command";
|
|
4
|
-
|
|
5
|
-
export const neofetch = new Command()
|
|
6
|
-
.setManual({
|
|
7
|
-
purpose: "Fetch system information"
|
|
8
|
-
})
|
|
9
|
-
.setExecute(async function(args, params) {
|
|
10
|
-
const { username, hostname, app, systemManager, settingsManager } = params as ExecuteParams;
|
|
11
|
-
const leftColumn = ANSI_ASCII_LOGO.split("\n");
|
|
12
|
-
const rightColumnWidth = (username?.length ?? 0) + (hostname?.length ?? 0) + 1;
|
|
13
|
-
|
|
14
|
-
const themeIndex = await settingsManager.getSettings(SettingsManager.VIRTUAL_PATHS.theme).get("theme");
|
|
15
|
-
let theme = THEMES[0] as string;
|
|
16
|
-
if (themeIndex != null && parseInt(themeIndex)) {
|
|
17
|
-
theme = THEMES[(themeIndex as unknown as number) ?? 0] as string ?? THEMES[0];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const userAgent = navigator.userAgent;
|
|
21
|
-
|
|
22
|
-
// Check for the browser name using regular expressions
|
|
23
|
-
let browserName: string;
|
|
24
|
-
if (userAgent.match(/Firefox\//)) {
|
|
25
|
-
browserName = "Mozilla Firefox";
|
|
26
|
-
} else if (userAgent.match(/Edg\//)) {
|
|
27
|
-
browserName = "Microsoft Edge";
|
|
28
|
-
} else if (userAgent.match(/Chrome\//)) {
|
|
29
|
-
browserName = "Google Chrome";
|
|
30
|
-
} else if (userAgent.match(/Safari\//)) {
|
|
31
|
-
browserName = "Apple Safari";
|
|
32
|
-
} else {
|
|
33
|
-
browserName = "Unknown";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const formatLine = (label: string, text: string) => ANSI.fg.cyan + label.toUpperCase() + ANSI.reset + ": " + text;
|
|
37
|
-
|
|
38
|
-
const rightColumn = [
|
|
39
|
-
`${ANSI.fg.cyan + username + ANSI.reset}@${ANSI.fg.cyan + hostname + ANSI.reset}`,
|
|
40
|
-
"-".repeat(rightColumnWidth),
|
|
41
|
-
formatLine("os", systemManager.systemName),
|
|
42
|
-
formatLine("uptime", systemManager.getUptime(2)),
|
|
43
|
-
formatLine("resolution", window.innerWidth + "x" + window.innerHeight),
|
|
44
|
-
formatLine("theme", theme),
|
|
45
|
-
formatLine("icons", "Font Awesome"),
|
|
46
|
-
formatLine("terminal", app?.name ?? "Unknown"),
|
|
47
|
-
formatLine("browser", browserName),
|
|
48
|
-
formatLine("platform", navigator.platform),
|
|
49
|
-
formatLine("language", navigator.language),
|
|
50
|
-
"",
|
|
51
|
-
Object.values(ANSI.fg).map((colorCode) => colorCode + "███").join("") + ANSI.reset,
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
const combined = [];
|
|
55
|
-
for (let i = 1; i < leftColumn.length; i++) {
|
|
56
|
-
let line = `${ANSI_LOGO_COLOR + leftColumn[i] + ANSI.reset} `;
|
|
57
|
-
|
|
58
|
-
if (i <= rightColumn.length) {
|
|
59
|
-
line += rightColumn[i - 1];
|
|
60
|
-
} else {
|
|
61
|
-
// This fixes a weird display bug on Safari mobile
|
|
62
|
-
line += " ".repeat(rightColumnWidth);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
combined.push(line);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return combined.join("\n");
|
|
69
|
-
});
|
package/src/core/commands/pwd.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Command, ExecuteParams } from "../command";
|
|
2
|
-
|
|
3
|
-
export const pwd = new Command()
|
|
4
|
-
.setManual({
|
|
5
|
-
purpose: "Display path of the current directory"
|
|
6
|
-
})
|
|
7
|
-
.setExecute(function(args, params) {
|
|
8
|
-
const { currentDirectory } = params as ExecuteParams;
|
|
9
|
-
|
|
10
|
-
if (currentDirectory.root) {
|
|
11
|
-
return "/";
|
|
12
|
-
} else {
|
|
13
|
-
return currentDirectory.absolutePath;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { reloadViewport } from "@prozilla-os/core";
|
|
2
|
-
import { Command } from "../command";
|
|
3
|
-
|
|
4
|
-
export const reboot = new Command()
|
|
5
|
-
.setManual({
|
|
6
|
-
purpose: "Reboot the system"
|
|
7
|
-
})
|
|
8
|
-
.setExecute(function() {
|
|
9
|
-
reloadViewport();
|
|
10
|
-
return { blank: true };
|
|
11
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Command } from "../command";
|
|
2
|
-
import { CommandsManager } from "../commands";
|
|
3
|
-
|
|
4
|
-
export const reload = new Command()
|
|
5
|
-
.setManual({
|
|
6
|
-
purpose: "Reload the terminal",
|
|
7
|
-
})
|
|
8
|
-
.setExecute(function() {
|
|
9
|
-
CommandsManager.reload();
|
|
10
|
-
return { blank: true };
|
|
11
|
-
});
|