lit-shell.js 0.1.3 → 1.1.0
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/CHANGELOG.md +45 -0
- package/LICENSE +21 -21
- package/README.md +304 -304
- package/dist/client/browser-bundle.js +240 -4
- package/dist/client/browser-bundle.js.map +2 -2
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/terminal-client.d.ts +78 -3
- package/dist/client/terminal-client.d.ts.map +1 -1
- package/dist/client/terminal-client.js +237 -4
- package/dist/client/terminal-client.js.map +1 -1
- package/dist/server/circular-buffer.d.ts +55 -0
- package/dist/server/circular-buffer.d.ts.map +1 -0
- package/dist/server/circular-buffer.js +91 -0
- package/dist/server/circular-buffer.js.map +1 -0
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/session-manager.d.ts +195 -0
- package/dist/server/session-manager.d.ts.map +1 -0
- package/dist/server/session-manager.js +448 -0
- package/dist/server/session-manager.js.map +1 -0
- package/dist/server/terminal-server.d.ts +75 -5
- package/dist/server/terminal-server.d.ts.map +1 -1
- package/dist/server/terminal-server.js +496 -79
- package/dist/server/terminal-server.js.map +1 -1
- package/dist/shared/types.d.ts +179 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/ui/browser-bundle.js +240 -4
- package/dist/ui/browser-bundle.js.map +3 -3
- package/dist/ui/lit-shell-terminal.js +126 -126
- package/dist/ui/styles.js +108 -108
- package/package.json +99 -94
package/README.md
CHANGED
|
@@ -1,304 +1,304 @@
|
|
|
1
|
-
# lit-shell.js
|
|
2
|
-
|
|
3
|
-
> WebSocket-based terminal for Node.js - the truth is in your shell
|
|
4
|
-
|
|
5
|
-
A plug-and-play terminal solution for web applications. Includes a server component (node-pty), client library, and ready-to-use Lit web component.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- **Server**: WebSocket server with node-pty for real shell sessions
|
|
10
|
-
- **Client**: Lightweight WebSocket client with auto-reconnection
|
|
11
|
-
- **UI**: `<lit-shell-terminal>` Lit web component with xterm.js
|
|
12
|
-
- **Themes**: Built-in dark/light/auto theme support
|
|
13
|
-
- **Security**: Configurable shell and path allowlists
|
|
14
|
-
- **Framework Agnostic**: Works with React, Vue, Angular, Svelte, or vanilla JS
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install lit-shell.js node-pty
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Note: `node-pty` requires native compilation. See [node-pty docs](https://github.com/microsoft/node-pty) for platform-specific requirements.
|
|
23
|
-
|
|
24
|
-
## Quick Start
|
|
25
|
-
|
|
26
|
-
### Server Setup
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
import express from 'express';
|
|
30
|
-
import { createServer } from 'http';
|
|
31
|
-
import { TerminalServer } from 'lit-shell.js/server';
|
|
32
|
-
|
|
33
|
-
const app = express();
|
|
34
|
-
const server = createServer(app);
|
|
35
|
-
|
|
36
|
-
// Create and attach terminal server
|
|
37
|
-
const terminalServer = new TerminalServer({
|
|
38
|
-
allowedShells: ['/bin/bash', '/bin/zsh'],
|
|
39
|
-
allowedPaths: ['/home/user'],
|
|
40
|
-
defaultCwd: '/home/user',
|
|
41
|
-
verbose: true,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
terminalServer.attach(server);
|
|
45
|
-
|
|
46
|
-
server.listen(3000, () => {
|
|
47
|
-
console.log('Server running on http://localhost:3000');
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Client Usage (Web Component)
|
|
52
|
-
|
|
53
|
-
```html
|
|
54
|
-
<!-- Load xterm.js CSS -->
|
|
55
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.css">
|
|
56
|
-
|
|
57
|
-
<!-- Load lit-shell.js UI bundle -->
|
|
58
|
-
<script type="module" src="https://unpkg.com/lit-shell.js/dist/ui/browser-bundle.js"></script>
|
|
59
|
-
|
|
60
|
-
<!-- Use the component -->
|
|
61
|
-
<lit-shell-terminal
|
|
62
|
-
url="ws://localhost:3000/terminal"
|
|
63
|
-
theme="dark"
|
|
64
|
-
auto-connect
|
|
65
|
-
auto-spawn
|
|
66
|
-
></lit-shell-terminal>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Client Usage (JavaScript)
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
import { TerminalClient } from 'lit-shell.js/client';
|
|
73
|
-
|
|
74
|
-
const client = new TerminalClient({
|
|
75
|
-
url: 'ws://localhost:3000/terminal'
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await client.connect();
|
|
79
|
-
|
|
80
|
-
client.onData((data) => {
|
|
81
|
-
console.log('Output:', data);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
client.onExit((code) => {
|
|
85
|
-
console.log('Exited with code:', code);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await client.spawn({
|
|
89
|
-
shell: '/bin/bash',
|
|
90
|
-
cwd: '/home/user'
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
client.write('ls -la\n');
|
|
94
|
-
client.resize(120, 40);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## API Reference
|
|
98
|
-
|
|
99
|
-
### Server
|
|
100
|
-
|
|
101
|
-
#### `TerminalServer`
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
import { TerminalServer } from 'lit-shell.js/server';
|
|
105
|
-
|
|
106
|
-
const server = new TerminalServer({
|
|
107
|
-
// Allowed shells (empty = all allowed)
|
|
108
|
-
allowedShells: ['/bin/bash', '/bin/zsh', 'cmd.exe'],
|
|
109
|
-
|
|
110
|
-
// Allowed working directories (empty = all allowed)
|
|
111
|
-
allowedPaths: ['/home/user', '/var/www'],
|
|
112
|
-
|
|
113
|
-
// Default shell if not specified
|
|
114
|
-
defaultShell: '/bin/bash',
|
|
115
|
-
|
|
116
|
-
// Default working directory
|
|
117
|
-
defaultCwd: '/home/user',
|
|
118
|
-
|
|
119
|
-
// Max sessions per client (default: 5)
|
|
120
|
-
maxSessionsPerClient: 5,
|
|
121
|
-
|
|
122
|
-
// Idle timeout in ms (default: 30 minutes, 0 = disabled)
|
|
123
|
-
idleTimeout: 30 * 60 * 1000,
|
|
124
|
-
|
|
125
|
-
// WebSocket path (default: '/terminal')
|
|
126
|
-
path: '/terminal',
|
|
127
|
-
|
|
128
|
-
// Enable verbose logging
|
|
129
|
-
verbose: false,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Attach to HTTP server
|
|
133
|
-
server.attach(httpServer);
|
|
134
|
-
|
|
135
|
-
// Or start standalone
|
|
136
|
-
server.listen(3001);
|
|
137
|
-
|
|
138
|
-
// Get active sessions
|
|
139
|
-
const sessions = server.getSessions();
|
|
140
|
-
|
|
141
|
-
// Close server
|
|
142
|
-
server.close();
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### Client
|
|
146
|
-
|
|
147
|
-
#### `TerminalClient`
|
|
148
|
-
|
|
149
|
-
```typescript
|
|
150
|
-
import { TerminalClient } from 'lit-shell.js/client';
|
|
151
|
-
|
|
152
|
-
const client = new TerminalClient({
|
|
153
|
-
url: 'ws://localhost:3000/terminal',
|
|
154
|
-
reconnect: true, // Auto-reconnect (default: true)
|
|
155
|
-
maxReconnectAttempts: 10, // Max attempts (default: 10)
|
|
156
|
-
reconnectDelay: 1000, // Initial delay ms (default: 1000)
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Connect to server
|
|
160
|
-
await client.connect();
|
|
161
|
-
|
|
162
|
-
// Spawn terminal session
|
|
163
|
-
const sessionInfo = await client.spawn({
|
|
164
|
-
shell: '/bin/bash',
|
|
165
|
-
cwd: '/home/user',
|
|
166
|
-
env: { TERM: 'xterm-256color' },
|
|
167
|
-
cols: 80,
|
|
168
|
-
rows: 24,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// Write to terminal
|
|
172
|
-
client.write('echo "Hello World"\n');
|
|
173
|
-
|
|
174
|
-
// Resize terminal
|
|
175
|
-
client.resize(120, 40);
|
|
176
|
-
|
|
177
|
-
// Kill session
|
|
178
|
-
client.kill();
|
|
179
|
-
|
|
180
|
-
// Disconnect
|
|
181
|
-
client.disconnect();
|
|
182
|
-
|
|
183
|
-
// Event handlers
|
|
184
|
-
client.onConnect(() => console.log('Connected'));
|
|
185
|
-
client.onDisconnect(() => console.log('Disconnected'));
|
|
186
|
-
client.onData((data) => console.log('Data:', data));
|
|
187
|
-
client.onExit((code) => console.log('Exit:', code));
|
|
188
|
-
client.onError((err) => console.log('Error:', err));
|
|
189
|
-
client.onSpawned((info) => console.log('Spawned:', info));
|
|
190
|
-
|
|
191
|
-
// State getters
|
|
192
|
-
client.isConnected(); // boolean
|
|
193
|
-
client.hasActiveSession(); // boolean
|
|
194
|
-
client.getSessionId(); // string | null
|
|
195
|
-
client.getSessionInfo(); // SessionInfo | null
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### UI Component
|
|
199
|
-
|
|
200
|
-
#### `<lit-shell-terminal>`
|
|
201
|
-
|
|
202
|
-
```html
|
|
203
|
-
<lit-shell-terminal
|
|
204
|
-
url="ws://localhost:3000/terminal"
|
|
205
|
-
shell="/bin/bash"
|
|
206
|
-
cwd="/home/user"
|
|
207
|
-
theme="dark"
|
|
208
|
-
font-size="14"
|
|
209
|
-
font-family="Menlo, Monaco, monospace"
|
|
210
|
-
cols="80"
|
|
211
|
-
rows="24"
|
|
212
|
-
auto-connect
|
|
213
|
-
auto-spawn
|
|
214
|
-
no-header
|
|
215
|
-
></lit-shell-terminal>
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
**Attributes:**
|
|
219
|
-
|
|
220
|
-
| Attribute | Type | Default | Description |
|
|
221
|
-
|-----------|------|---------|-------------|
|
|
222
|
-
| `url` | string | `''` | WebSocket URL |
|
|
223
|
-
| `shell` | string | `''` | Shell to use |
|
|
224
|
-
| `cwd` | string | `''` | Working directory |
|
|
225
|
-
| `theme` | `'dark'` \| `'light'` \| `'auto'` | `'dark'` | Color theme |
|
|
226
|
-
| `font-size` | number | `14` | Terminal font size |
|
|
227
|
-
| `font-family` | string | `'Menlo, Monaco, ...'` | Terminal font |
|
|
228
|
-
| `cols` | number | `80` | Initial columns |
|
|
229
|
-
| `rows` | number | `24` | Initial rows |
|
|
230
|
-
| `auto-connect` | boolean | `false` | Connect on mount |
|
|
231
|
-
| `auto-spawn` | boolean | `false` | Spawn on connect |
|
|
232
|
-
| `no-header` | boolean | `false` | Hide header bar |
|
|
233
|
-
|
|
234
|
-
**Methods:**
|
|
235
|
-
|
|
236
|
-
```javascript
|
|
237
|
-
const terminal = document.querySelector('lit-shell-terminal');
|
|
238
|
-
|
|
239
|
-
await terminal.connect(); // Connect to server
|
|
240
|
-
terminal.disconnect(); // Disconnect
|
|
241
|
-
await terminal.spawn(); // Spawn session
|
|
242
|
-
terminal.kill(); // Kill session
|
|
243
|
-
terminal.clear(); // Clear display
|
|
244
|
-
terminal.write('text'); // Write to display
|
|
245
|
-
terminal.writeln('line'); // Write line to display
|
|
246
|
-
terminal.focus(); // Focus terminal
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
**Events:**
|
|
250
|
-
|
|
251
|
-
```javascript
|
|
252
|
-
terminal.addEventListener('connect', () => {});
|
|
253
|
-
terminal.addEventListener('disconnect', () => {});
|
|
254
|
-
terminal.addEventListener('spawned', (e) => console.log(e.detail.session));
|
|
255
|
-
terminal.addEventListener('exit', (e) => console.log(e.detail.exitCode));
|
|
256
|
-
terminal.addEventListener('error', (e) => console.log(e.detail.error));
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
## Theming
|
|
260
|
-
|
|
261
|
-
The component uses CSS custom properties for theming:
|
|
262
|
-
|
|
263
|
-
```css
|
|
264
|
-
lit-shell-terminal {
|
|
265
|
-
--ls-bg: #1e1e1e;
|
|
266
|
-
--ls-bg-header: #2d2d2d;
|
|
267
|
-
--ls-text: #cccccc;
|
|
268
|
-
--ls-text-muted: #808080;
|
|
269
|
-
--ls-border: #3e3e3e;
|
|
270
|
-
--ls-terminal-bg: #1e1e1e;
|
|
271
|
-
--ls-terminal-fg: #cccccc;
|
|
272
|
-
--ls-terminal-cursor: #ffffff;
|
|
273
|
-
--ls-terminal-selection: #264f78;
|
|
274
|
-
--ls-btn-bg: #3c3c3c;
|
|
275
|
-
--ls-btn-text: #cccccc;
|
|
276
|
-
--ls-btn-hover: #4a4a4a;
|
|
277
|
-
--ls-status-connected: #22c55e;
|
|
278
|
-
--ls-status-disconnected: #ef4444;
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
## Security
|
|
283
|
-
|
|
284
|
-
**Always configure security for production:**
|
|
285
|
-
|
|
286
|
-
```javascript
|
|
287
|
-
const server = new TerminalServer({
|
|
288
|
-
// Restrict allowed shells
|
|
289
|
-
allowedShells: ['/bin/bash'],
|
|
290
|
-
|
|
291
|
-
// Restrict working directories
|
|
292
|
-
allowedPaths: ['/home/app', '/var/www'],
|
|
293
|
-
|
|
294
|
-
// Limit sessions per client
|
|
295
|
-
maxSessionsPerClient: 2,
|
|
296
|
-
|
|
297
|
-
// Set idle timeout
|
|
298
|
-
idleTimeout: 10 * 60 * 1000, // 10 minutes
|
|
299
|
-
});
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
## License
|
|
303
|
-
|
|
304
|
-
MIT
|
|
1
|
+
# lit-shell.js
|
|
2
|
+
|
|
3
|
+
> WebSocket-based terminal for Node.js - the truth is in your shell
|
|
4
|
+
|
|
5
|
+
A plug-and-play terminal solution for web applications. Includes a server component (node-pty), client library, and ready-to-use Lit web component.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Server**: WebSocket server with node-pty for real shell sessions
|
|
10
|
+
- **Client**: Lightweight WebSocket client with auto-reconnection
|
|
11
|
+
- **UI**: `<lit-shell-terminal>` Lit web component with xterm.js
|
|
12
|
+
- **Themes**: Built-in dark/light/auto theme support
|
|
13
|
+
- **Security**: Configurable shell and path allowlists
|
|
14
|
+
- **Framework Agnostic**: Works with React, Vue, Angular, Svelte, or vanilla JS
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install lit-shell.js node-pty
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Note: `node-pty` requires native compilation. See [node-pty docs](https://github.com/microsoft/node-pty) for platform-specific requirements.
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### Server Setup
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
import express from 'express';
|
|
30
|
+
import { createServer } from 'http';
|
|
31
|
+
import { TerminalServer } from 'lit-shell.js/server';
|
|
32
|
+
|
|
33
|
+
const app = express();
|
|
34
|
+
const server = createServer(app);
|
|
35
|
+
|
|
36
|
+
// Create and attach terminal server
|
|
37
|
+
const terminalServer = new TerminalServer({
|
|
38
|
+
allowedShells: ['/bin/bash', '/bin/zsh'],
|
|
39
|
+
allowedPaths: ['/home/user'],
|
|
40
|
+
defaultCwd: '/home/user',
|
|
41
|
+
verbose: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
terminalServer.attach(server);
|
|
45
|
+
|
|
46
|
+
server.listen(3000, () => {
|
|
47
|
+
console.log('Server running on http://localhost:3000');
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Client Usage (Web Component)
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<!-- Load xterm.js CSS -->
|
|
55
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.css">
|
|
56
|
+
|
|
57
|
+
<!-- Load lit-shell.js UI bundle -->
|
|
58
|
+
<script type="module" src="https://unpkg.com/lit-shell.js/dist/ui/browser-bundle.js"></script>
|
|
59
|
+
|
|
60
|
+
<!-- Use the component -->
|
|
61
|
+
<lit-shell-terminal
|
|
62
|
+
url="ws://localhost:3000/terminal"
|
|
63
|
+
theme="dark"
|
|
64
|
+
auto-connect
|
|
65
|
+
auto-spawn
|
|
66
|
+
></lit-shell-terminal>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Client Usage (JavaScript)
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import { TerminalClient } from 'lit-shell.js/client';
|
|
73
|
+
|
|
74
|
+
const client = new TerminalClient({
|
|
75
|
+
url: 'ws://localhost:3000/terminal'
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await client.connect();
|
|
79
|
+
|
|
80
|
+
client.onData((data) => {
|
|
81
|
+
console.log('Output:', data);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
client.onExit((code) => {
|
|
85
|
+
console.log('Exited with code:', code);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await client.spawn({
|
|
89
|
+
shell: '/bin/bash',
|
|
90
|
+
cwd: '/home/user'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
client.write('ls -la\n');
|
|
94
|
+
client.resize(120, 40);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API Reference
|
|
98
|
+
|
|
99
|
+
### Server
|
|
100
|
+
|
|
101
|
+
#### `TerminalServer`
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { TerminalServer } from 'lit-shell.js/server';
|
|
105
|
+
|
|
106
|
+
const server = new TerminalServer({
|
|
107
|
+
// Allowed shells (empty = all allowed)
|
|
108
|
+
allowedShells: ['/bin/bash', '/bin/zsh', 'cmd.exe'],
|
|
109
|
+
|
|
110
|
+
// Allowed working directories (empty = all allowed)
|
|
111
|
+
allowedPaths: ['/home/user', '/var/www'],
|
|
112
|
+
|
|
113
|
+
// Default shell if not specified
|
|
114
|
+
defaultShell: '/bin/bash',
|
|
115
|
+
|
|
116
|
+
// Default working directory
|
|
117
|
+
defaultCwd: '/home/user',
|
|
118
|
+
|
|
119
|
+
// Max sessions per client (default: 5)
|
|
120
|
+
maxSessionsPerClient: 5,
|
|
121
|
+
|
|
122
|
+
// Idle timeout in ms (default: 30 minutes, 0 = disabled)
|
|
123
|
+
idleTimeout: 30 * 60 * 1000,
|
|
124
|
+
|
|
125
|
+
// WebSocket path (default: '/terminal')
|
|
126
|
+
path: '/terminal',
|
|
127
|
+
|
|
128
|
+
// Enable verbose logging
|
|
129
|
+
verbose: false,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Attach to HTTP server
|
|
133
|
+
server.attach(httpServer);
|
|
134
|
+
|
|
135
|
+
// Or start standalone
|
|
136
|
+
server.listen(3001);
|
|
137
|
+
|
|
138
|
+
// Get active sessions
|
|
139
|
+
const sessions = server.getSessions();
|
|
140
|
+
|
|
141
|
+
// Close server
|
|
142
|
+
server.close();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Client
|
|
146
|
+
|
|
147
|
+
#### `TerminalClient`
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { TerminalClient } from 'lit-shell.js/client';
|
|
151
|
+
|
|
152
|
+
const client = new TerminalClient({
|
|
153
|
+
url: 'ws://localhost:3000/terminal',
|
|
154
|
+
reconnect: true, // Auto-reconnect (default: true)
|
|
155
|
+
maxReconnectAttempts: 10, // Max attempts (default: 10)
|
|
156
|
+
reconnectDelay: 1000, // Initial delay ms (default: 1000)
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Connect to server
|
|
160
|
+
await client.connect();
|
|
161
|
+
|
|
162
|
+
// Spawn terminal session
|
|
163
|
+
const sessionInfo = await client.spawn({
|
|
164
|
+
shell: '/bin/bash',
|
|
165
|
+
cwd: '/home/user',
|
|
166
|
+
env: { TERM: 'xterm-256color' },
|
|
167
|
+
cols: 80,
|
|
168
|
+
rows: 24,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Write to terminal
|
|
172
|
+
client.write('echo "Hello World"\n');
|
|
173
|
+
|
|
174
|
+
// Resize terminal
|
|
175
|
+
client.resize(120, 40);
|
|
176
|
+
|
|
177
|
+
// Kill session
|
|
178
|
+
client.kill();
|
|
179
|
+
|
|
180
|
+
// Disconnect
|
|
181
|
+
client.disconnect();
|
|
182
|
+
|
|
183
|
+
// Event handlers
|
|
184
|
+
client.onConnect(() => console.log('Connected'));
|
|
185
|
+
client.onDisconnect(() => console.log('Disconnected'));
|
|
186
|
+
client.onData((data) => console.log('Data:', data));
|
|
187
|
+
client.onExit((code) => console.log('Exit:', code));
|
|
188
|
+
client.onError((err) => console.log('Error:', err));
|
|
189
|
+
client.onSpawned((info) => console.log('Spawned:', info));
|
|
190
|
+
|
|
191
|
+
// State getters
|
|
192
|
+
client.isConnected(); // boolean
|
|
193
|
+
client.hasActiveSession(); // boolean
|
|
194
|
+
client.getSessionId(); // string | null
|
|
195
|
+
client.getSessionInfo(); // SessionInfo | null
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### UI Component
|
|
199
|
+
|
|
200
|
+
#### `<lit-shell-terminal>`
|
|
201
|
+
|
|
202
|
+
```html
|
|
203
|
+
<lit-shell-terminal
|
|
204
|
+
url="ws://localhost:3000/terminal"
|
|
205
|
+
shell="/bin/bash"
|
|
206
|
+
cwd="/home/user"
|
|
207
|
+
theme="dark"
|
|
208
|
+
font-size="14"
|
|
209
|
+
font-family="Menlo, Monaco, monospace"
|
|
210
|
+
cols="80"
|
|
211
|
+
rows="24"
|
|
212
|
+
auto-connect
|
|
213
|
+
auto-spawn
|
|
214
|
+
no-header
|
|
215
|
+
></lit-shell-terminal>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Attributes:**
|
|
219
|
+
|
|
220
|
+
| Attribute | Type | Default | Description |
|
|
221
|
+
|-----------|------|---------|-------------|
|
|
222
|
+
| `url` | string | `''` | WebSocket URL |
|
|
223
|
+
| `shell` | string | `''` | Shell to use |
|
|
224
|
+
| `cwd` | string | `''` | Working directory |
|
|
225
|
+
| `theme` | `'dark'` \| `'light'` \| `'auto'` | `'dark'` | Color theme |
|
|
226
|
+
| `font-size` | number | `14` | Terminal font size |
|
|
227
|
+
| `font-family` | string | `'Menlo, Monaco, ...'` | Terminal font |
|
|
228
|
+
| `cols` | number | `80` | Initial columns |
|
|
229
|
+
| `rows` | number | `24` | Initial rows |
|
|
230
|
+
| `auto-connect` | boolean | `false` | Connect on mount |
|
|
231
|
+
| `auto-spawn` | boolean | `false` | Spawn on connect |
|
|
232
|
+
| `no-header` | boolean | `false` | Hide header bar |
|
|
233
|
+
|
|
234
|
+
**Methods:**
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
const terminal = document.querySelector('lit-shell-terminal');
|
|
238
|
+
|
|
239
|
+
await terminal.connect(); // Connect to server
|
|
240
|
+
terminal.disconnect(); // Disconnect
|
|
241
|
+
await terminal.spawn(); // Spawn session
|
|
242
|
+
terminal.kill(); // Kill session
|
|
243
|
+
terminal.clear(); // Clear display
|
|
244
|
+
terminal.write('text'); // Write to display
|
|
245
|
+
terminal.writeln('line'); // Write line to display
|
|
246
|
+
terminal.focus(); // Focus terminal
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Events:**
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
terminal.addEventListener('connect', () => {});
|
|
253
|
+
terminal.addEventListener('disconnect', () => {});
|
|
254
|
+
terminal.addEventListener('spawned', (e) => console.log(e.detail.session));
|
|
255
|
+
terminal.addEventListener('exit', (e) => console.log(e.detail.exitCode));
|
|
256
|
+
terminal.addEventListener('error', (e) => console.log(e.detail.error));
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Theming
|
|
260
|
+
|
|
261
|
+
The component uses CSS custom properties for theming:
|
|
262
|
+
|
|
263
|
+
```css
|
|
264
|
+
lit-shell-terminal {
|
|
265
|
+
--ls-bg: #1e1e1e;
|
|
266
|
+
--ls-bg-header: #2d2d2d;
|
|
267
|
+
--ls-text: #cccccc;
|
|
268
|
+
--ls-text-muted: #808080;
|
|
269
|
+
--ls-border: #3e3e3e;
|
|
270
|
+
--ls-terminal-bg: #1e1e1e;
|
|
271
|
+
--ls-terminal-fg: #cccccc;
|
|
272
|
+
--ls-terminal-cursor: #ffffff;
|
|
273
|
+
--ls-terminal-selection: #264f78;
|
|
274
|
+
--ls-btn-bg: #3c3c3c;
|
|
275
|
+
--ls-btn-text: #cccccc;
|
|
276
|
+
--ls-btn-hover: #4a4a4a;
|
|
277
|
+
--ls-status-connected: #22c55e;
|
|
278
|
+
--ls-status-disconnected: #ef4444;
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Security
|
|
283
|
+
|
|
284
|
+
**Always configure security for production:**
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
const server = new TerminalServer({
|
|
288
|
+
// Restrict allowed shells
|
|
289
|
+
allowedShells: ['/bin/bash'],
|
|
290
|
+
|
|
291
|
+
// Restrict working directories
|
|
292
|
+
allowedPaths: ['/home/app', '/var/www'],
|
|
293
|
+
|
|
294
|
+
// Limit sessions per client
|
|
295
|
+
maxSessionsPerClient: 2,
|
|
296
|
+
|
|
297
|
+
// Set idle timeout
|
|
298
|
+
idleTimeout: 10 * 60 * 1000, // 10 minutes
|
|
299
|
+
});
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## License
|
|
303
|
+
|
|
304
|
+
MIT
|