mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
API: Move tail-related APIs to another namespace (#1935)
* API: Move tail-related APIs to another namespace * Add missing RAM cost config * Remove setTailFontSize from NS namespace
This commit is contained in:
@@ -4,7 +4,12 @@
|
||||
|
||||
## NS.closeTail() method
|
||||
|
||||
Close the tail window of a script.
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Use [ns.ui.closeTail](./bitburner.userinterface.closetail.md) instead.
|
||||
>
|
||||
|
||||
Close the tail window of a script. This function is deprecated and will be removed in a later version.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export async function main(ns) {
|
||||
| [clear(handle)](./bitburner.ns.clear.md) | Clear data from a file. |
|
||||
| [clearLog()](./bitburner.ns.clearlog.md) | Clears the script’s logs. |
|
||||
| [clearPort(portNumber)](./bitburner.ns.clearport.md) | Clear data from a port. |
|
||||
| [closeTail(pid)](./bitburner.ns.closetail.md) | Close the tail window of a script. |
|
||||
| [closeTail(pid)](./bitburner.ns.closetail.md) | Close the tail window of a script. This function is deprecated and will be removed in a later version. |
|
||||
| [deleteServer(host)](./bitburner.ns.deleteserver.md) | Delete a purchased server. |
|
||||
| [disableLog(fn)](./bitburner.ns.disablelog.md) | Disables logging for the given NS function. |
|
||||
| [enableLog(fn)](./bitburner.ns.enablelog.md) | Enables logging for the given NS function. |
|
||||
@@ -131,7 +131,7 @@ export async function main(ns) {
|
||||
| [kill(filename, hostname, args)](./bitburner.ns.kill_1.md) | Terminate the script(s) with the provided filename, hostname, and script arguments. |
|
||||
| [killall(host, safetyGuard)](./bitburner.ns.killall.md) | Terminate all scripts on a server. |
|
||||
| [ls(host, substring)](./bitburner.ns.ls.md) | List files on a server. |
|
||||
| [moveTail(x, y, pid)](./bitburner.ns.movetail.md) | Move a tail window. |
|
||||
| [moveTail(x, y, pid)](./bitburner.ns.movetail.md) | Move a tail window. This function is deprecated and will be removed in a later version. |
|
||||
| [mv(host, source, destination)](./bitburner.ns.mv.md) | Move a file on the target server. |
|
||||
| [nextPortWrite(port)](./bitburner.ns.nextportwrite.md) | Listen for a port write. |
|
||||
| [nFormat(n, format)](./bitburner.ns.nformat.md) | Format a number using the numeral library. This function is deprecated and will be removed in a later version. |
|
||||
@@ -148,8 +148,7 @@ export async function main(ns) {
|
||||
| [readPort(portNumber)](./bitburner.ns.readport.md) | Read data from a port. |
|
||||
| [relaysmtp(host)](./bitburner.ns.relaysmtp.md) | Runs relaySMTP.exe on a server. |
|
||||
| [renamePurchasedServer(hostname, newName)](./bitburner.ns.renamepurchasedserver.md) | Rename a purchased server. |
|
||||
| [renderTail(pid)](./bitburner.ns.rendertail.md) | Render a tail window. |
|
||||
| [resizeTail(width, height, pid)](./bitburner.ns.resizetail.md) | Resize a tail window. |
|
||||
| [resizeTail(width, height, pid)](./bitburner.ns.resizetail.md) | Resize a tail window. This function is deprecated and will be removed in a later version. |
|
||||
| [rm(name, host)](./bitburner.ns.rm.md) | Delete a file. |
|
||||
| [run(script, threadOrOptions, args)](./bitburner.ns.run.md) | Start another script on the current server. |
|
||||
| [scan(host)](./bitburner.ns.scan.md) | Get the list of servers connected to a server. |
|
||||
@@ -158,14 +157,13 @@ 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. |
|
||||
| [setTitle(title, pid)](./bitburner.ns.settitle.md) | Set the title of the tail window of a script. This function is deprecated and will be removed in a later version. |
|
||||
| [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. |
|
||||
| [spawn(script, threadOrOptions, args)](./bitburner.ns.spawn.md) | Terminate current script and start another in a defined number of milliseconds. |
|
||||
| [sprintf(format, args)](./bitburner.ns.sprintf.md) | Format a string. |
|
||||
| [sqlinject(host)](./bitburner.ns.sqlinject.md) | Runs SQLInject.exe on a server. |
|
||||
| [tail(fn, host, args)](./bitburner.ns.tail.md) | Open the tail window of a script. |
|
||||
| [tail(fn, host, args)](./bitburner.ns.tail.md) | Open the tail window of a script. This function is deprecated and will be removed in a later version. |
|
||||
| [tFormat(milliseconds, milliPrecision)](./bitburner.ns.tformat.md) | Format time to a readable string. |
|
||||
| [toast(msg, variant, duration)](./bitburner.ns.toast.md) | Queue a toast (bottom-right notification). |
|
||||
| [tprint(args)](./bitburner.ns.tprint.md) | Prints one or more values or variables to the Terminal. |
|
||||
|
||||
@@ -4,7 +4,12 @@
|
||||
|
||||
## NS.moveTail() method
|
||||
|
||||
Move a tail window.
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Use [ns.ui.moveTail](./bitburner.userinterface.movetail.md) instead.
|
||||
>
|
||||
|
||||
Move a tail window. This function is deprecated and will be removed in a later version.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -4,7 +4,12 @@
|
||||
|
||||
## NS.resizeTail() method
|
||||
|
||||
Resize a tail window.
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Use [ns.ui.resizeTail](./bitburner.userinterface.resizetail.md) instead.
|
||||
>
|
||||
|
||||
Resize a tail window. This function is deprecated and will be removed in a later version.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -4,7 +4,12 @@
|
||||
|
||||
## NS.setTitle() method
|
||||
|
||||
Set the title of the tail window of a script.
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Use [ns.ui.setTailTitle](./bitburner.userinterface.settailtitle.md) instead.
|
||||
>
|
||||
|
||||
Set the title of the tail window of a script. This function is deprecated and will be removed in a later version.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -4,7 +4,12 @@
|
||||
|
||||
## NS.tail() method
|
||||
|
||||
Open the tail window of a script.
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Use [ns.ui.openTail](./bitburner.userinterface.opentail.md) instead.
|
||||
>
|
||||
|
||||
Open the tail window of a script. This function is deprecated and will be removed in a later version.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
34
markdown/bitburner.userinterface.closetail.md
Normal file
34
markdown/bitburner.userinterface.closetail.md
Normal file
@@ -0,0 +1,34 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [closeTail](./bitburner.userinterface.closetail.md)
|
||||
|
||||
## UserInterface.closeTail() method
|
||||
|
||||
Close the tail window of a script.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
closeTail(pid?: number): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| 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
|
||||
|
||||
Closes a script’s logs. This is functionally the same as pressing the "Close" button on the tail window.
|
||||
|
||||
If the function is called with no arguments, it will close the current script’s logs.
|
||||
|
||||
Otherwise, the pid argument can be used to close the logs from another script.
|
||||
|
||||
@@ -17,12 +17,19 @@ interface UserInterface
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [clearTerminal()](./bitburner.userinterface.clearterminal.md) | Clear the Terminal window, as if the player ran <code>clear</code> in the terminal |
|
||||
| [closeTail(pid)](./bitburner.userinterface.closetail.md) | Close the tail window of a script. |
|
||||
| [getGameInfo()](./bitburner.userinterface.getgameinfo.md) | Gets the current game information (version, commit, ...) |
|
||||
| [getStyles()](./bitburner.userinterface.getstyles.md) | Get the current styles |
|
||||
| [getTheme()](./bitburner.userinterface.gettheme.md) | Get the current theme |
|
||||
| [moveTail(x, y, pid)](./bitburner.userinterface.movetail.md) | Move a tail window. |
|
||||
| [openTail(fn, host, args)](./bitburner.userinterface.opentail.md) | Open the tail window of a script. |
|
||||
| [renderTail(pid)](./bitburner.userinterface.rendertail.md) | Render a tail window. |
|
||||
| [resetStyles()](./bitburner.userinterface.resetstyles.md) | Resets the player's styles to the default values |
|
||||
| [resetTheme()](./bitburner.userinterface.resettheme.md) | Resets the player's theme to the default values |
|
||||
| [resizeTail(width, height, pid)](./bitburner.userinterface.resizetail.md) | Resize a tail window. |
|
||||
| [setStyles(newStyles)](./bitburner.userinterface.setstyles.md) | Sets the current styles |
|
||||
| [setTailFontSize(pixel, fn, host, args)](./bitburner.userinterface.settailfontsize.md) | Set the font size of the tail window of a script. |
|
||||
| [setTailTitle(title, pid)](./bitburner.userinterface.settailtitle.md) | Set the title of the tail window of a script. |
|
||||
| [setTheme(newTheme)](./bitburner.userinterface.settheme.md) | Sets the current theme |
|
||||
| [windowSize()](./bitburner.userinterface.windowsize.md) | Get the current window size |
|
||||
|
||||
|
||||
32
markdown/bitburner.userinterface.movetail.md
Normal file
32
markdown/bitburner.userinterface.movetail.md
Normal file
@@ -0,0 +1,32 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [moveTail](./bitburner.userinterface.movetail.md)
|
||||
|
||||
## UserInterface.moveTail() method
|
||||
|
||||
Move a tail window.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
moveTail(x: number, y: number, pid?: number): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| x | number | x coordinate. |
|
||||
| y | number | y coordinate. |
|
||||
| pid | number | _(Optional)_ Optional. PID of the script having its tail moved. If omitted, the current script is used. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
void
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Moves a tail window. Coordinates are in screen space pixels (top left is 0,0).
|
||||
|
||||
50
markdown/bitburner.userinterface.opentail.md
Normal file
50
markdown/bitburner.userinterface.opentail.md
Normal file
@@ -0,0 +1,50 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [openTail](./bitburner.userinterface.opentail.md)
|
||||
|
||||
## UserInterface.openTail() method
|
||||
|
||||
Open the tail window of a script.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
openTail(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| fn | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of the script being tailed. If omitted, the current script is tailed. |
|
||||
| host | string | _(Optional)_ Optional. Hostname of the script being tailed. 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 script being tailed. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
void
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Opens a script’s logs. This is functionally the same as the tail Terminal command.
|
||||
|
||||
If the function is called with no arguments, it will open the current script’s logs.
|
||||
|
||||
Otherwise, the PID or filename, hostname/ip, and args… arguments can be used to get the logs from another script. Remember that scripts are uniquely identified by both their names and arguments.
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```js
|
||||
//Open logs from foo.js on the current server that was run with no args
|
||||
ns.tail("foo.js");
|
||||
|
||||
//Get logs from foo.js on the foodnstuff server that was run with no args
|
||||
ns.tail("foo.js", "foodnstuff");
|
||||
|
||||
//Get logs from foo.js on the foodnstuff server that was run with the arguments [1, "test"]
|
||||
ns.tail("foo.js", "foodnstuff", 1, "test");
|
||||
```
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [renderTail](./bitburner.ns.rendertail.md)
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [renderTail](./bitburner.userinterface.rendertail.md)
|
||||
|
||||
## NS.renderTail() method
|
||||
## UserInterface.renderTail() method
|
||||
|
||||
Render a tail window.
|
||||
|
||||
32
markdown/bitburner.userinterface.resizetail.md
Normal file
32
markdown/bitburner.userinterface.resizetail.md
Normal file
@@ -0,0 +1,32 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [resizeTail](./bitburner.userinterface.resizetail.md)
|
||||
|
||||
## UserInterface.resizeTail() method
|
||||
|
||||
Resize a tail window.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
resizeTail(width: number, height: number, pid?: number): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| width | number | Width of the window. |
|
||||
| height | number | Height of the window. |
|
||||
| pid | number | _(Optional)_ Optional. PID of the script having its tail resized. If omitted, the current script is used. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
void
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
Resize a tail window. Size are in pixel.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [setTailFontSize](./bitburner.ns.settailfontsize.md)
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [setTailFontSize](./bitburner.userinterface.settailfontsize.md)
|
||||
|
||||
## NS.setTailFontSize() method
|
||||
## UserInterface.setTailFontSize() method
|
||||
|
||||
Set the font size of the tail window of a script.
|
||||
|
||||
39
markdown/bitburner.userinterface.settailtitle.md
Normal file
39
markdown/bitburner.userinterface.settailtitle.md
Normal file
@@ -0,0 +1,39 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [UserInterface](./bitburner.userinterface.md) > [setTailTitle](./bitburner.userinterface.settailtitle.md)
|
||||
|
||||
## UserInterface.setTailTitle() method
|
||||
|
||||
Set the title of the tail window of a script.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
setTailTitle(title: string | ReactNode, pid?: number): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| title | string \| [ReactNode](./bitburner.reactnode.md) | The new title for the tail window. |
|
||||
| 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 sets the title to the given string, and also forces an update of the tail window's contents.
|
||||
|
||||
The title is saved across restarts, but only if it is a simple string.
|
||||
|
||||
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.
|
||||
|
||||
It is possible to pass any React Node instead of a string. See [ReactElement](./bitburner.reactelement.md) and [ReactNode](./bitburner.reactnode.md) types for additional info.
|
||||
|
||||
@@ -380,6 +380,13 @@ const stanek = {
|
||||
|
||||
// UI API
|
||||
const ui = {
|
||||
openTail: 0,
|
||||
renderTail: 0,
|
||||
moveTail: 0,
|
||||
resizeTail: 0,
|
||||
closeTail: 0,
|
||||
setTailTitle: 0,
|
||||
setTailFontSize: 0,
|
||||
getTheme: 0,
|
||||
setTheme: 0,
|
||||
resetTheme: 0,
|
||||
@@ -601,11 +608,9 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
tail: 0,
|
||||
toast: 0,
|
||||
moveTail: 0,
|
||||
renderTail: 0,
|
||||
resizeTail: 0,
|
||||
closeTail: 0,
|
||||
setTitle: 0,
|
||||
setTailFontSize: 0,
|
||||
clearPort: 0,
|
||||
openDevMenu: 0,
|
||||
alert: 0,
|
||||
|
||||
@@ -66,7 +66,6 @@ import {
|
||||
} from "./ui/formatNumber";
|
||||
import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions";
|
||||
import { roundToTwo } from "./utils/helpers/roundToTwo";
|
||||
import { LogBoxEvents, LogBoxCloserEvents } from "./ui/React/LogBoxManager";
|
||||
import { arrayToString } from "./utils/helpers/ArrayHelpers";
|
||||
import { NetscriptGang } from "./NetscriptFunctions/Gang";
|
||||
import { NetscriptGo } from "./NetscriptFunctions/Go";
|
||||
@@ -561,82 +560,32 @@ export const ns: InternalAPI<NSFull> = {
|
||||
tail:
|
||||
(ctx) =>
|
||||
(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;
|
||||
}
|
||||
|
||||
LogBoxEvents.emit(runningScriptObj);
|
||||
},
|
||||
renderTail:
|
||||
(ctx) =>
|
||||
(_pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.rerender();
|
||||
deprecationWarning("ns.tail", "Use ns.ui.openTail instead.");
|
||||
ns.ui.openTail(ctx)(scriptID, hostname, ...scriptArgs);
|
||||
},
|
||||
moveTail:
|
||||
(ctx) =>
|
||||
(_x, _y, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const x = helpers.number(ctx, "x", _x);
|
||||
const y = helpers.number(ctx, "y", _y);
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.setPosition(x, y);
|
||||
deprecationWarning("ns.moveTail", "Use ns.ui.moveTail instead.");
|
||||
ns.ui.moveTail(ctx)(_x, _y, _pid);
|
||||
},
|
||||
resizeTail:
|
||||
(ctx) =>
|
||||
(_w, _h, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const w = helpers.number(ctx, "w", _w);
|
||||
const h = helpers.number(ctx, "h", _h);
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.setSize(w, h);
|
||||
deprecationWarning("ns.resizeTail", "Use ns.ui.resizeTail instead.");
|
||||
ns.ui.resizeTail(ctx)(_w, _h, _pid);
|
||||
},
|
||||
closeTail:
|
||||
(ctx) =>
|
||||
(_pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
//Emit an event to tell the game to close the tail window if it exists
|
||||
LogBoxCloserEvents.emit(pid);
|
||||
deprecationWarning("ns.closeTail", "Use ns.ui.closeTail instead.");
|
||||
ns.ui.closeTail(ctx)(_pid);
|
||||
},
|
||||
setTitle:
|
||||
(ctx) =>
|
||||
(title, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
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));
|
||||
deprecationWarning("ns.setTitle", "Use ns.ui.setTailTitle instead.");
|
||||
ns.ui.setTailTitle(ctx)(title, _pid);
|
||||
},
|
||||
nuke: (ctx) => (_hostname) => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
|
||||
@@ -7,14 +7,103 @@ import { CONSTANTS } from "../Constants";
|
||||
import { commitHash } from "../utils/helpers/commitHash";
|
||||
import { InternalAPI } from "../Netscript/APIWrapper";
|
||||
import { Terminal } from "../../src/Terminal";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { helpers, wrapUserNode } from "../Netscript/NetscriptHelpers";
|
||||
import { assertAndSanitizeMainTheme, assertAndSanitizeStyles } from "../JsonSchema/JSONSchemaAssertion";
|
||||
import { LogBoxCloserEvents, LogBoxEvents } from "../ui/React/LogBoxManager";
|
||||
|
||||
export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
return {
|
||||
openTail:
|
||||
(ctx) =>
|
||||
(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;
|
||||
}
|
||||
|
||||
LogBoxEvents.emit(runningScriptObj);
|
||||
},
|
||||
|
||||
renderTail:
|
||||
(ctx) =>
|
||||
(_pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.rerender();
|
||||
},
|
||||
|
||||
moveTail:
|
||||
(ctx) =>
|
||||
(_x, _y, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const x = helpers.number(ctx, "x", _x);
|
||||
const y = helpers.number(ctx, "y", _y);
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.setPosition(x, y);
|
||||
},
|
||||
|
||||
resizeTail:
|
||||
(ctx) =>
|
||||
(_w, _h, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const w = helpers.number(ctx, "w", _w);
|
||||
const h = helpers.number(ctx, "h", _h);
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
runningScriptObj.tailProps?.setSize(w, h);
|
||||
},
|
||||
|
||||
closeTail:
|
||||
(ctx) =>
|
||||
(_pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
//Emit an event to tell the game to close the tail window if it exists
|
||||
LogBoxCloserEvents.emit(pid);
|
||||
},
|
||||
|
||||
setTailTitle:
|
||||
(ctx) =>
|
||||
(title, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, pid);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
|
||||
return;
|
||||
}
|
||||
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));
|
||||
},
|
||||
|
||||
windowSize: () => () => {
|
||||
return [window.innerWidth, window.innerHeight];
|
||||
},
|
||||
|
||||
getTheme: () => () => {
|
||||
return { ...Settings.theme };
|
||||
},
|
||||
|
||||
188
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
188
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -5675,6 +5675,136 @@ interface Infiltration {
|
||||
* @public
|
||||
*/
|
||||
interface UserInterface {
|
||||
/**
|
||||
* Open the tail window of a script.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Opens a script’s logs. This is functionally the same as the tail Terminal command.
|
||||
*
|
||||
* If the function is called with no arguments, it will open the current script’s logs.
|
||||
*
|
||||
* Otherwise, the PID or filename, hostname/ip, and args… arguments can be used to get the logs from another script.
|
||||
* Remember that scripts are uniquely identified by both their names and arguments.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* //Open logs from foo.js on the current server that was run with no args
|
||||
* ns.tail("foo.js");
|
||||
*
|
||||
* //Get logs from foo.js on the foodnstuff server that was run with no args
|
||||
* ns.tail("foo.js", "foodnstuff");
|
||||
*
|
||||
* //Get logs from foo.js on the foodnstuff server that was run with the arguments [1, "test"]
|
||||
* ns.tail("foo.js", "foodnstuff", 1, "test");
|
||||
* ```
|
||||
* @param fn - Optional. Filename or PID of the script being tailed. If omitted, the current script is tailed.
|
||||
* @param host - Optional. Hostname of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional.
|
||||
* @param args - Arguments for the script being tailed.
|
||||
*/
|
||||
openTail(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void;
|
||||
|
||||
/**
|
||||
* Render a tail window.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Tail windows are rendered at an interval defined in game settings. This function renders the tail window of the
|
||||
* specified script immediately.
|
||||
*
|
||||
* @param pid - Optional. PID of the script having its tail rendered. If omitted, the current script is used.
|
||||
*/
|
||||
renderTail(pid?: number): void;
|
||||
|
||||
/**
|
||||
* Move a tail window.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Moves a tail window. Coordinates are in screen space pixels (top left is 0,0).
|
||||
*
|
||||
* @param x - x coordinate.
|
||||
* @param y - y coordinate.
|
||||
* @param pid - Optional. PID of the script having its tail moved. If omitted, the current script is used.
|
||||
*/
|
||||
moveTail(x: number, y: number, pid?: number): void;
|
||||
|
||||
/**
|
||||
* Resize a tail window.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Resize a tail window. Size are in pixel.
|
||||
*
|
||||
* @param width - Width of the window.
|
||||
* @param height - Height of the window.
|
||||
* @param pid - Optional. PID of the script having its tail resized. If omitted, the current script is used.
|
||||
*/
|
||||
resizeTail(width: number, height: number, pid?: number): void;
|
||||
|
||||
/**
|
||||
* Close the tail window of a script.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* Closes a script’s logs. This is functionally the same as pressing the "Close" button on the tail window.
|
||||
*
|
||||
* If the function is called with no arguments, it will close the current script’s logs.
|
||||
*
|
||||
* Otherwise, the pid argument can be used to close the logs from another script.
|
||||
*
|
||||
* @param pid - Optional. PID of the script having its tail closed. If omitted, the current script is used.
|
||||
*/
|
||||
closeTail(pid?: number): void;
|
||||
|
||||
/**
|
||||
* Set the title of the tail window of a script.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* This sets the title to the given string, and also forces an update of the
|
||||
* tail window's contents.
|
||||
*
|
||||
* The title is saved across restarts, but only if it is a simple string.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* It is possible to pass any React Node instead of a string.
|
||||
* See {@link ReactElement} and {@link ReactNode} types for additional info.
|
||||
*
|
||||
* @param title - The new title for the tail window.
|
||||
* @param pid - Optional. PID of the script having its tail closed. If omitted, the current script is used.
|
||||
*/
|
||||
setTailTitle(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 current window size
|
||||
* @remarks
|
||||
@@ -6405,7 +6535,11 @@ export interface NS {
|
||||
getRecentScripts(): RecentScript[];
|
||||
|
||||
/**
|
||||
* Open the tail window of a script.
|
||||
* Open the tail window of a script. This function is deprecated and will be removed in a later version.
|
||||
*
|
||||
* @deprecated
|
||||
* Use {@link UserInterface.openTail | ns.ui.openTail} instead.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
@@ -6434,20 +6568,11 @@ export interface NS {
|
||||
tail(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void;
|
||||
|
||||
/**
|
||||
* Render a tail window.
|
||||
* Move a tail window. This function is deprecated and will be removed in a later version.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @deprecated
|
||||
* Use {@link UserInterface.moveTail | ns.ui.moveTail} instead.
|
||||
*
|
||||
* Tail windows are rendered at an interval defined in game settings. This function renders the tail window of the
|
||||
* specified script immediately.
|
||||
*
|
||||
* @param pid - Optional. PID of the script having its tail rendered. If omitted, the current script is used.
|
||||
*/
|
||||
renderTail(pid?: number): void;
|
||||
|
||||
/**
|
||||
* Move a tail window.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
@@ -6460,7 +6585,11 @@ export interface NS {
|
||||
moveTail(x: number, y: number, pid?: number): void;
|
||||
|
||||
/**
|
||||
* Resize a tail window.
|
||||
* Resize a tail window. This function is deprecated and will be removed in a later version.
|
||||
*
|
||||
* @deprecated
|
||||
* Use {@link UserInterface.resizeTail | ns.ui.resizeTail} instead.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
@@ -6473,7 +6602,11 @@ export interface NS {
|
||||
resizeTail(width: number, height: number, pid?: number): void;
|
||||
|
||||
/**
|
||||
* Close the tail window of a script.
|
||||
* Close the tail window of a script. This function is deprecated and will be removed in a later version.
|
||||
*
|
||||
* @deprecated
|
||||
* Use {@link UserInterface.closeTail | ns.ui.closeTail} instead.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
@@ -6488,7 +6621,11 @@ export interface NS {
|
||||
closeTail(pid?: number): void;
|
||||
|
||||
/**
|
||||
* Set the title of the tail window of a script.
|
||||
* Set the title of the tail window of a script. This function is deprecated and will be removed in a later version.
|
||||
*
|
||||
* @deprecated
|
||||
* Use {@link UserInterface.setTailTitle | ns.ui.setTailTitle} instead.
|
||||
*
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
@@ -6509,25 +6646,6 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user