Skip to content

Commit eff8d66

Browse files
authored
changed format references (#206)
1 parent bf90d8a commit eff8d66

File tree

13 files changed

+153
-124
lines changed

13 files changed

+153
-124
lines changed

content/blog/cx-1.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ cx.setConsole(document.getElementById("console"));
135135
await cx.run("/usr/bin/python3", []);
136136
```
137137

138-
That’s it. The user will now be able to try Python code in the browser. The basic _builtin console_ is sufficient for quick experimentation, but you should consider using the full-fledged [xterm.js](https://xtermjs.org/) terminal emulator for better results. You can do so using the [`cx.setCustomConsole` API](https://cheerpx.io/docs/reference/CheerpX-Linux-setCustomConsole)
138+
That’s it. The user will now be able to try Python code in the browser. The basic _builtin console_ is sufficient for quick experimentation, but you should consider using the full-fledged [xterm.js](https://xtermjs.org/) terminal emulator for better results. You can do so using the [`cx.setCustomConsole` API](/docs/reference/CheerpX.Linux/setCustomConsole)
139139

140140
![Python in the browser](./images/cx10_python.png)
141141

sites/cheerpx/src/content/docs/10-getting-started/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CheerpX is also available as an ES6 JavaScript module. If you prefer to use the
3333
3434
## 2. Create an application instance
3535

36-
To start using CheerpX, create an instance by calling the [`CheerpX.Linux.create`](/docs/reference/CheerpX-Linux-create) method, which is available globally once the script is included.
36+
To start using CheerpX, create an instance by calling the [`CheerpX.Linux.create`](/docs/reference/CheerpX.Linux/create) method, which is available globally once the script is included.
3737

3838
The example below demonstrates how to set up the file system and devices using [WebVM's `debian_large` image](https://github.com/leaningtech/webvm/blob/main/dockerfiles/debian_large), but you can also [create your own images](/docs/guides/custom-images).
3939

@@ -98,15 +98,15 @@ During development, you don't need to use HTTPS if you're using `localhost` as t
9898
9999
## 4. Attach and interact with a console
100100

101-
To be able to see the output printed by the program, use [`setConsole`](/docs/reference/CheerpX-Linux-setConsole) method to use an HTML element as a console. Add the following code at the very end of the `<script>` tag in the example above.
101+
To be able to see the output printed by the program, use [`setConsole`](/docs/reference/CheerpX.Linux/setConsole) method to use an HTML element as a console. Add the following code at the very end of the `<script>` tag in the example above.
102102

103103
```js
104104
cx.setConsole(document.getElementById("console"));
105105
```
106106

107107
## 5. Run an executable
108108

109-
Executables are started using the the [`run`](/docs/reference/CheerpX-Linux-run) API. Add the following code to the `<script>` tag to run a full-featured shell in your browser.
109+
Executables are started using the the [`run`](/docs/reference/CheerpX.Linux/run) API. Add the following code to the `<script>` tag to run a full-featured shell in your browser.
110110

111111
```js
112112
await cx.run("/bin/bash", ["--login"], {

sites/cheerpx/src/content/docs/11-guides/Networking.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ What is happening here?
132132

133133
Headscale is an open-source and self-hosted implementation of the Tailscale control server. The upstream version of Headscale does not yet properly support the WebSocket transport. For the time being, please use [our fork](https://github.com/leaningtech/headscale).
134134

135-
[controlUrl]: /docs/reference/CheerpX-Linux-create#controlurl
136-
[authKey]: /docs/reference/CheerpX-Linux-create#authkey
137-
[stateUpdateCb]: /docs/reference/CheerpX-Linux-create#stateupdatecb
138-
[netmapUpdateCb]: /docs/reference/CheerpX-Linux-create#netmapupdatecb
139-
[loginUrlCb]: /docs/reference/CheerpX-Linux-create#loginurlcb
135+
[controlUrl]: /docs/reference/CheerpX.Linux/create#controlurl
136+
[authKey]: /docs/reference/CheerpX.Linux/create#authkey
137+
[stateUpdateCb]: /docs/reference/CheerpX.Linux/create#stateupdatecb
138+
[netmapUpdateCb]: /docs/reference/CheerpX.Linux/create#netmapupdatecb
139+
[loginUrlCb]: /docs/reference/CheerpX.Linux/create#loginurlcb

sites/cheerpx/src/content/docs/11-guides/input-output.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CheerpX provides two options for handling console input and output: a _built-in_
1111

1212
CheerpX comes with a _built-in_ console that mimics traditional console behavior. The _built-in_ console supports standard input and output over a HTML `<pre>` (pre-formatted) element. Keyboard input works provided the element is in focus.
1313

14-
For more information, visit the [CheerpX console] reference.
14+
For more information, visit the [CheerpX console](/docs/reference/CheerpX.Linux/setConsole) reference.
1515

1616
### Custom console
1717

@@ -39,7 +39,7 @@ for (let i = 0; i < encodedStr.length; i++) {
3939
}
4040
```
4141

42-
For more details on customizing the console, see [CheerpX Custom console].
42+
For more details on customizing the console, see [CheerpX Custom console](/docs/reference/CheerpX.Linux/setCustomConsole).
4343

4444
## Reading Files Using IDBDevice and Redirecting Output
4545

@@ -95,8 +95,6 @@ The `DataDevice` API exposes JavaScript data via the filesystem. This device pro
9595
For more information, see the [CheerpX DataDevice].
9696

9797
[CheerpX documentations]: https://cheerpx.io/docs/overview
98-
[CheerpX console]: https://cheerpx.io/docs/reference/CheerpX-Linux-setConsole
99-
[CheerpX Custom console]: https://cheerpx.io/docs/reference/CheerpX-Linux-setCustomConsole
10098
[CheerpX DataDevice]: https://cheerpx.io/docs/guides/File-System-support#datadevice
10199
[CheerpX IDBDevice]: https://cheerpx.io/docs/guides/File-System-support#idbdevice
102100
[Frequently Asked Questions]: https://cheerpx.io/docs/faq

sites/cheerpx/src/content/docs/12-reference/01-CheerpX-Linux-run.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

sites/cheerpx/src/content/docs/12-reference/00-CheerpX-Linux-create.md renamed to sites/cheerpx/src/content/docs/12-reference/CheerpX.Linux/00-create.md

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: CheerpX.Linux.create
2+
title: create
33
description: Create a CheerpX application instance
44
---
55

@@ -12,28 +12,6 @@ namespace CheerpX {
1212
}): Promise<CheerpX.Linux>;
1313
}
1414
}
15-
16-
interface MountPointConfiguration {
17-
// Specifies the filesystem type
18-
// 'ext2' for Linux ext2
19-
// 'dir' for a hierarchical file system
20-
// 'devs' for device files
21-
// 'proc' for process info files.
22-
type: "ext2" | "dir" | "devs" | "proc";
23-
24-
// First mount must be "/" (root)
25-
path: string;
26-
// Can be one of: overlayDevice / webDevice / dataDevice / idbDevice
27-
dev: CheerpX.Device;
28-
}
29-
30-
interface NetworkInterface {
31-
authKey?: string;
32-
controlUrl?: string;
33-
loginUrlCb?: (url: string) => void;
34-
stateUpdateCb?: (state: number) => void;
35-
netmapUpdateCb?: (map: any) => void;
36-
}
3715
```
3816

3917
## Parameters
@@ -44,6 +22,8 @@ interface NetworkInterface {
4422

4523
`CheerpX.Linux.create` returns a [Promise] which is resolved once the CheerpX Linux environment is fully initialized and ready to use. The resolved value is a `CheerpX.Linux` instance that provides methods for interacting with the CheerpX environment.
4624

25+
Additionally, this instance allows you to register and monitor system events, such as CPU and disk activity. For more details, see the [`event callbacks`](/docs/reference/CheerpX.Linux/event%20callbacks) page.
26+
4727
## Options
4828

4929
A description of each `CheerpX.Linux.create` option with brief examples are given below.
@@ -56,6 +36,24 @@ mounts?: MountPointConfiguration[];
5636

5737
This option configures the filesystems that will be available in the CheerpX environment. Each mount point configures a device and specifies where it should be accessible within the virtual filesystem.
5838

39+
Each mount configuration must follow this structure:
40+
41+
```ts
42+
interface MountPointConfiguration {
43+
// Specifies the filesystem type
44+
// 'ext2' for Linux ext2
45+
// 'dir' for a hierarchical file system
46+
// 'devs' for device files
47+
// 'proc' for process info files.
48+
type: "ext2" | "dir" | "devs" | "proc";
49+
50+
// First mount must be "/" (root)
51+
path: string;
52+
// Can be one of: overlayDevice / webDevice / dataDevice / idbDevice
53+
dev: CheerpX.Device;
54+
}
55+
```
56+
5957
Example:
6058

6159
```js
@@ -68,17 +66,31 @@ const cx = await CheerpX.Linux.create({
6866
```
6967

7068
> [!note] Note
71-
> CheerpX supports a variety of backends, designed to provide access to HTTP resources, IndexedDB-base persistent storage and data from JavaScript. Complete Ext2 filesystems are also supported on top of block devices. For detailed information, including usage examples and full APIs, please refer to the [Files and filesystems](/docs/guides/File-System-support) guide.
69+
> CheerpX supports a variety of backends, designed to provide access to HTTP resources, IndexedDB-based persistent storage and data from JavaScript. Complete Ext2 filesystems are also supported on top of block devices. For detailed information, including usage examples and full APIs, please refer to the [Files and filesystems](/docs/guides/File-System-support) guide.
7270
7371
### `networkInterface`
7472

7573
```ts
7674
networkInterface?: NetworkInterface;
7775
```
7876

79-
This option configures network settings, which allows CheerpX to communicate over networks. For more detailed information about how CheerpX handles networking, including the use of Tailscale and overcoming browser limitations, see the [Networking](/docs/guides/Networking) guide.
77+
This option configures network settings, which allows CheerpX to communicate over networks.
8078

81-
### `authKey`
79+
Each Configuration must follow this structure:
80+
81+
```ts
82+
interface NetworkInterface {
83+
authKey?: string;
84+
controlUrl?: string;
85+
loginUrlCb?: (url: string) => void;
86+
stateUpdateCb?: (state: number) => void;
87+
netmapUpdateCb?: (map: any) => void;
88+
}
89+
```
90+
91+
The following sections provide details on each available option within `NetworkInterface`, along with example usages.
92+
93+
#### `authKey`
8294

8395
```ts
8496
authKey?: string;
@@ -95,7 +107,7 @@ const cx = await CheerpX.Linux.create({
95107
});
96108
```
97109

98-
### `controlUrl`
110+
#### `controlUrl`
99111

100112
```ts
101113
controlUrl?: string;
@@ -112,7 +124,7 @@ const cx = await CheerpX.Linux.create({
112124
});
113125
```
114126

115-
### `loginUrlCb`
127+
#### `loginUrlCb`
116128

117129
```ts
118130
loginUrlCb?: (url: string) => void;
@@ -135,7 +147,7 @@ function loginUrlCb(url) {
135147
}
136148
```
137149

138-
### stateUpdateCb
150+
#### `stateUpdateCb`
139151

140152
```ts
141153
stateUpdateCb?: (state: number) => void;
@@ -158,7 +170,7 @@ function stateUpdateCb(state) {
158170
}
159171
```
160172

161-
### netmapUpdateCb
173+
#### `netmapUpdateCb`
162174

163175
```ts
164176
netmapUpdateCb?: (map: any) => void;
@@ -180,4 +192,6 @@ function netmapUpdateCb(map) {
180192
}
181193
```
182194

195+
For more detailed information about how CheerpX handles networking, including the use of Tailscale and overcoming browser limitations, see the [Networking](/docs/guides/Networking) guide.
196+
183197
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: run
3+
description: Executes a command within the CheerpX Linux environment.
4+
---
5+
6+
```ts
7+
namespace CheerpX {
8+
class Linux {
9+
async run(
10+
fileName: string,
11+
args: string[],
12+
options?: {
13+
env?: string[]; // Environment variables in the form "KEY=VALUE"
14+
cwd?: string; // Current working directory
15+
uid?: number; // User ID
16+
gid?: number; // Group ID
17+
}
18+
): Promise<{ status: number }>;
19+
}
20+
}
21+
```
22+
23+
## Parameters
24+
25+
- **fileName (`string`)** - The path to the executable file.
26+
- **args (`string[]`)** - Arguments to pass to the executable.
27+
- **options (`object`, optional)** - Used to configure different settings of the runtime in the form {`option: "value"`}. This can include environment variables, working directory, user ID, group ID, and other related options.
28+
29+
## Options
30+
31+
- **env (`string[]`)**: Environment variables for the process.
32+
- **cwd (`string`)**: The working directory from which the command will be run.
33+
- **uid (`number`)**: User ID under which the command will be executed.
34+
- **gid (`number`)**: Group ID under which the command will be executed.
35+
36+
## Returns
37+
38+
`CheerpX.Linux.run` returns a [Promise] which resolves when the process terminates. The returned object contains the exit status.
39+
40+
### Examples
41+
42+
**1. Run a bash script**
43+
44+
Run a script that prints numbers from 1 to 5:
45+
46+
```js
47+
const result = await cx.run("/bin/bash", [
48+
"-c",
49+
"for i in {1..5}; do echo $i; done",
50+
]);
51+
console.log("Bash script exit status:", result.status);
52+
```
53+
54+
**2. Run a shell command with custom environment**
55+
56+
Execute a shell session with specified environment variables, a working directory, and specific user/group IDs:
57+
58+
```js
59+
await cx.run("/bin/bash", ["--login"], {
60+
env: [
61+
"HOME=/home/user", // User's home directory
62+
"USER=user", // Username
63+
"SHELL=/bin/bash", // Default shell
64+
"EDITOR=vim", // Default editor
65+
"LANG=en_US.UTF-8", // Language setting
66+
"LC_ALL=C", // Locale
67+
],
68+
cwd: "/home/user", // Set working directory
69+
uid: 1000, // Set user ID
70+
gid: 1000, // Set group ID
71+
});
72+
```
73+
74+
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

sites/cheerpx/src/content/docs/12-reference/10-CheerpX-Linux-setConsole.md renamed to sites/cheerpx/src/content/docs/12-reference/CheerpX.Linux/02-setConsole.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
title: CheerpX.Linux#setConsole
2+
title: setConsole
33
description: Configure an HTML element as the console output for CheerpX Linux applications
44
---
55

6-
Sets up an HTML element to be used as the console for the application. The element will be focused and styled.
7-
86
```ts
97
namespace CheerpX {
108
class Linux {
@@ -30,7 +28,3 @@ namespace CheerpX {
3028
cx.setConsole(document.getElementById("console"));
3129
</script>
3230
```
33-
34-
## See also
35-
36-
If you'd prefer to capture output yourself, use [`setCustomConsole`](/docs/reference/CheerpX-Linux-setCustomConsole).

sites/cheerpx/src/content/docs/12-reference/12-CheerpX-Linux-setActivateConsole.md renamed to sites/cheerpx/src/content/docs/12-reference/CheerpX.Linux/03-setActivateConsole.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: CheerpX.Linux#setActivateConsole
2+
title: setActivateConsole
33
description: Manage virtual terminal switching within CheerpX
44
---
55

0 commit comments

Comments
 (0)