2023-06-26 10:24:37 +02:00
|
|
|
import React from "react";
|
|
|
|
import { Theme } from "@mui/material/styles";
|
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
import type { TextFilePath } from "../../Paths/TextFilePath";
|
|
|
|
import type { ContractFilePath } from "../../Paths/ContractFilePath";
|
|
|
|
import type { ProgramFilePath } from "../../Paths/ProgramFilePath";
|
|
|
|
import type { ContentFilePath } from "../../Paths/ContentFile";
|
|
|
|
import type { ScriptFilePath } from "../../Paths/ScriptFilePath";
|
|
|
|
|
2022-01-11 04:40:01 +01:00
|
|
|
import createStyles from "@mui/styles/createStyles";
|
|
|
|
import makeStyles from "@mui/styles/makeStyles";
|
2021-09-16 01:50:44 +02:00
|
|
|
import { BaseServer } from "../../Server/BaseServer";
|
2022-09-06 15:07:12 +02:00
|
|
|
import { Router } from "../../ui/GameRoot";
|
2023-06-26 10:24:37 +02:00
|
|
|
import { Page } from "../../ui/Router";
|
2022-09-06 15:07:12 +02:00
|
|
|
import { Terminal } from "../../Terminal";
|
2022-07-20 03:53:43 +02:00
|
|
|
import libarg from "arg";
|
2022-04-14 16:23:45 +02:00
|
|
|
import { showLiterature } from "../../Literature/LiteratureHelpers";
|
2023-06-12 06:34:20 +02:00
|
|
|
import { showMessage } from "../../Message/MessageHelpers";
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
import { FilePath, combinePath, removeDirectoryFromPath } from "../../Paths/FilePath";
|
|
|
|
import {
|
|
|
|
Directory,
|
|
|
|
directoryExistsOnServer,
|
|
|
|
getFirstDirectoryInPath,
|
|
|
|
resolveDirectory,
|
|
|
|
root,
|
|
|
|
} from "../../Paths/Directory";
|
2023-06-12 06:34:20 +02:00
|
|
|
import { isMember } from "../../utils/EnumHelper";
|
2021-09-16 01:50:44 +02:00
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
export function ls(args: (string | number | boolean)[], server: BaseServer): void {
|
2022-07-20 03:53:43 +02:00
|
|
|
interface LSFlags {
|
|
|
|
["-l"]: boolean;
|
|
|
|
["--grep"]: string;
|
|
|
|
}
|
|
|
|
let flags: LSFlags;
|
2022-02-05 16:27:08 +01:00
|
|
|
try {
|
2022-04-07 01:30:08 +02:00
|
|
|
flags = libarg(
|
|
|
|
{
|
|
|
|
"-l": Boolean,
|
|
|
|
"--grep": String,
|
|
|
|
"-g": "--grep",
|
|
|
|
},
|
|
|
|
{ argv: args },
|
|
|
|
);
|
2022-02-05 16:27:08 +01:00
|
|
|
} catch (e) {
|
|
|
|
// catch passing only -g / --grep with no string to use as the search
|
2022-04-07 01:30:08 +02:00
|
|
|
incorrectUsage();
|
2022-02-05 16:27:08 +01:00
|
|
|
return;
|
|
|
|
}
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
const filter = flags["--grep"] ?? "";
|
2022-02-05 16:27:08 +01:00
|
|
|
|
2021-09-16 01:50:44 +02:00
|
|
|
const numArgs = args.length;
|
|
|
|
function incorrectUsage(): void {
|
2022-09-06 15:07:12 +02:00
|
|
|
Terminal.error("Incorrect usage of ls command. Usage: ls [dir] [-l] [-g, --grep pattern]");
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
|
2022-02-05 17:05:48 +01:00
|
|
|
if (numArgs > 4) {
|
2021-09-16 01:50:44 +02:00
|
|
|
return incorrectUsage();
|
|
|
|
}
|
|
|
|
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
let baseDirectory = Terminal.currDir;
|
|
|
|
// Parse first argument which should be a directory.
|
|
|
|
if (args[0] && typeof args[0] == "string" && !args[0].startsWith("-")) {
|
|
|
|
const directory = resolveDirectory(args[0], args[0].startsWith("/") ? root : Terminal.currDir);
|
|
|
|
if (directory !== null && directoryExistsOnServer(directory, server)) {
|
|
|
|
baseDirectory = directory;
|
|
|
|
} else return incorrectUsage();
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display all programs and scripts
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
const allPrograms: ProgramFilePath[] = [];
|
|
|
|
const allScripts: ScriptFilePath[] = [];
|
|
|
|
const allTextFiles: TextFilePath[] = [];
|
|
|
|
const allContracts: ContractFilePath[] = [];
|
|
|
|
const allMessages: FilePath[] = [];
|
|
|
|
const folders: Directory[] = [];
|
2021-09-16 01:50:44 +02:00
|
|
|
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
function handlePath(path: FilePath, dest: FilePath[]): void {
|
|
|
|
// This parses out any files not in the starting directory.
|
|
|
|
const parsedPath = removeDirectoryFromPath(baseDirectory, path);
|
|
|
|
if (!parsedPath) return;
|
2021-09-16 01:50:44 +02:00
|
|
|
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
if (!parsedPath.includes(filter)) return;
|
2021-09-16 01:50:44 +02:00
|
|
|
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
// Check if there's a directory in the parsed path, if so we need to add the folder and not the file.
|
|
|
|
const firstParentDir = getFirstDirectoryInPath(parsedPath);
|
|
|
|
if (firstParentDir) {
|
|
|
|
if (!firstParentDir.includes(filter) || folders.includes(firstParentDir)) return;
|
|
|
|
folders.push(firstParentDir);
|
2021-09-16 01:50:44 +02:00
|
|
|
return;
|
|
|
|
}
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
dest.push(parsedPath);
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get all of the programs and scripts on the machine into one temporary array
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
// Type assertions that programs and msg/lit are filepaths are safe due to checks in
|
|
|
|
// Program, Message, and Literature constructors
|
|
|
|
for (const program of server.programs) handlePath(program as FilePath, allPrograms);
|
|
|
|
for (const scriptFilename of server.scripts.keys()) handlePath(scriptFilename, allScripts);
|
|
|
|
for (const txtFilename of server.textFiles.keys()) handlePath(txtFilename, allTextFiles);
|
|
|
|
for (const contract of server.contracts) handlePath(contract.fn, allContracts);
|
|
|
|
for (const msgOrLit of server.messages) handlePath(msgOrLit as FilePath, allMessages);
|
2021-09-16 01:50:44 +02:00
|
|
|
|
|
|
|
// Sort the files/folders alphabetically then print each
|
|
|
|
allPrograms.sort();
|
|
|
|
allScripts.sort();
|
|
|
|
allTextFiles.sort();
|
|
|
|
allContracts.sort();
|
|
|
|
allMessages.sort();
|
|
|
|
folders.sort();
|
|
|
|
|
2023-04-26 21:18:26 +02:00
|
|
|
function SegmentGrid(props: { colSize: string; children: React.ReactChild[] }): React.ReactElement {
|
|
|
|
const classes = makeStyles({
|
|
|
|
segmentGrid: {
|
|
|
|
display: "grid",
|
|
|
|
gridTemplateColumns: "repeat(auto-fill, var(--colSize))",
|
|
|
|
},
|
|
|
|
})();
|
|
|
|
const style = { ["--colSize"]: props.colSize } as React.CSSProperties;
|
|
|
|
return (
|
|
|
|
<span style={style} className={classes.segmentGrid}>
|
|
|
|
{props.children}
|
|
|
|
</span>
|
|
|
|
);
|
2022-01-11 04:40:01 +01:00
|
|
|
}
|
2023-04-26 21:18:26 +02:00
|
|
|
function ClickableScriptLink(props: { path: ScriptFilePath }): React.ReactElement {
|
2022-01-11 04:40:01 +01:00
|
|
|
const classes = makeStyles((theme: Theme) =>
|
|
|
|
createStyles({
|
2023-04-26 21:18:26 +02:00
|
|
|
link: {
|
2022-01-11 04:40:01 +01:00
|
|
|
cursor: "pointer",
|
|
|
|
textDecorationLine: "underline",
|
2023-04-26 21:18:26 +02:00
|
|
|
color: theme.palette.warning.main,
|
2022-01-11 04:40:01 +01:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
)();
|
2023-04-26 21:18:26 +02:00
|
|
|
const fullPath = combinePath(baseDirectory, props.path);
|
|
|
|
function onClick() {
|
2023-05-26 18:09:44 +02:00
|
|
|
const code = server.scripts.get(fullPath)?.content ?? "";
|
2023-06-26 10:24:37 +02:00
|
|
|
const files = new Map<ContentFilePath, string>();
|
|
|
|
files.set(fullPath, code);
|
|
|
|
Router.toPage(Page.ScriptEditor, { files });
|
2022-01-11 04:40:01 +01:00
|
|
|
}
|
|
|
|
return (
|
2023-04-26 21:18:26 +02:00
|
|
|
<span>
|
|
|
|
<span className={classes.link} onClick={onClick}>
|
|
|
|
{props.path}
|
|
|
|
</span>
|
2022-01-11 04:40:01 +01:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-04-26 21:18:26 +02:00
|
|
|
function ClickableMessageLink(props: { path: FilePath }): React.ReactElement {
|
|
|
|
const classes = makeStyles({
|
|
|
|
link: {
|
|
|
|
cursor: "pointer",
|
|
|
|
textDecorationLine: "underline",
|
|
|
|
},
|
|
|
|
})();
|
|
|
|
function onClick(): void {
|
2022-09-06 15:07:12 +02:00
|
|
|
if (!server.isConnectedTo) {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
return Terminal.error(`File is not on this server, connect to ${server.hostname} and try again`);
|
2023-03-23 17:01:58 +01:00
|
|
|
}
|
2023-04-26 21:18:26 +02:00
|
|
|
// Message and lit files are always in root, no need to combine path with base directory
|
2023-06-12 06:34:20 +02:00
|
|
|
if (isMember("MessageFilename", props.path)) {
|
2023-04-26 21:18:26 +02:00
|
|
|
showMessage(props.path);
|
2023-06-12 06:34:20 +02:00
|
|
|
} else if (isMember("LiteratureName", props.path)) {
|
2023-04-26 21:18:26 +02:00
|
|
|
showLiterature(props.path);
|
2022-04-14 16:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (
|
2023-04-26 21:18:26 +02:00
|
|
|
<span>
|
|
|
|
<span className={classes.link} onClick={onClick}>
|
|
|
|
{props.path}
|
|
|
|
</span>
|
2022-04-14 16:23:45 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum FileType {
|
|
|
|
Folder,
|
|
|
|
Message,
|
|
|
|
TextFile,
|
|
|
|
Program,
|
|
|
|
Contract,
|
|
|
|
Script,
|
|
|
|
}
|
|
|
|
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
type FileGroup =
|
|
|
|
| {
|
|
|
|
// Types that are not clickable only need to be string[]
|
|
|
|
type: FileType.Folder | FileType.Program | FileType.Contract | FileType.TextFile;
|
|
|
|
segments: string[];
|
|
|
|
}
|
|
|
|
| { type: FileType.Message; segments: FilePath[] }
|
|
|
|
| { type: FileType.Script; segments: ScriptFilePath[] };
|
2022-04-14 16:23:45 +02:00
|
|
|
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
function postSegments({ type, segments }: FileGroup, flags: LSFlags): void {
|
2023-04-26 21:18:26 +02:00
|
|
|
let segmentElements: React.ReactElement[];
|
|
|
|
const colSize = flags["-l"]
|
|
|
|
? "100%"
|
|
|
|
: Math.ceil(Math.max(...segments.map((segment) => segment.length)) * 0.7) + "em";
|
|
|
|
switch (type) {
|
|
|
|
case FileType.Folder:
|
|
|
|
segmentElements = segments.map((segment) => (
|
|
|
|
<span key={segment} style={{ color: "cyan" }}>
|
|
|
|
{segment}
|
|
|
|
</span>
|
|
|
|
));
|
|
|
|
break;
|
|
|
|
case FileType.Message:
|
|
|
|
segmentElements = segments.map((segment) => <ClickableMessageLink key={segment} path={segment} />);
|
|
|
|
break;
|
|
|
|
case FileType.Script:
|
|
|
|
segmentElements = segments.map((segment) => <ClickableScriptLink key={segment} path={segment} />);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
segmentElements = segments.map((segment) => <span key={segment}>{segment}</span>);
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
2023-04-26 21:18:26 +02:00
|
|
|
Terminal.printRaw(<SegmentGrid colSize={colSize}>{segmentElements}</SegmentGrid>);
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
|
2022-04-14 16:23:45 +02:00
|
|
|
const groups: FileGroup[] = [
|
|
|
|
{ type: FileType.Folder, segments: folders },
|
|
|
|
{ type: FileType.Message, segments: allMessages },
|
|
|
|
{ type: FileType.TextFile, segments: allTextFiles },
|
|
|
|
{ type: FileType.Program, segments: allPrograms },
|
|
|
|
{ type: FileType.Contract, segments: allContracts },
|
|
|
|
{ type: FileType.Script, segments: allScripts },
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
];
|
2022-04-14 16:23:45 +02:00
|
|
|
for (const group of groups) {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
if (group.segments.length > 0) postSegments(group, flags);
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|
|
|
|
}
|