UI: LogBox overhaul (#508)

This commit is contained in:
David Walker
2023-05-26 05:07:37 -07:00
committed by GitHub
parent 113af6e711
commit 4503da6226
26 changed files with 431 additions and 114 deletions
+21 -2
View File
@@ -17,6 +17,8 @@ import { getKeyList } from "../utils/helpers/getKeyList";
import { ScriptFilePath } from "../Paths/ScriptFilePath";
import { ScriptKey, scriptKey } from "../utils/helpers/scriptKey";
import type { LogBoxProperties } from "../ui/React/LogBoxManager";
export class RunningScript {
// Script arguments
args: ScriptArg[] = [];
@@ -65,6 +67,14 @@ export class RunningScript {
// Cached key for ByArgs lookups. Will be overwritten by a correct ScriptKey in fromJSON or constructor
scriptKey = "" as ScriptKey;
// Access to properties of the tail window. Can be used to get/set size, position, etc.
tailProps = null as LogBoxProperties | null;
// The title, as shown in the script's log box. Defaults to the name + args,
// but can be changed by the user. If it is set to a React element (only by the user),
// that will not be persisted, and will be restored to default on load.
title = "" as string | React.ReactElement;
// Number of threads that this script is running with
threads = 1 as PositiveInteger;
@@ -83,6 +93,7 @@ export class RunningScript {
this.server = script.server;
this.ramUsage = ramUsage;
this.dependencies = script.dependencies;
this.title = `${this.filename} ${args.join(" ")}`;
}
log(txt: React.ReactNode): void {
@@ -140,7 +151,12 @@ export class RunningScript {
// Serialize the current object to a JSON save state
toJSON(): IReviverValue {
return Generic_toJSON("RunningScript", this, includedProperties);
// Omit the title if it's a ReactNode, it will be filled in with the default on load.
return Generic_toJSON(
"RunningScript",
this,
typeof this.title === "string" ? includedProperties : includedPropsNoTitle,
);
}
// Initializes a RunningScript Object from a JSON save state
@@ -150,6 +166,9 @@ export class RunningScript {
return runningScript;
}
}
const includedProperties = getKeyList(RunningScript, { removedKeys: ["logs", "dependencies", "logUpd", "pid"] });
const includedProperties = getKeyList(RunningScript, {
removedKeys: ["logs", "dependencies", "logUpd", "pid", "tailProps"],
});
const includedPropsNoTitle = includedProperties.filter((x) => x !== "title");
constructorsForReviver.RunningScript = RunningScript;