vt100.js 0.1.0 → 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 +45 -83
- package/dist/index.d.mts +59 -0
- package/dist/index.mjs +564 -0
- package/package.json +37 -18
- package/LICENSE +0 -21
- package/src/index.ts +0 -8
- package/src/screen.ts +0 -1202
package/README.md
CHANGED
|
@@ -2,29 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
Pure TypeScript VT100 terminal emulator. Zero dependencies, headless, fast.
|
|
4
4
|
|
|
5
|
+
Part of the [vterm](https://github.com/beorn/vterm) monorepo.
|
|
6
|
+
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
-
|
|
8
|
-
- SGR attributes
|
|
9
|
-
-
|
|
10
|
-
- Cursor
|
|
11
|
-
-
|
|
9
|
+
- Strict DEC VT100 (1978) emulation — monochrome display
|
|
10
|
+
- SGR attributes: bold, underline (boolean), blink, inverse
|
|
11
|
+
- Cursor movement (CUP, CUU, CUD, CUF, CUB, CHA, CNL, CPL, HVP, VPA)
|
|
12
|
+
- Cursor save/restore (DECSC/DECRC)
|
|
13
|
+
- Erase display/line (ED/EL)
|
|
12
14
|
- Scroll regions (DECSTBM) with content preservation
|
|
15
|
+
- Scroll up/down (SU/SD)
|
|
13
16
|
- Scrollback buffer with configurable limit
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
## Comparison
|
|
19
|
-
|
|
20
|
-
| Package | Screen State | SGR Colors | Scrollback | Wide Chars | Zero Deps | Size |
|
|
21
|
-
|---------|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
22
|
-
| **vt100.js** | yes | 16/256/true | yes | yes | yes | ~30KB |
|
|
23
|
-
| `@xterm/headless` | yes | 16/256/true | yes | yes | no | ~500KB |
|
|
24
|
-
| `node-pty` + xterm | yes | 16/256/true | yes | yes | no | native build |
|
|
25
|
-
| `ansi-parser` | no | parse only | no | no | yes | ~5KB |
|
|
26
|
-
| `terminal-kit` | yes | 16/256/true | no | partial | no | ~2MB |
|
|
27
|
-
| `blessed` / `neo-blessed` | yes | 16/256 | no | no | no | ~1MB |
|
|
17
|
+
- Screen modes (auto-wrap, origin mode, cursor visibility)
|
|
18
|
+
- DEC special graphics charset
|
|
19
|
+
- DA1/DSR/CPR device responses
|
|
20
|
+
- Zero dependencies — works in Bun, Node.js, and browsers
|
|
28
21
|
|
|
29
22
|
## Install
|
|
30
23
|
|
|
@@ -40,91 +33,60 @@ import { createVt100Screen } from "vt100.js"
|
|
|
40
33
|
const screen = createVt100Screen({ cols: 80, rows: 24 })
|
|
41
34
|
screen.process(new TextEncoder().encode("Hello, \x1b[1mBold\x1b[0m World!"))
|
|
42
35
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
console.log(
|
|
46
|
-
|
|
47
|
-
// Read text
|
|
48
|
-
console.log(screen.getText()) // "Hello, Bold World!"
|
|
49
|
-
|
|
50
|
-
// Check cursor position
|
|
51
|
-
const pos = screen.getCursorPosition()
|
|
52
|
-
console.log(pos) // { x: 18, y: 0 }
|
|
36
|
+
console.log(screen.getText()) // "Hello, Bold World!"
|
|
37
|
+
console.log(screen.getCell(0, 7).bold) // true
|
|
38
|
+
console.log(screen.getCursorPosition()) // { x: 18, y: 0 }
|
|
53
39
|
```
|
|
54
40
|
|
|
55
41
|
## API
|
|
56
42
|
|
|
57
43
|
### `createVt100Screen(options)`
|
|
58
44
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
rows: 24, // terminal height
|
|
65
|
-
scrollbackLimit: 1000 // max scrollback lines (default: 1000)
|
|
66
|
-
})
|
|
67
|
-
```
|
|
45
|
+
| Option | Type | Default | Description |
|
|
46
|
+
| ----------------- | -------- | -------- | -------------------- |
|
|
47
|
+
| `cols` | `number` | required | Terminal width |
|
|
48
|
+
| `rows` | `number` | required | Terminal height |
|
|
49
|
+
| `scrollbackLimit` | `number` | `1000` | Max scrollback lines |
|
|
68
50
|
|
|
69
51
|
### Screen methods
|
|
70
52
|
|
|
71
|
-
| Method
|
|
72
|
-
|
|
73
|
-
| `process(data: Uint8Array)`
|
|
74
|
-
| `getText()`
|
|
75
|
-
| `getTextRange(
|
|
76
|
-
| `getLine(row)`
|
|
77
|
-
| `getCell(row, col)`
|
|
78
|
-
| `getCursorPosition()`
|
|
79
|
-
| `getCursorVisible()`
|
|
80
|
-
| `getMode(mode)`
|
|
81
|
-
| `getTitle()`
|
|
82
|
-
| `getScrollbackLength()`
|
|
83
|
-
| `getViewportOffset()`
|
|
84
|
-
| `scrollViewport(delta)`
|
|
85
|
-
| `resize(cols, rows)`
|
|
86
|
-
| `reset()`
|
|
53
|
+
| Method | Description |
|
|
54
|
+
| ------------------------------ | ---------------------------------- |
|
|
55
|
+
| `process(data: Uint8Array)` | Feed raw terminal data |
|
|
56
|
+
| `getText()` | Get all text (scrollback + screen) |
|
|
57
|
+
| `getTextRange(sr, sc, er, ec)` | Get text in a range |
|
|
58
|
+
| `getLine(row)` | Get cells for a row |
|
|
59
|
+
| `getCell(row, col)` | Get a single cell |
|
|
60
|
+
| `getCursorPosition()` | Get cursor `{ x, y }` |
|
|
61
|
+
| `getCursorVisible()` | Check cursor visibility |
|
|
62
|
+
| `getMode(mode)` | Check terminal mode |
|
|
63
|
+
| `getTitle()` | Get window title |
|
|
64
|
+
| `getScrollbackLength()` | Number of scrollback lines |
|
|
65
|
+
| `getViewportOffset()` | Current viewport scroll offset |
|
|
66
|
+
| `scrollViewport(delta)` | Scroll viewport |
|
|
67
|
+
| `resize(cols, rows)` | Resize terminal |
|
|
68
|
+
| `reset()` | Reset to initial state |
|
|
87
69
|
|
|
88
70
|
### Cell properties
|
|
89
71
|
|
|
90
72
|
```typescript
|
|
91
73
|
interface ScreenCell {
|
|
92
|
-
char: string
|
|
93
|
-
fg: CellColor | null
|
|
94
|
-
bg: CellColor | null
|
|
74
|
+
char: string
|
|
75
|
+
fg: CellColor | null // always null (VT100 is monochrome)
|
|
76
|
+
bg: CellColor | null // always null (VT100 is monochrome)
|
|
95
77
|
bold: boolean
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
underline: UnderlineStyle // "none" | "single" | "double" | "curly" | "dotted" | "dashed"
|
|
99
|
-
strikethrough: boolean
|
|
78
|
+
underline: boolean
|
|
79
|
+
blink: boolean
|
|
100
80
|
inverse: boolean
|
|
101
81
|
hidden: boolean
|
|
102
|
-
wide: boolean // true for CJK/emoji double-width chars
|
|
103
82
|
}
|
|
104
83
|
```
|
|
105
84
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
Queryable via `screen.getMode(mode)`:
|
|
109
|
-
|
|
110
|
-
- `altScreen` -- alternate screen buffer
|
|
111
|
-
- `bracketedPaste` -- bracketed paste mode
|
|
112
|
-
- `mouseTracking` -- mouse tracking
|
|
113
|
-
- `autoWrap` -- auto-wrap at right margin (default: on)
|
|
114
|
-
- `applicationCursor` -- application cursor keys
|
|
115
|
-
- `applicationKeypad` -- application keypad mode
|
|
116
|
-
- `originMode` -- origin mode
|
|
117
|
-
- `insertMode` -- insert mode
|
|
118
|
-
- `reverseVideo` -- reverse video
|
|
119
|
-
- `focusTracking` -- focus tracking
|
|
120
|
-
- `cursorVisible` -- cursor visibility
|
|
121
|
-
|
|
122
|
-
## Ecosystem
|
|
85
|
+
## See also
|
|
123
86
|
|
|
124
|
-
- [
|
|
125
|
-
- [
|
|
126
|
-
- [
|
|
127
|
-
- [@termless/vt100](https://github.com/beorn/termless) -- Termless backend wrapper for vt100.js
|
|
87
|
+
- [vterm.js](../vterm/) — full-featured modern emulator (100% terminfo.dev coverage)
|
|
88
|
+
- [Termless](https://termless.dev) — headless terminal testing
|
|
89
|
+
- [Terminfo.dev](https://terminfo.dev) — terminal feature support tables
|
|
128
90
|
|
|
129
91
|
## License
|
|
130
92
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/screen.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pure TypeScript VT100 terminal emulator.
|
|
4
|
+
*
|
|
5
|
+
* Strict DEC VT100 (1978) implementation: monochrome display, cursor movement,
|
|
6
|
+
* scroll regions, auto-wrap, origin mode, DEC special graphics charset.
|
|
7
|
+
* SGR supports bold, underline, blink, and reverse — NO colors (VT100 is
|
|
8
|
+
* monochrome). No insert mode, no insert/delete chars/lines — those are
|
|
9
|
+
* VT102/VT220 features.
|
|
10
|
+
*
|
|
11
|
+
* Zero dependencies. For colors and VT220 features, use vt220.js.
|
|
12
|
+
* For truecolor, 256 colors, and wide chars, use vterm.js.
|
|
13
|
+
*/
|
|
14
|
+
interface CellColor {
|
|
15
|
+
r: number;
|
|
16
|
+
g: number;
|
|
17
|
+
b: number;
|
|
18
|
+
}
|
|
19
|
+
interface ScreenCell {
|
|
20
|
+
char: string;
|
|
21
|
+
fg: CellColor | null;
|
|
22
|
+
bg: CellColor | null;
|
|
23
|
+
bold: boolean;
|
|
24
|
+
underline: boolean;
|
|
25
|
+
blink: boolean;
|
|
26
|
+
inverse: boolean;
|
|
27
|
+
hidden: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface ScreenOptions {
|
|
30
|
+
cols: number;
|
|
31
|
+
rows: number;
|
|
32
|
+
scrollbackLimit?: number;
|
|
33
|
+
/** Callback for DA1/DSR responses — write these back to the PTY */
|
|
34
|
+
onResponse?: (data: string) => void;
|
|
35
|
+
}
|
|
36
|
+
interface Screen {
|
|
37
|
+
readonly cols: number;
|
|
38
|
+
readonly rows: number;
|
|
39
|
+
process(data: Uint8Array): void;
|
|
40
|
+
resize(cols: number, rows: number): void;
|
|
41
|
+
reset(): void;
|
|
42
|
+
getCell(row: number, col: number): ScreenCell;
|
|
43
|
+
getLine(row: number): ScreenCell[];
|
|
44
|
+
getText(): string;
|
|
45
|
+
getTextRange(startRow: number, startCol: number, endRow: number, endCol: number): string;
|
|
46
|
+
getCursorPosition(): {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
};
|
|
50
|
+
getCursorVisible(): boolean;
|
|
51
|
+
getTitle(): string;
|
|
52
|
+
getMode(mode: string): boolean;
|
|
53
|
+
getScrollbackLength(): number;
|
|
54
|
+
getViewportOffset(): number;
|
|
55
|
+
scrollViewport(delta: number): void;
|
|
56
|
+
}
|
|
57
|
+
declare function createScreen(opts: ScreenOptions): Screen;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { type CellColor, type ScreenCell, type Screen as Vt100Screen, type ScreenOptions as Vt100ScreenOptions, createScreen as createVt100Screen };
|