vterm.js 0.0.1 → 0.1.2
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/README.md +185 -0
- package/package.json +35 -3
- package/src/index.ts +8 -0
- package/src/screen.ts +1689 -0
package/README.md
CHANGED
|
@@ -1 +1,186 @@
|
|
|
1
1
|
# vterm.js
|
|
2
|
+
|
|
3
|
+
Modern terminal emulator — full VT/ECMA-48/xterm standards coverage. Pure TypeScript, zero dependencies.
|
|
4
|
+
|
|
5
|
+
Part of the [vterm](https://github.com/beorn/vterm) monorepo.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **All SGR attributes** — bold, faint, italic, blink, overline, strikethrough, inverse, hidden
|
|
10
|
+
- **Underline styles** — single, double, curly, dotted, dashed (SGR 4:0–4:5)
|
|
11
|
+
- **Full color support** — 16-color, 256-color, 24-bit truecolor for foreground, background, and underline
|
|
12
|
+
- **Cursor shapes** — block, underline, bar with blinking variants (DECSCUSR)
|
|
13
|
+
- **Cursor control** — CUP, CUU/CUD/CUF/CUB, CHA, CNL, CPL, HVP, save/restore (DECSC/DECRC)
|
|
14
|
+
- **Erase operations** — ED 0/1/2/3, EL 0/1/2, ECH
|
|
15
|
+
- **Editing operations** — ICH, DCH, IL, DL, REP (repeat last character)
|
|
16
|
+
- **Scroll regions** — DECSTBM, SU, SD with content preservation
|
|
17
|
+
- **DEC private modes** — alternate screen, auto-wrap, origin, insert, reverse video, bracketed paste
|
|
18
|
+
- **Mouse tracking** — X10, normal, button, any-event, SGR format
|
|
19
|
+
- **Focus tracking** — mode 1004
|
|
20
|
+
- **Synchronized output** — mode 2026
|
|
21
|
+
- **Application cursor keys & keypad**
|
|
22
|
+
- **OSC sequences** — window title (OSC 0/2), hyperlinks (OSC 8), clipboard (OSC 52), colors
|
|
23
|
+
- **DCS sequences** — consumed and ignored, XTVERSION response
|
|
24
|
+
- **Device attributes** — DA1/DA2/DA3 responses
|
|
25
|
+
- **Device status reports** — DSR responses
|
|
26
|
+
- **Mode reporting** — DECRPM
|
|
27
|
+
- **Character sets** — DEC Special Graphics (box drawing), UTF-8
|
|
28
|
+
- **Soft terminal reset** — DECSTR
|
|
29
|
+
- **Scrollback buffer** with configurable limit
|
|
30
|
+
- **Wide character support** — CJK, emoji ZWJ sequences, regional indicators, VS-16
|
|
31
|
+
- **Full C0/C1 control code handling**
|
|
32
|
+
- **Zero dependencies** — works in Bun, Node.js, and browsers
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install vterm.js
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Basic
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createVtermScreen } from "vterm.js"
|
|
46
|
+
|
|
47
|
+
const screen = createVtermScreen({ cols: 80, rows: 24 })
|
|
48
|
+
screen.process(new TextEncoder().encode("Hello, \x1b[1mBold\x1b[0m World!"))
|
|
49
|
+
|
|
50
|
+
console.log(screen.getText()) // "Hello, Bold World!"
|
|
51
|
+
console.log(screen.getCell(0, 7).bold) // true
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Cursor shapes
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// Set cursor to blinking bar
|
|
58
|
+
screen.process(new TextEncoder().encode("\x1b[5 q"))
|
|
59
|
+
console.log(screen.getCursorShape()) // "bar"
|
|
60
|
+
console.log(screen.getCursorBlinking()) // true
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Hyperlinks (OSC 8)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
screen.process(new TextEncoder().encode("\x1b]8;;https://example.com\x1b\\Click here\x1b]8;;\x1b\\"))
|
|
67
|
+
console.log(screen.getCell(0, 0).url) // "https://example.com"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Device attribute responses
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const screen = createVtermScreen({
|
|
74
|
+
cols: 80,
|
|
75
|
+
rows: 24,
|
|
76
|
+
onResponse: (data) => {
|
|
77
|
+
// Write response back to PTY
|
|
78
|
+
pty.write(data)
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// When the screen receives DA1 (\x1b[c), it calls onResponse
|
|
83
|
+
// with the appropriate response string
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Extended SGR
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// Bold + curly underline + truecolor orange foreground + underline color
|
|
90
|
+
screen.process(new TextEncoder().encode("\x1b[1;4:3;38;2;255;100;0;58;2;0;150;255mStyled\x1b[0m"))
|
|
91
|
+
|
|
92
|
+
const cell = screen.getCell(0, 0)
|
|
93
|
+
console.log(cell.bold) // true
|
|
94
|
+
console.log(cell.underline) // "curly"
|
|
95
|
+
console.log(cell.fg) // { r: 255, g: 100, b: 0 }
|
|
96
|
+
console.log(cell.underlineColor) // { r: 0, g: 150, b: 255 }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## API
|
|
100
|
+
|
|
101
|
+
### `createVtermScreen(options)`
|
|
102
|
+
|
|
103
|
+
| Option | Type | Default | Description |
|
|
104
|
+
|--------|------|---------|-------------|
|
|
105
|
+
| `cols` | `number` | `80` | Terminal width |
|
|
106
|
+
| `rows` | `number` | `24` | Terminal height |
|
|
107
|
+
| `scrollbackLimit` | `number` | `1000` | Max scrollback lines |
|
|
108
|
+
| `onResponse` | `(data: string) => void` | — | Callback for DA1/DA2/DSR responses |
|
|
109
|
+
|
|
110
|
+
### Screen methods
|
|
111
|
+
|
|
112
|
+
| Method | Description |
|
|
113
|
+
|--------|-------------|
|
|
114
|
+
| `process(data: Uint8Array)` | Feed raw terminal data |
|
|
115
|
+
| `getText()` | Get all text (scrollback + screen) |
|
|
116
|
+
| `getTextRange(sr, sc, er, ec)` | Get text in a range |
|
|
117
|
+
| `getLine(row)` | Get cells for a row |
|
|
118
|
+
| `getCell(row, col)` | Get a single cell |
|
|
119
|
+
| `getCursorPosition()` | Get cursor `{ x, y }` |
|
|
120
|
+
| `getCursorVisible()` | Check cursor visibility |
|
|
121
|
+
| `getCursorShape()` | Get cursor shape: `"block"`, `"underline"`, or `"bar"` |
|
|
122
|
+
| `getCursorBlinking()` | Check if cursor is blinking |
|
|
123
|
+
| `getMode(mode)` | Check terminal mode |
|
|
124
|
+
| `getTitle()` | Get window title |
|
|
125
|
+
| `getScrollbackLength()` | Number of scrollback lines |
|
|
126
|
+
| `getViewportOffset()` | Current viewport scroll offset |
|
|
127
|
+
| `scrollViewport(delta)` | Scroll viewport |
|
|
128
|
+
| `resize(cols, rows)` | Resize terminal |
|
|
129
|
+
| `reset()` | Reset to initial state |
|
|
130
|
+
|
|
131
|
+
### Cell properties
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface ScreenCell {
|
|
135
|
+
char: string
|
|
136
|
+
fg: CellColor | null // { r, g, b }
|
|
137
|
+
bg: CellColor | null
|
|
138
|
+
bold: boolean
|
|
139
|
+
faint: boolean
|
|
140
|
+
italic: boolean
|
|
141
|
+
underline: "none" | "single" | "double" | "curly" | "dotted" | "dashed"
|
|
142
|
+
underlineColor: CellColor | null
|
|
143
|
+
overline: boolean
|
|
144
|
+
strikethrough: boolean
|
|
145
|
+
inverse: boolean
|
|
146
|
+
hidden: boolean
|
|
147
|
+
blink: boolean
|
|
148
|
+
wide: boolean
|
|
149
|
+
url: string | null // OSC 8 hyperlink
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## vs vt100.js
|
|
154
|
+
|
|
155
|
+
| Feature | vt100.js | vterm.js |
|
|
156
|
+
|---------|----------|---------|
|
|
157
|
+
| SGR basics (bold, italic, underline, colors) | Yes | Yes |
|
|
158
|
+
| Underline styles (curly, dotted, dashed) | Yes | Yes |
|
|
159
|
+
| Underline color | No | Yes |
|
|
160
|
+
| Blink, overline | No | Yes |
|
|
161
|
+
| Cursor shapes (DECSCUSR) | No | Yes |
|
|
162
|
+
| OSC 8 hyperlinks | No | Yes |
|
|
163
|
+
| DA1/DA2/DA3 responses | No | Yes |
|
|
164
|
+
| DSR/DECRPM responses | No | Yes |
|
|
165
|
+
| Mouse tracking | No | Yes |
|
|
166
|
+
| Focus tracking | No | Yes |
|
|
167
|
+
| Synchronized output | No | Yes |
|
|
168
|
+
| DEC Special Graphics | No | Yes |
|
|
169
|
+
| REP (repeat character) | No | Yes |
|
|
170
|
+
| DECSTR (soft reset) | No | Yes |
|
|
171
|
+
| DCS sequences | No | Yes |
|
|
172
|
+
| Package size | Smaller | Larger |
|
|
173
|
+
|
|
174
|
+
**Use vt100.js** when you want fast and simple — it covers ~90% of real-world terminal usage.
|
|
175
|
+
|
|
176
|
+
**Use vterm.js** when you need everything — 100% coverage of the [terminfo.dev](https://terminfo.dev) feature matrix.
|
|
177
|
+
|
|
178
|
+
## See also
|
|
179
|
+
|
|
180
|
+
- [vt100.js](../vt100/) — VT100-era emulator (smaller, focused)
|
|
181
|
+
- [Termless](https://termless.dev) — headless terminal testing
|
|
182
|
+
- [Terminfo.dev](https://terminfo.dev) — terminal feature support tables
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vterm.js",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Modern terminal emulator — full VT/ECMA-48/xterm standards coverage. Pure TypeScript, zero dependencies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ansi",
|
|
7
|
+
"ecma-48",
|
|
8
|
+
"headless",
|
|
9
|
+
"terminal-emulator",
|
|
10
|
+
"tui",
|
|
11
|
+
"typescript",
|
|
12
|
+
"vt",
|
|
13
|
+
"vterm",
|
|
14
|
+
"xterm",
|
|
15
|
+
"zero-dependency"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/beorn/vterm/tree/main/packages/vterm",
|
|
18
|
+
"bugs": "https://github.com/beorn/vterm/issues",
|
|
5
19
|
"license": "MIT",
|
|
6
|
-
"author": "Beorn"
|
|
20
|
+
"author": "Beorn",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/beorn/vterm.git",
|
|
24
|
+
"directory": "packages/vterm"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./src/index.ts"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=23.6.0"
|
|
38
|
+
}
|
|
7
39
|
}
|