vt100.js 0.1.0 → 0.1.1

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 CHANGED
@@ -17,14 +17,14 @@ Pure TypeScript VT100 terminal emulator. Zero dependencies, headless, fast.
17
17
 
18
18
  ## Comparison
19
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 |
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 |
28
28
 
29
29
  ## Install
30
30
 
@@ -42,14 +42,14 @@ screen.process(new TextEncoder().encode("Hello, \x1b[1mBold\x1b[0m World!"))
42
42
 
43
43
  // Read cell state
44
44
  const cell = screen.getCell(0, 0)
45
- console.log(cell.char) // "H"
45
+ console.log(cell.char) // "H"
46
46
 
47
47
  // Read text
48
- console.log(screen.getText()) // "Hello, Bold World!"
48
+ console.log(screen.getText()) // "Hello, Bold World!"
49
49
 
50
50
  // Check cursor position
51
51
  const pos = screen.getCursorPosition()
52
- console.log(pos) // { x: 18, y: 0 }
52
+ console.log(pos) // { x: 18, y: 0 }
53
53
  ```
54
54
 
55
55
  ## API
@@ -60,46 +60,46 @@ Create a new screen instance.
60
60
 
61
61
  ```typescript
62
62
  const screen = createVt100Screen({
63
- cols: 80, // terminal width
64
- rows: 24, // terminal height
65
- scrollbackLimit: 1000 // max scrollback lines (default: 1000)
63
+ cols: 80, // terminal width
64
+ rows: 24, // terminal height
65
+ scrollbackLimit: 1000, // max scrollback lines (default: 1000)
66
66
  })
67
67
  ```
68
68
 
69
69
  ### Screen methods
70
70
 
71
- | Method | Description |
72
- |--------|-------------|
73
- | `process(data: Uint8Array)` | Feed raw terminal data |
74
- | `getText()` | Get all text (scrollback + screen) |
75
- | `getTextRange(startRow, startCol, endRow, endCol)` | Get text in a range |
76
- | `getLine(row)` | Get cells for a row |
77
- | `getCell(row, col)` | Get a single cell (char, fg, bg, bold, etc.) |
78
- | `getCursorPosition()` | Get cursor `{ x, y }` |
79
- | `getCursorVisible()` | Check cursor visibility |
80
- | `getMode(mode)` | Check terminal mode (`altScreen`, `bracketedPaste`, etc.) |
81
- | `getTitle()` | Get window title (set via OSC 0/2) |
82
- | `getScrollbackLength()` | Number of scrollback lines |
83
- | `getViewportOffset()` | Current viewport scroll offset |
84
- | `scrollViewport(delta)` | Scroll viewport by delta lines |
85
- | `resize(cols, rows)` | Resize the terminal |
86
- | `reset()` | Reset to initial state |
71
+ | Method | Description |
72
+ | -------------------------------------------------- | --------------------------------------------------------- |
73
+ | `process(data: Uint8Array)` | Feed raw terminal data |
74
+ | `getText()` | Get all text (scrollback + screen) |
75
+ | `getTextRange(startRow, startCol, endRow, endCol)` | Get text in a range |
76
+ | `getLine(row)` | Get cells for a row |
77
+ | `getCell(row, col)` | Get a single cell (char, fg, bg, bold, etc.) |
78
+ | `getCursorPosition()` | Get cursor `{ x, y }` |
79
+ | `getCursorVisible()` | Check cursor visibility |
80
+ | `getMode(mode)` | Check terminal mode (`altScreen`, `bracketedPaste`, etc.) |
81
+ | `getTitle()` | Get window title (set via OSC 0/2) |
82
+ | `getScrollbackLength()` | Number of scrollback lines |
83
+ | `getViewportOffset()` | Current viewport scroll offset |
84
+ | `scrollViewport(delta)` | Scroll viewport by delta lines |
85
+ | `resize(cols, rows)` | Resize the terminal |
86
+ | `reset()` | Reset to initial state |
87
87
 
88
88
  ### Cell properties
89
89
 
90
90
  ```typescript
