vt220.js 0.1.2 → 0.7.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/dist/index.d.mts CHANGED
@@ -32,12 +32,72 @@ interface ScreenOptions {
32
32
  /** Callback for DA1/DA2/DSR responses — write these back to the PTY */
33
33
  onResponse?: (data: string) => void;
34
34
  }
35
+ interface Attrs {
36
+ fg: CellColor | null;
37
+ bg: CellColor | null;
38
+ bold: boolean;
39
+ underline: boolean;
40
+ blink: boolean;
41
+ inverse: boolean;
42
+ hidden: boolean;
43
+ }
44
+ /**
45
+ * Serializable VT220 screen state — the same snapshot/restore API shape as
46
+ * vterm.js, restricted to the documented VT220 subset. Deliberately absent:
47
+ * truecolor/256-color, alternate screen, mouse tracking, hyperlinks,
48
+ * sixel/Kitty graphics, OSC clipboard, semantic zones, wide-char shaping.
49
+ * Do not widen without an explicit scope decision (km bead 20667).
50
+ */
51
+ interface ScreenSnapshot {
52
+ version: 1;
53
+ cols: number;
54
+ rows: number;
55
+ scrollbackLimit: number;
56
+ grid: ScreenCell[][];
57
+ scrollback: ScreenCell[][];
58
+ cursor: {
59
+ x: number;
60
+ y: number;
61
+ visible: boolean;
62
+ savedX: number;
63
+ savedY: number;
64
+ };
65
+ savedState: {
66
+ curX: number;
67
+ curY: number;
68
+ attrs: Attrs;
69
+ originMode: boolean;
70
+ autoWrap: boolean;
71
+ };
72
+ attrs: Attrs;
73
+ title: string;
74
+ modes: {
75
+ applicationCursor: boolean;
76
+ applicationKeypad: boolean;
77
+ autoWrap: boolean;
78
+ originMode: boolean;
79
+ insertMode: boolean;
80
+ reverseVideo: boolean;
81
+ };
82
+ scrollRegion: {
83
+ top: number;
84
+ bottom: number;
85
+ };
86
+ viewportOffset: number;
87
+ parser: {
88
+ state: "ground" | "escape" | "csi" | "osc" | "dcs" | "oscString";
89
+ escBuf: string;
90
+ oscBuf: string;
91
+ };
92
+ }
35
93
  interface Screen {
36
94
  readonly cols: number;
37
95
  readonly rows: number;
38
96
  process(data: Uint8Array): void;
39
97
  resize(cols: number, rows: number): void;
40
98
  reset(): void;
99
+ snapshot(): ScreenSnapshot;
100
+ restore(snapshot: ScreenSnapshot): void;
41
101
  getCell(row: number, col: number): ScreenCell;
42
102
  getLine(row: number): ScreenCell[];
43
103
  getText(): string;
@@ -55,4 +115,4 @@ interface Screen {
55
115
  }
56
116
  declare function createScreen(opts: ScreenOptions): Screen;
57
117
  //#endregion
58
- export { type CellColor, type ScreenCell, type Screen as Vt220Screen, type ScreenOptions as Vt220ScreenOptions, createScreen as createVt220Screen };
118
+ export { type CellColor, type ScreenCell, type Attrs as Vt220Attrs, type Screen as Vt220Screen, type ScreenOptions as Vt220ScreenOptions, type ScreenSnapshot as Vt220ScreenSnapshot, createScreen as createVt220Screen };
package/dist/index.mjs CHANGED
@@ -724,6 +724,82 @@ function createScreen(opts) {
724
724
  default: return false;
725
725
  }
726
726
  }
727
+ function snapshot() {
728
+ return structuredClone({
729
+ version: 1,
730
+ cols,
731
+ rows,
732
+ scrollbackLimit,
733
+ grid,
734
+ scrollback,
735
+ cursor: {
736
+ x: curX,
737
+ y: curY,
738
+ visible: curVisible,
739
+ savedX: savedCurX,
740
+ savedY: savedCurY
741
+ },
742
+ savedState,
743
+ attrs,
744
+ title,
745
+ modes: {
746
+ applicationCursor,
747
+ applicationKeypad,
748
+ autoWrap,
749
+ originMode,
750
+ insertMode,
751
+ reverseVideo
752
+ },
753
+ scrollRegion: {
754
+ top: scrollTop,
755
+ bottom: scrollBottom
756
+ },
757
+ viewportOffset,
758
+ parser: {
759
+ state: parserState,
760
+ escBuf,
761
+ oscBuf
762
+ }
763
+ });
764
+ }
765
+ function restore(value) {
766
+ if (typeof value !== "object" || value === null) throw new TypeError("Invalid vt220 snapshot");
767
+ if (value.version !== 1) throw new TypeError(`Unsupported vt220 snapshot version: ${String(value.version)}`);
768
+ for (const [name, n] of [
769
+ ["cols", value.cols],
770
+ ["rows", value.rows],
771
+ ["scrollbackLimit", value.scrollbackLimit],
772
+ ["viewportOffset", value.viewportOffset]
773
+ ]) if (!Number.isInteger(n) || n < 0) throw new TypeError(`Invalid vt220 snapshot ${name}`);
774
+ if (!Array.isArray(value.grid) || value.grid.length !== value.rows) throw new TypeError("Invalid vt220 snapshot grid");
775
+ if (!Array.isArray(value.scrollback)) throw new TypeError("Invalid vt220 snapshot scrollback");
776
+ const copy = structuredClone(value);
777
+ cols = copy.cols;
778
+ rows = copy.rows;
779
+ grid = copy.grid;
780
+ scrollback = copy.scrollback;
781
+ curX = copy.cursor.x;
782
+ curY = copy.cursor.y;
783
+ curVisible = copy.cursor.visible;
784
+ savedCurX = copy.cursor.savedX;
785
+ savedCurY = copy.cursor.savedY;
786
+ savedState = copy.savedState;
787
+ attrs = copy.attrs;
788
+ title = copy.title;
789
+ applicationCursor = copy.modes.applicationCursor;
790
+ applicationKeypad = copy.modes.applicationKeypad;
791
+ autoWrap = copy.modes.autoWrap;
792
+ originMode = copy.modes.originMode;
793
+ insertMode = copy.modes.insertMode;
794
+ reverseVideo = copy.modes.reverseVideo;
795
+ scrollTop = copy.scrollRegion.top;
796
+ scrollBottom = copy.scrollRegion.bottom;
797
+ viewportOffset = copy.viewportOffset;
798
+ parserState = copy.parser.state;
799
+ escBuf = copy.parser.escBuf;
800
+ oscBuf = copy.parser.oscBuf;
801
+ clampCursor();
802
+ }
727
803
  return {
728
804
  get cols() {
729
805
  return cols;
@@ -734,6 +810,8 @@ function createScreen(opts) {
734
810
  process,
735
811
  resize,
736
812
  reset: fullReset,
813
+ snapshot,
814
+ restore,
737
815
  getCell,
738
816
  getLine,
739
817
  getText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vt220.js",
3
- "version": "0.1.2",
3
+ "version": "0.7.0",
4
4
  "description": "VT220 terminal emulator — 8 colors, insert/delete, selective erase. Pure TypeScript, zero dependencies.",
5
5
  "keywords": [
6
6
  "ansi",
@@ -24,6 +24,8 @@
24
24
  "dist"
25
25
  ],
26
26
  "type": "module",
27
+ "main": "./dist/index.mjs",
28
+ "types": "./dist/index.d.mts",
27
29
  "exports": {
28
30
  ".": {
29
31
  "types": "./dist/index.d.mts",