diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index b0fe3cc36..33acddadb 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, fn, host, args)](./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 000000000..5d48d89cf --- /dev/null +++ b/markdown/bitburner.ns.settailfontsize.md @@ -0,0 +1,39 @@ + + +[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, fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| pixel | number | _(Optional)_ Optional. The new font size in pixels. If omitted, the default tail font size is used. | +| fn | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of the target script. If omitted, the current script is used. | +| host | string | _(Optional)_ Optional. Hostname of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. | +| args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments for the target script. | + +**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 ran without a filename or pid, this will affect the current script's tail window. + +Otherwise, the PID or filename, hostname/ip, and args… arguments can be used to target the tail window from another script. Remember that scripts are uniquely identified by both their names and arguments. + diff --git a/markdown/bitburner.tailproperties.fontsize.md b/markdown/bitburner.tailproperties.fontsize.md new file mode 100644 index 000000000..4e5728697 --- /dev/null +++ b/markdown/bitburner.tailproperties.fontsize.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [TailProperties](./bitburner.tailproperties.md) > [fontSize](./bitburner.tailproperties.fontsize.md) + +## TailProperties.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.tailproperties.md b/markdown/bitburner.tailproperties.md index 113d7d9f6..4a3bcb0e0 100644 --- a/markdown/bitburner.tailproperties.md +++ b/markdown/bitburner.tailproperties.md @@ -15,6 +15,7 @@ interface TailProperties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [fontSize](./bitburner.tailproperties.fontsize.md) | | number | The font size of the tail window. Defaults to the font size set in the style editor. | | [height](./bitburner.tailproperties.height.md) | | number | Height of the log window content area | | [width](./bitburner.tailproperties.width.md) | | number | Width of the log window content area | | [x](./bitburner.tailproperties.x.md) | | number | X-coordinate of the log window | diff --git a/src/Netscript/NetscriptHelpers.tsx b/src/Netscript/NetscriptHelpers.tsx index 24c6dac7c..466dc7719 100644 --- a/src/Netscript/NetscriptHelpers.tsx +++ b/src/Netscript/NetscriptHelpers.tsx @@ -63,6 +63,7 @@ import { validateSourceFileOverrides, } from "../BitNode/BitNodeUtils"; import { JSONMap } from "../Types/Jsonable"; +import { Settings } from "../Settings/Settings"; export const helpers = { string, @@ -747,6 +748,7 @@ function createPublicRunningScript(runningScript: RunningScript, workerScript?: y: logProps.y, width: logProps.width, height: logProps.height, + fontSize: logProps.fontSize ?? Settings.styles.tailFontSize, }, title: runningScript.title, threads: runningScript.threads, diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 6f3cdbbe8..0c565ac00 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 5c429bba9..1bab92632 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -616,6 +616,18 @@ export const ns: InternalAPI = { runningScriptObj.title = typeof title === "string" ? title : wrapUserNode(title); runningScriptObj.tailProps?.rerender(); }, + setTailFontSize: + (ctx) => + (_pixel, scriptID, hostname, ...scriptArgs) => { + const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs); + const runningScriptObj = helpers.getRunningScript(ctx, ident); + if (runningScriptObj == null) { + helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident)); + return; + } + if (_pixel === undefined) runningScriptObj.tailProps?.setFontSize(undefined); + else runningScriptObj.tailProps?.setFontSize(helpers.number(ctx, "pixel", _pixel)); + }, nuke: (ctx) => (_hostname) => { const hostname = helpers.string(ctx, "hostname", _hostname); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 71d91af79..f4f24cf3b 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -192,6 +192,8 @@ interface TailProperties { width: number; /** Height of the log window content area */ height: number; + /** The font size of the tail window. Defaults to the font size set in the style editor. */ + fontSize: number; } /** @@ -6467,6 +6469,25 @@ 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. + * + * If ran without a filename or pid, this will affect the current script's tail window. + * + * Otherwise, the PID or filename, hostname/ip, and args… arguments can be used to target the tail window from another script. + * Remember that scripts are uniquely identified by both their names and arguments. + * + * @param pixel - Optional. The new font size in pixels. If omitted, the default tail font size is used. + * @param fn - Optional. Filename or PID of the target script. If omitted, the current script is used. + * @param host - Optional. Hostname of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. + * @param args - Arguments for the target script. + */ + setTailFontSize(pixel?: number, fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): 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 5e2b3c675..4d3c1a38f 100644 --- a/src/ui/React/LogBoxManager.tsx +++ b/src/ui/React/LogBoxManager.tsx @@ -39,6 +39,7 @@ export class LogBoxProperties { y = window.innerHeight * 0.3; width = 500; height = 500; + fontSize: number | undefined = undefined; rerender: () => void; rootRef: React.RefObject; @@ -68,6 +69,11 @@ export class LogBoxProperties { this.rerender(); } + setFontSize(size?: number): void { + this.fontSize = size; + this.rerender(); + } + isVisible(): boolean { return this.rootRef.current !== null; } @@ -415,7 +421,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem text={line} color={lineColor(line)} styles={{ - fontSize: Settings.styles.tailFontSize, + fontSize: propsRef.current.fontSize ?? Settings.styles.tailFontSize, }} /> ),