NETSCRIPT: Add undocumented function printRaw() (#277)

This is analagous to tprintRaw (enabled by ns.iKnowWhatImDoing()), but
for logs instead of the terminal. This provides a supported* method of
creating complicated UIs for scripts.

*No actual support, expressed or implied, is provided for use of this
function.
This commit is contained in:
David Walker
2023-01-05 17:30:34 -08:00
committed by GitHub
parent c42fde9379
commit 7b5080a42b
7 changed files with 23 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
* Class representing a Script instance that is actively running.
* A Script can have multiple active instances
*/
import type React from "react";
import { Script } from "./Script";
import { ScriptUrl } from "./ScriptUrl";
import { Settings } from "../Settings/Settings";
@@ -23,7 +24,7 @@ export class RunningScript {
filename = "";
// This script's logs. An array of log entries
logs: string[] = [];
logs: React.ReactNode[] = [];
// Flag indicating whether the logs have been updated since
// the last time the UI was updated
@@ -73,13 +74,13 @@ export class RunningScript {
this.dependencies = script.dependencies;
}
log(txt: string): void {
log(txt: React.ReactNode): void {
if (this.logs.length > Settings.MaxLogCapacity) {
this.logs.shift();
}
let logEntry = txt;
if (Settings.TimestampsFormat) {
if (Settings.TimestampsFormat && typeof txt === "string") {
logEntry = "[" + formatTime(Settings.TimestampsFormat) + "] " + logEntry;
}
@@ -88,8 +89,12 @@ export class RunningScript {
}
displayLog(): void {
for (let i = 0; i < this.logs.length; ++i) {
Terminal.print(this.logs[i]);
for (const log of this.logs) {
if (typeof log === "string") {
Terminal.print(log);
} else {
Terminal.printRaw(log);
}
}
}