@freestyle-sh/with-ttyd 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -22,6 +22,10 @@ type TtydConfig = {
22
22
  title?: string;
23
23
  /** Read-only terminal (no input allowed) */
24
24
  readOnly?: boolean;
25
+ /** Xterm.js theme settings passed to ttyd client options */
26
+ theme?: Record<string, string | number | boolean>;
27
+ /** TTYD client options (xterm.js options, ttyd client flags) */
28
+ clientOptions?: Record<string, unknown>;
25
29
  };
26
30
  type ResolvedTerminalConfig = {
27
31
  port: number;
@@ -34,6 +38,8 @@ type ResolvedTerminalConfig = {
34
38
  };
35
39
  title: string;
36
40
  readOnly: boolean;
41
+ theme?: Record<string, string | number | boolean>;
42
+ clientOptions?: Record<string, unknown>;
37
43
  };
38
44
  declare class VmWebTerminal<T extends TtydConfig[] = TtydConfig[]> extends VmWith<VmWebTerminalInstance<T>> {
39
45
  private resolvedTerminals;
package/dist/index.js CHANGED
@@ -23,7 +23,9 @@ class VmWebTerminal extends VmWith {
23
23
  cwd: config.cwd ?? "/root",
24
24
  credential: config.credential,
25
25
  title: config.title ?? `terminal-${port}`,
26
- readOnly: config.readOnly ?? false
26
+ readOnly: config.readOnly ?? false,
27
+ theme: config.theme,
28
+ clientOptions: config.clientOptions
27
29
  };
28
30
  });
29
31
  }
@@ -66,6 +68,24 @@ class VmWebTerminal extends VmWith {
66
68
  } else {
67
69
  args.push(`--writable`);
68
70
  }
71
+ if (t.theme && t.clientOptions && "theme" in t.clientOptions) {
72
+ throw new Error(
73
+ `Client option conflict for terminal on port ${t.port}: theme is set in both theme and clientOptions`
74
+ );
75
+ }
76
+ const clientOptions = {
77
+ ...t.clientOptions ?? {}
78
+ };
79
+ if (t.theme) {
80
+ clientOptions.theme = t.theme;
81
+ }
82
+ for (const [key, value] of Object.entries(clientOptions)) {
83
+ if (value === void 0) {
84
+ continue;
85
+ }
86
+ const serialized = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : JSON.stringify(value);
87
+ args.push(`-t '${key}=${serialized}'`);
88
+ }
69
89
  args.push(t.command);
70
90
  return {
71
91
  name: `web-terminal-${t.port}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freestyle-sh/with-ttyd",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Web terminal for freestyle sandboxes",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "freestyle-sandboxes": "^0.1.28",
28
- "@freestyle-sh/with-pty": "^0.0.2"
28
+ "@freestyle-sh/with-pty": "^0.0.4"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "pkgroll"
package/src/index.ts CHANGED
@@ -23,6 +23,10 @@ export type TtydConfig = {
23
23
  title?: string;
24
24
  /** Read-only terminal (no input allowed) */
25
25
  readOnly?: boolean;
26
+ /** Xterm.js theme settings passed to ttyd client options */
27
+ theme?: Record<string, string | number | boolean>;
28
+ /** TTYD client options (xterm.js options, ttyd client flags) */
29
+ clientOptions?: Record<string, unknown>;
26
30
  };
27
31
 
28
32
  export type ResolvedTerminalConfig = {
@@ -33,6 +37,8 @@ export type ResolvedTerminalConfig = {
33
37
  credential?: { username: string; password: string };
34
38
  title: string;
35
39
  readOnly: boolean;
40
+ theme?: Record<string, string | number | boolean>;
41
+ clientOptions?: Record<string, unknown>;
36
42
  };
37
43
 
38
44
  // ============================================================================
@@ -73,6 +79,8 @@ export class VmWebTerminal<
73
79
  credential: config.credential,
74
80
  title: config.title ?? `terminal-${port}`,
75
81
  readOnly: config.readOnly ?? false,
82
+ theme: config.theme,
83
+ clientOptions: config.clientOptions,
76
84
  };
77
85
  });
78
86
  }
@@ -129,6 +137,33 @@ export class VmWebTerminal<
129
137
  args.push(`--writable`);
130
138
  }
131
139
 
140
+ if (t.theme && t.clientOptions && "theme" in t.clientOptions) {
141
+ throw new Error(
142
+ `Client option conflict for terminal on port ${t.port}: theme is set in both theme and clientOptions`,
143
+ );
144
+ }
145
+
146
+ const clientOptions: Record<string, unknown> = {
147
+ ...(t.clientOptions ?? {}),
148
+ };
149
+
150
+ if (t.theme) {
151
+ clientOptions.theme = t.theme;
152
+ }
153
+
154
+ for (const [key, value] of Object.entries(clientOptions)) {
155
+ if (value === undefined) {
156
+ continue;
157
+ }
158
+ const serialized =
159
+ typeof value === "string" ||
160
+ typeof value === "number" ||
161
+ typeof value === "boolean"
162
+ ? String(value)
163
+ : JSON.stringify(value);
164
+ args.push(`-t '${key}=${serialized}'`);
165
+ }
166
+
132
167
  // Shell command at the end
133
168
  args.push(t.command);
134
169