91
91
  interface ScreenCell {
92
- char: string // character content
93
- fg: CellColor | null // foreground color { r, g, b }
94
- bg: CellColor | null // background color { r, g, b }
92
+ char: string // character content
93
+ fg: CellColor | null // foreground color { r, g, b }
94
+ bg: CellColor | null // background color { r, g, b }
95
95
  bold: boolean
96
96
  faint: boolean
97
97
  italic: boolean
98
- underline: UnderlineStyle // "none" | "single" | "double" | "curly" | "dotted" | "dashed"
98
+ underline: UnderlineStyle // "none" | "single" | "double" | "curly" | "dotted" | "dashed"
99
99
  strikethrough: boolean
100
100
  inverse: boolean
101
101
  hidden: boolean
102
- wide: boolean // true for CJK/emoji double-width chars
102
+ wide: boolean // true for CJK/emoji double-width chars
103
103
  }
104
104
  ```
105
105
 
@@ -0,0 +1,2 @@
1
+ export { createScreen as createVt100Screen, type Screen as Vt100Screen, type ScreenOptions as Vt100ScreenOptions, type ScreenCell, type CellColor, type UnderlineStyle, } from "./screen.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,IAAI,iBAAiB,EACjC,KAAK,MAAM,IAAI,WAAW,EAC1B,KAAK,aAAa,IAAI,kBAAkB,EACxC,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,cAAc,GACpB,MAAM,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createScreen as createVt100Screen, } from "./screen.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,IAAI,iBAAiB,GAMlC,MAAM,aAAa,CAAA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Pure TypeScript VT100 terminal emulator.
3
+ *
4
+ * Inspired by the Rust vt100 crate — parses a terminal byte stream and
5
+ * maintains an in-memory screen representation with per-cell attributes,
6
+ * cursor tracking, and mode state.
7
+ *
8
+ * Zero dependencies. Handles: SGR (16/256/truecolor), cursor movement,
9
+ * erase, scroll regions, alternate screen, modes, OSC title, and more.
10
+ */
11
+ export interface CellColor {
12
+ r: number;
13
+ g: number;
14
+ b: number;
15
+ }
16
+ export type UnderlineStyle = "none" | "single" | "double" | "curly" | "dotted" | "dashed";
17
+ export interface ScreenCell {
18
+ char: string;
19
+ fg: CellColor | null;
20
+ bg: CellColor | null;
21
+ bold: boolean;
22
+ faint: boolean;
23
+ italic: boolean;
24
+ underline: UnderlineStyle;
25
+ strikethrough: boolean;
26
+ inverse: boolean;
27
+ hidden: boolean;
28
+ wide: boolean;
29
+ }
30
+ export interface ScreenOptions {
31
+ cols: number;
32
+ rows: number;
33
+ scrollbackLimit?: number;
34
+ }
35
+ export interface Screen {
36
+ readonly cols: number;
37
+ readonly rows: number;
38
+ process(data: Uint8Array): void;
39
+ resize(cols: number, rows: number): void;
40
+ reset(): void;
41
+ getCell(row: number, col: number): ScreenCell;
42
+ getLine(row: number): ScreenCell[];
43
+ getText(): string;
44
+ getTextRange(startRow: number, startCol: number, endRow: number, endCol: number): string;
45
+ getCursorPosition(): {
46
+ x: number;
47
+ y: number;
48
+ };
49
+ getCursorVisible(): boolean;
50
+ getTitle(): string;
51
+ getMode(mode: string): boolean;
52
+ getScrollbackLength(): number;
53
+ getViewportOffset(): number;
54
+ scrollViewport(delta: number): void;
55
+ }
56
+ export declare function createScreen(opts: ScreenOptions): Screen;
57
+ //# sour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