diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index b0fe3cc365..322855b241 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -157,6 +157,7 @@ export async function main(ns) { | [scriptRunning(script, host)](./bitburner.ns.scriptrunning.md) | Check if any script with a filename is running. | | [self()](./bitburner.ns.self.md) | Returns the currently running script. | | [serverExists(host)](./bitburner.ns.serverexists.md) | Returns a boolean denoting whether or not the specified server exists. | +| [setTailFontSize(pixel, pid)](./bitburner.ns.settailfontsize.md) | Set the font size of the tail window of a script. | | [setTitle(title, pid)](./bitburner.ns.settitle.md) | Set the title of the tail window of a script. | | [share()](./bitburner.ns.share.md) | Share the server's ram with your factions. | | [sleep(millis)](./bitburner.ns.sleep.md) | Suspends the script for n milliseconds. | diff --git a/markdown/bitburner.ns.settailfontsize.md b/markdown/bitburner.ns.settailfontsize.md new file mode 100644 index 0000000000..bf1ee56bb6 --- /dev/null +++ b/markdown/bitburner.ns.settailfontsize.md @@ -0,0 +1,37 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [setTailFontSize](./bitburner.ns.settailfontsize.md) + +## NS.setTailFontSize() method + +Set the font size of the tail window of a script. + +**Signature:** + +```typescript +setTailFontSize(pixel?: number, pid?: number): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| pixel | number | _(Optional)_ Optional. The new font size in pixels. If omitted, the default tail font size is used. | +| pid | number | _(Optional)_ Optional. PID of the script having its tail closed. If omitted, the current script is used. | + +**Returns:** + +void + +## Remarks + +RAM cost: 0 GB + +This overwrites the tail font size and forces an update of the tail window's contents. + +The font size is saved across restarts. + +If the pid is unspecified, it will modify the current script's logs. + +Otherwise, the pid argument can be used to change the logs from another script. + diff --git a/markdown/bitburner.runningscript.fontsize.md b/markdown/bitburner.runningscript.fontsize.md new file mode 100644 index 0000000000..08357f696f --- /dev/null +++ b/markdown/bitburner.runningscript.fontsize.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [RunningScript](./bitburner.runningscript.md) > [fontSize](./bitburner.runningscript.fontsize.md) + +## RunningScript.fontSize property + +The font size of the tail window. Defaults to the font size set in the style editor. + +**Signature:** + +```typescript +fontSize: number; +``` diff --git a/markdown/bitburner.runningscript.md b/markdown/bitburner.runningscript.md index 248b36545d..107aab46e6 100644 --- a/markdown/bitburner.runningscript.md +++ b/markdown/bitburner.runningscript.md @@ -18,6 +18,7 @@ interface RunningScript | [args](./bitburner.runningscript.args.md) | | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments the script was called with | | [dynamicRamUsage](./bitburner.runningscript.dynamicramusage.md) | | number \| undefined |

The dynamic RAM usage of (one thread of) this script instance. Does not affect overall RAM consumption (ramUsage is for that), but rather shows how much of the reserved RAM is currently in use via all the ns functions the script has called. Initially 1.6GB, this increases as new functions are called.

Only set for scripts that are still running.

| | [filename](./bitburner.runningscript.filename.md) | | string | Filename of the script | +| [fontSize](./bitburner.runningscript.fontsize.md) | | number | The font size of the tail window. Defaults to the font size set in the style editor. | | [logs](./bitburner.runningscript.logs.md) | | string\[\] | Script logs as an array. The newest log entries are at the bottom. Timestamps, if enabled, are placed inside [brackets] at the start of each line. | | [offlineExpGained](./bitburner.runningscript.offlineexpgained.md) | | number | Total amount of hacking experience earned from this script when offline | | [offlineMoneyMade](./bitburner.runningscript.offlinemoneymade.md) | | number | Total amount of money made by this script when offline | diff --git a/src/Netscript/NetscriptHelpers.tsx b/src/Netscript/NetscriptHelpers.tsx index 24c6dac7c9..ee81149ce4 100644 --- a/src/Netscript/NetscriptHelpers.tsx +++ b/src/Netscript/NetscriptHelpers.tsx @@ -749,6 +749,7 @@ function createPublicRunningScript(runningScript: RunningScript, workerScript?: height: logProps.height, }, title: runningScript.title, + fontSize: runningScript.fontSize, threads: runningScript.threads, temporary: runningScript.temporary, }; diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 6f3cdbbe8c..0c565ac009 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -602,6 +602,7 @@ export const RamCosts: RamCostTree = { resizeTail: 0, closeTail: 0, setTitle: 0, + setTailFontSize: 0, clearPort: 0, openDevMenu: 0, alert: 0, diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index ce1fc8c6bb..60f019632f 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -113,6 +113,7 @@ import { assertFunction } from "./Netscript/TypeAssertion"; import { Router } from "./ui/GameRoot"; import { Page } from "./ui/Router"; import { canAccessBitNodeFeature, validBitNodes } from "./BitNode/BitNodeUtils"; +import { Settings } from "./Settings/Settings"; export const enums: NSEnums = { CityName, @@ -613,6 +614,19 @@ export const ns: InternalAPI = { runningScriptObj.title = typeof title === "string" ? title : wrapUserNode(title); runningScriptObj.tailProps?.rerender(); }, + setTailFontSize: + (ctx) => + (_pixel = Settings.styles.tailFontSize, _pid = ctx.workerScript.scriptRef.pid) => { + const pixel = helpers.number(ctx, "pixel", _pixel); + const pid = helpers.number(ctx, "pid", _pid); + const runningSCriptObj = helpers.getRunningScript(ctx, pid); + if (runningSCriptObj == null) { + helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid)); + return; + } + runningSCriptObj.fontSize = pixel; + runningSCriptObj.tailProps?.rerender(); + }, nuke: (ctx) => (_hostname) => { const hostname = helpers.string(ctx, "hostname", _hostname); diff --git a/src/Script/RunningScript.ts b/src/Script/RunningScript.ts index 68278109f2..fd55fafc79 100644 --- a/src/Script/RunningScript.ts +++ b/src/Script/RunningScript.ts @@ -78,6 +78,9 @@ export class RunningScript { // that will not be persisted, and will be restored to default on load. title = "" as string | React.ReactElement; + // The font size of the tail window. Defaults to the font size set in the style editor. + fontSize = Settings.styles.tailFontSize; + // Number of threads that this script is running with threads = 1 as PositiveInteger; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 29d370a4da..e9d6ec6757 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -277,6 +277,8 @@ interface RunningScript { * load. */ title: string | ReactElement; + /** The font size of the tail window. Defaults to the font size set in the style editor. */ + fontSize: number; /** Number of threads that this script runs with */ threads: number; /** Whether this RunningScript is excluded from saves */ @@ -6460,6 +6462,24 @@ export interface NS { */ setTitle(title: string | ReactNode, pid?: number): void; + /** + * Set the font size of the tail window of a script. + * @remarks + * RAM cost: 0 GB + * + * This overwrites the tail font size and forces an update of the tail window's contents. + * + * The font size is saved across restarts. + * + * If the pid is unspecified, it will modify the current script's logs. + * + * Otherwise, the pid argument can be used to change the logs from another script. + * + * @param pixel - Optional. The new font size in pixels. If omitted, the default tail font size is used. + * @param pid - Optional. PID of the script having its tail closed. If omitted, the current script is used. + */ + setTailFontSize(pixel?: number, pid?: number): void; + /** * Get the list of servers connected to a server. * @remarks diff --git a/src/ui/React/LogBoxManager.tsx b/src/ui/React/LogBoxManager.tsx index 5e2b3c6757..7e6a0df53d 100644 --- a/src/ui/React/LogBoxManager.tsx +++ b/src/ui/React/LogBoxManager.tsx @@ -415,7 +415,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem text={line} color={lineColor(line)} styles={{ - fontSize: Settings.styles.tailFontSize, + fontSize: script.fontSize, }} /> ), diff --git a/test/jest/Save.test.ts b/test/jest/Save.test.ts index 65f4f7f388..d442b03a60 100644 --- a/test/jest/Save.test.ts +++ b/test/jest/Save.test.ts @@ -79,6 +79,7 @@ function loadStandardServers() { "server": "home", "scriptKey": "script.js*[]", "title": "Awesome Script", + "fontSize": 16, "dependencies": [ { "filename": "script.js", diff --git a/test/jest/__snapshots__/Save.test.ts.snap b/test/jest/__snapshots__/Save.test.ts.snap index 517b86d53b..092c0b0f57 100644 --- a/test/jest/__snapshots__/Save.test.ts.snap +++ b/test/jest/__snapshots__/Save.test.ts.snap @@ -75,6 +75,7 @@ exports[`load/saveAllServers 1`] = ` "server": "home", "scriptKey": "script.js*[]", "title": "Awesome Script", + "fontSize": 16, "threads": 1, "temporary": false }