Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BrowserPod {
createCustomTerminal(opts: {
cols?: number;
rows?: number;
onOutput: (buffer: ArrayBuffer, vt?: unknown) => void;
onOutput: (buffer: Uint8Array, vt?: number) => void;
}): Promise<Terminal>;
}
```
Expand All @@ -21,7 +21,7 @@ class BrowserPod {

- **cols (`number`, _optional_)** - The number of columns (width) for the terminal display. If not specified, a default width will be used.
- **rows (`number`, _optional_)** - The number of rows (height) for the terminal display. If not specified, a default height will be used.
- **onOutput (`function(buffer: ArrayBuffer, vt?: unknown) => void`)** - Callback function invoked whenever the terminal produces output. The buffer contains the raw terminal data, and vt contains optional VT escape sequence information.
- **onOutput (`function(buffer: Uint8Array, vt?: number) => void`)** - Callback function invoked whenever the terminal produces output. The buffer contains the raw terminal data, and vt is the ID of the terminal that produced it.

## Returns

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: run
description: "Run an executable inside a BrowserPod Pod, attach it to a terminal for input and output, and get back a Process handle for its result."
description: "Run an executable inside a BrowserPod Pod, attach it to a terminal for input and output, and wait for its exit code."
---

```ts
Expand All @@ -14,7 +14,7 @@ class BrowserPod {
cwd?: string;
echo?: boolean;
}
): Promise<Process>;
): Process;
}
```

Expand All @@ -33,8 +33,16 @@ class BrowserPod {

## Returns

`run` returns a [Promise] which resolves to a [Process] object once the command finishes running.
`run` returns a [Process], a thenable object. Awaiting it resolves to the exit code of the process once it exits, so you can check whether it succeeded or failed:

```ts
const exitCode = await pod.run("npm", ["install"], { terminal });
if (exitCode !== 0) {
console.error(`npm install failed with exit code ${exitCode}`);
}
```

If the process cannot be started or is killed by a signal, awaiting it throws an error instead.

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[Terminal]: /docs/reference/Terminal
[Process]: /docs/reference/Process
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ const pod = await BrowserPod.boot({ apiKey: "...", storageKey: "my-project" });

### Run programs

Use [`run`](/docs/reference/BrowserPod/run) to execute a program and get back a [Process](/docs/reference/Process):
Use [`run`](/docs/reference/BrowserPod/run) to execute a program. It returns a [Process](/docs/reference/Process) that resolves to the exit code when awaited:

```ts
const process = await pod.run("node", ["script.js"], { terminal });
const exitCode = await pod.run("node", ["script.js"], { terminal });
```

### Manage the filesystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ title: Terminal
description: A handle to a terminal emulator running inside a Pod
---

A `Terminal` is an opaque handle to a terminal emulator running inside a [Pod](/docs/reference/BrowserPod). It is created by [`createDefaultTerminal`](/docs/reference/BrowserPod/createDefaultTerminal) or [`createCustomTerminal`](/docs/reference/BrowserPod/createCustomTerminal), and passed to [`run`](/docs/reference/BrowserPod/run) to connect a process to I/O.
A `Terminal` is a handle to a terminal emulator running inside a [Pod](/docs/reference/BrowserPod). It is created by [`createDefaultTerminal`](/docs/reference/BrowserPod/createDefaultTerminal) or [`createCustomTerminal`](/docs/reference/BrowserPod/createCustomTerminal), and passed to [`run`](/docs/reference/BrowserPod/run) to connect a process to I/O.

```ts
class Terminal {}
class Terminal {
write(data: string | Uint8Array): void;
}
```

## Creating a Terminal
Expand All @@ -20,3 +22,12 @@ class Terminal {}
const terminal = await pod.createDefaultTerminal(element);
await pod.run("node", ["script.js"], { terminal });
```

## Writing to a terminal

`write` sends text or bytes directly to the terminal's output, without going through a process in the Pod. Running processes do not receive it as input. Use it to show your own messages alongside program output, such as the command about to run:

```ts
terminal.write("$ npm install\r\n");
await pod.run("npm", ["install"], { terminal });
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
title: Process
description: A handle to a process that ran inside a Pod
description: A handle to a process running inside a Pod
---

A `Process` is an opaque handle to a program that ran inside a [Pod](/docs/reference/BrowserPod). It is returned by [`run`](/docs/reference/BrowserPod/run) once the process has exited.
A `Process` is a handle to a process running inside a [Pod](/docs/reference/BrowserPod). It is returned by [`run`](/docs/reference/BrowserPod/run).

`Process` is a thenable object: awaiting it resolves to the exit code of the process once it exits. If the process cannot be started or is killed by a signal, awaiting it throws an error instead.

```ts
class Process {}
Expand All @@ -12,9 +14,5 @@ class Process {}
## Creating a Process

```ts
const process = await pod.run("node", ["script.js"], { terminal });
const exitCode = await pod.run("node", ["script.js"], { terminal });
```

The [Promise] resolves to a `Process` when the program exits.

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
Loading