baxian 2.0.1 → 2.0.3

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.
Files changed (259) hide show
  1. package/README.md +5 -7
  2. package/README.zh-CN.md +5 -7
  3. package/dist/agent/bootstrap.d.ts.map +1 -1
  4. package/dist/agent/bootstrap.js +2 -4
  5. package/dist/agent/bootstrap.js.map +1 -1
  6. package/dist/agent/branch.d.ts +0 -12
  7. package/dist/agent/branch.d.ts.map +1 -1
  8. package/dist/agent/branch.js +1 -78
  9. package/dist/agent/branch.js.map +1 -1
  10. package/dist/agent/detect/region.d.ts.map +1 -1
  11. package/dist/agent/detect/region.js +0 -3
  12. package/dist/agent/detect/region.js.map +1 -1
  13. package/dist/agent/dispatch-reconciler.d.ts.map +1 -1
  14. package/dist/agent/dispatch-reconciler.js +8 -59
  15. package/dist/agent/dispatch-reconciler.js.map +1 -1
  16. package/dist/agent/lineage.d.ts.map +1 -1
  17. package/dist/agent/lineage.js +0 -9
  18. package/dist/agent/lineage.js.map +1 -1
  19. package/dist/agent/manager.d.ts +66 -142
  20. package/dist/agent/manager.d.ts.map +1 -1
  21. package/dist/agent/manager.js +936 -2738
  22. package/dist/agent/manager.js.map +1 -1
  23. package/dist/agent/net-exec.d.ts.map +1 -1
  24. package/dist/agent/net-exec.js +0 -5
  25. package/dist/agent/net-exec.js.map +1 -1
  26. package/dist/agent/pane-streamer-manager.d.ts.map +1 -1
  27. package/dist/agent/pane-streamer-manager.js +0 -36
  28. package/dist/agent/pane-streamer-manager.js.map +1 -1
  29. package/dist/agent/pane-streamer.d.ts +10 -1
  30. package/dist/agent/pane-streamer.d.ts.map +1 -1
  31. package/dist/agent/pane-streamer.js +142 -79
  32. package/dist/agent/pane-streamer.js.map +1 -1
  33. package/dist/agent/phase-signal-watcher.d.ts +2 -11
  34. package/dist/agent/phase-signal-watcher.d.ts.map +1 -1
  35. package/dist/agent/phase-signal-watcher.js +36 -160
  36. package/dist/agent/phase-signal-watcher.js.map +1 -1
  37. package/dist/agent/phase-signal.d.ts +13 -40
  38. package/dist/agent/phase-signal.d.ts.map +1 -1
  39. package/dist/agent/phase-signal.js +38 -98
  40. package/dist/agent/phase-signal.js.map +1 -1
  41. package/dist/agent/preflight.d.ts +0 -1
  42. package/dist/agent/preflight.d.ts.map +1 -1
  43. package/dist/agent/preflight.js +6 -31
  44. package/dist/agent/preflight.js.map +1 -1
  45. package/dist/agent/prompt.d.ts +1 -30
  46. package/dist/agent/prompt.d.ts.map +1 -1
  47. package/dist/agent/prompt.js +20 -148
  48. package/dist/agent/prompt.js.map +1 -1
  49. package/dist/agent/repo-store.d.ts.map +1 -1
  50. package/dist/agent/repo-store.js +0 -42
  51. package/dist/agent/repo-store.js.map +1 -1
  52. package/dist/agent/runner.d.ts.map +1 -1
  53. package/dist/agent/runner.js +0 -2
  54. package/dist/agent/runner.js.map +1 -1
  55. package/dist/agent/tmux-install.js +0 -1
  56. package/dist/agent/tmux-install.js.map +1 -1
  57. package/dist/agent/tmux-probe-poller.d.ts.map +1 -1
  58. package/dist/agent/tmux-probe-poller.js +0 -7
  59. package/dist/agent/tmux-probe-poller.js.map +1 -1
  60. package/dist/agent/tmux.d.ts.map +1 -1
  61. package/dist/agent/tmux.js +0 -86
  62. package/dist/agent/tmux.js.map +1 -1
  63. package/dist/agent/vt-visible-text.d.ts +87 -0
  64. package/dist/agent/vt-visible-text.d.ts.map +1 -0
  65. package/dist/agent/vt-visible-text.js +1058 -0
  66. package/dist/agent/vt-visible-text.js.map +1 -0
  67. package/dist/api/agents.d.ts.map +1 -1
  68. package/dist/api/agents.js +1 -42
  69. package/dist/api/agents.js.map +1 -1
  70. package/dist/api/config.d.ts.map +1 -1
  71. package/dist/api/config.js +8 -53
  72. package/dist/api/config.js.map +1 -1
  73. package/dist/api/hosts.d.ts.map +1 -1
  74. package/dist/api/hosts.js +2 -57
  75. package/dist/api/hosts.js.map +1 -1
  76. package/dist/api/platform-guard.d.ts.map +1 -1
  77. package/dist/api/platform-guard.js +2 -3
  78. package/dist/api/platform-guard.js.map +1 -1
  79. package/dist/api/probe.d.ts.map +1 -1
  80. package/dist/api/probe.js +0 -1
  81. package/dist/api/probe.js.map +1 -1
  82. package/dist/api/projects.d.ts.map +1 -1
  83. package/dist/api/projects.js +599 -332
  84. package/dist/api/projects.js.map +1 -1
  85. package/dist/api/tasks.d.ts.map +1 -1
  86. package/dist/api/tasks.js +15 -40
  87. package/dist/api/tasks.js.map +1 -1
  88. package/dist/app.d.ts +0 -2
  89. package/dist/app.d.ts.map +1 -1
  90. package/dist/app.js +0 -6
  91. package/dist/app.js.map +1 -1
  92. package/dist/cli.d.ts.map +1 -1
  93. package/dist/cli.js +4 -29
  94. package/dist/cli.js.map +1 -1
  95. package/dist/config/hot-reload.d.ts.map +1 -1
  96. package/dist/config/hot-reload.js +0 -4
  97. package/dist/config/hot-reload.js.map +1 -1
  98. package/dist/config/loader.d.ts +5 -1
  99. package/dist/config/loader.d.ts.map +1 -1
  100. package/dist/config/loader.js +36 -47
  101. package/dist/config/loader.js.map +1 -1
  102. package/dist/config/normalizer.d.ts.map +1 -1
  103. package/dist/config/normalizer.js +0 -19
  104. package/dist/config/normalizer.js.map +1 -1
  105. package/dist/config/validator.d.ts +7 -4
  106. package/dist/config/validator.d.ts.map +1 -1
  107. package/dist/config/validator.js +56 -270
  108. package/dist/config/validator.js.map +1 -1
  109. package/dist/event/handlers.d.ts.map +1 -1
  110. package/dist/event/handlers.js +356 -234
  111. package/dist/event/handlers.js.map +1 -1
  112. package/dist/event/log.js +0 -2
  113. package/dist/event/log.js.map +1 -1
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +0 -50
  116. package/dist/index.js.map +1 -1
  117. package/dist/platform/body-digest.d.ts.map +1 -1
  118. package/dist/platform/body-digest.js +0 -4
  119. package/dist/platform/body-digest.js.map +1 -1
  120. package/dist/platform/command-renderer.d.ts +6 -0
  121. package/dist/platform/command-renderer.d.ts.map +1 -1
  122. package/dist/platform/command-renderer.js +20 -3
  123. package/dist/platform/command-renderer.js.map +1 -1
  124. package/dist/platform/comment-cursor.d.ts.map +1 -1
  125. package/dist/platform/comment-cursor.js +0 -21
  126. package/dist/platform/comment-cursor.js.map +1 -1
  127. package/dist/platform/driver-host.d.ts.map +1 -1
  128. package/dist/platform/driver-host.js +3 -1
  129. package/dist/platform/driver-host.js.map +1 -1
  130. package/dist/platform/driver-spec.d.ts.map +1 -1
  131. package/dist/platform/driver-spec.js +33 -46
  132. package/dist/platform/driver-spec.js.map +1 -1
  133. package/dist/platform/field-mapper.d.ts.map +1 -1
  134. package/dist/platform/field-mapper.js +3 -11
  135. package/dist/platform/field-mapper.js.map +1 -1
  136. package/dist/platform/git-driver.d.ts +2 -0
  137. package/dist/platform/git-driver.d.ts.map +1 -1
  138. package/dist/platform/git-driver.js +9 -23
  139. package/dist/platform/git-driver.js.map +1 -1
  140. package/dist/platform/manifest.d.ts.map +1 -1
  141. package/dist/platform/manifest.js +0 -3
  142. package/dist/platform/manifest.js.map +1 -1
  143. package/dist/platform/markers.d.ts.map +1 -1
  144. package/dist/platform/markers.js +0 -19
  145. package/dist/platform/markers.js.map +1 -1
  146. package/dist/platform/platform-poller.d.ts +0 -1
  147. package/dist/platform/platform-poller.d.ts.map +1 -1
  148. package/dist/platform/platform-poller.js +0 -49
  149. package/dist/platform/platform-poller.js.map +1 -1
  150. package/dist/platform/plugin-registry.d.ts.map +1 -1
  151. package/dist/platform/plugin-registry.js +1 -12
  152. package/dist/platform/plugin-registry.js.map +1 -1
  153. package/dist/platform/plugins/github/driver.json +5 -0
  154. package/dist/platform/plugins/github/skills/baxian-cli-gh/SKILL.md +20 -14
  155. package/dist/platform/pr-conversation-cache.d.ts.map +1 -1
  156. package/dist/platform/pr-conversation-cache.js +0 -17
  157. package/dist/platform/pr-conversation-cache.js.map +1 -1
  158. package/dist/platform/preflight-exec.d.ts.map +1 -1
  159. package/dist/platform/preflight-exec.js +0 -9
  160. package/dist/platform/preflight-exec.js.map +1 -1
  161. package/dist/platform/response-parser.d.ts.map +1 -1
  162. package/dist/platform/response-parser.js +0 -4
  163. package/dist/platform/response-parser.js.map +1 -1
  164. package/dist/platform/review-timeline.d.ts.map +1 -1
  165. package/dist/platform/review-timeline.js +0 -22
  166. package/dist/platform/review-timeline.js.map +1 -1
  167. package/dist/platform/row-schema.d.ts.map +1 -1
  168. package/dist/platform/row-schema.js +0 -11
  169. package/dist/platform/row-schema.js.map +1 -1
  170. package/dist/platform/startup.d.ts.map +1 -1
  171. package/dist/platform/startup.js +6 -17
  172. package/dist/platform/startup.js.map +1 -1
  173. package/dist/platform/types.d.ts +1 -0
  174. package/dist/platform/types.d.ts.map +1 -1
  175. package/dist/platform/types.js +3 -8
  176. package/dist/platform/types.js.map +1 -1
  177. package/dist/platform/verdict-engine.d.ts.map +1 -1
  178. package/dist/platform/verdict-engine.js +0 -15
  179. package/dist/platform/verdict-engine.js.map +1 -1
  180. package/dist/shared/concurrency.d.ts.map +1 -1
  181. package/dist/shared/concurrency.js +0 -2
  182. package/dist/shared/concurrency.js.map +1 -1
  183. package/dist/shared/constants.d.ts +1 -8
  184. package/dist/shared/constants.d.ts.map +1 -1
  185. package/dist/shared/constants.js +2 -32
  186. package/dist/shared/constants.js.map +1 -1
  187. package/dist/shared/git-url.d.ts.map +1 -1
  188. package/dist/shared/git-url.js +0 -9
  189. package/dist/shared/git-url.js.map +1 -1
  190. package/dist/shared/types.d.ts +28 -135
  191. package/dist/shared/types.d.ts.map +1 -1
  192. package/dist/shared/types.js +7 -6
  193. package/dist/shared/types.js.map +1 -1
  194. package/dist/skill/registry.d.ts.map +1 -1
  195. package/dist/skill/registry.js +0 -5
  196. package/dist/skill/registry.js.map +1 -1
  197. package/dist/skills/baxian-pr-feedback/SKILL.md +5 -3
  198. package/dist/skills/baxian-pr-recheck/SKILL.md +4 -0
  199. package/dist/skills/baxian-pr-review/SKILL.md +4 -0
  200. package/dist/skills/baxian-signals/SKILL.md +15 -38
  201. package/dist/skills/baxian-task-check/SKILL.md +13 -14
  202. package/dist/state/agent-store.d.ts.map +1 -1
  203. package/dist/state/agent-store.js +0 -6
  204. package/dist/state/agent-store.js.map +1 -1
  205. package/dist/state/error-record-store.d.ts.map +1 -1
  206. package/dist/state/error-record-store.js +0 -5
  207. package/dist/state/error-record-store.js.map +1 -1
  208. package/dist/state/init.d.ts.map +1 -1
  209. package/dist/state/init.js +0 -1
  210. package/dist/state/init.js.map +1 -1
  211. package/dist/state/lock.d.ts.map +1 -1
  212. package/dist/state/lock.js +0 -1
  213. package/dist/state/lock.js.map +1 -1
  214. package/dist/state/snapshot.d.ts.map +1 -1
  215. package/dist/state/snapshot.js +5 -2
  216. package/dist/state/snapshot.js.map +1 -1
  217. package/dist/state/task-store.d.ts.map +1 -1
  218. package/dist/state/task-store.js +56 -143
  219. package/dist/state/task-store.js.map +1 -1
  220. package/dist/terminal/attach.d.ts.map +1 -1
  221. package/dist/terminal/attach.js +0 -4
  222. package/dist/terminal/attach.js.map +1 -1
  223. package/dist/terminal/stream-ws.js +0 -5
  224. package/dist/terminal/stream-ws.js.map +1 -1
  225. package/dist/web/assets/index-CiAnjs1_.js +15 -0
  226. package/dist/web/assets/index-yqxawAPJ.css +1 -0
  227. package/dist/web/index.html +2 -2
  228. package/package.json +1 -1
  229. package/dist/agent/review-transport.d.ts +0 -92
  230. package/dist/agent/review-transport.d.ts.map +0 -1
  231. package/dist/agent/review-transport.js +0 -512
  232. package/dist/agent/review-transport.js.map +0 -1
  233. package/dist/agent/root-agent-runtime.d.ts +0 -80
  234. package/dist/agent/root-agent-runtime.d.ts.map +0 -1
  235. package/dist/agent/root-agent-runtime.js +0 -635
  236. package/dist/agent/root-agent-runtime.js.map +0 -1
  237. package/dist/agent/root-recovery-coordinator.d.ts +0 -125
  238. package/dist/agent/root-recovery-coordinator.d.ts.map +0 -1
  239. package/dist/agent/root-recovery-coordinator.js +0 -1579
  240. package/dist/agent/root-recovery-coordinator.js.map +0 -1
  241. package/dist/event/server-handlers.d.ts +0 -4
  242. package/dist/event/server-handlers.d.ts.map +0 -1
  243. package/dist/event/server-handlers.js +0 -1294
  244. package/dist/event/server-handlers.js.map +0 -1
  245. package/dist/skills/baxian-research/SKILL.md +0 -28
  246. package/dist/skills/baxian-server-feedback/SKILL.md +0 -40
  247. package/dist/skills/baxian-server-feedback/agents/openai.yaml +0 -2
  248. package/dist/skills/baxian-server-review/SKILL.md +0 -58
  249. package/dist/skills/baxian-server-review/agents/openai.yaml +0 -2
  250. package/dist/state/review-store.d.ts +0 -33
  251. package/dist/state/review-store.d.ts.map +0 -1
  252. package/dist/state/review-store.js +0 -272
  253. package/dist/state/review-store.js.map +0 -1
  254. package/dist/state/root-recovery-store.d.ts +0 -107
  255. package/dist/state/root-recovery-store.d.ts.map +0 -1
  256. package/dist/state/root-recovery-store.js +0 -400
  257. package/dist/state/root-recovery-store.js.map +0 -1
  258. package/dist/web/assets/index-BPv6vv3U.css +0 -1
  259. package/dist/web/assets/index-BXfgaFNm.js +0 -18
@@ -0,0 +1,1058 @@
1
+ const S = {
2
+ ground: 0,
3
+ escape: 1,
4
+ escapeIntermediate: 2,
5
+ csiEntry: 3,
6
+ csiParam: 4,
7
+ csiIntermediate: 5,
8
+ csiIgnore: 6,
9
+ dcsEntry: 7,
10
+ dcsParam: 8,
11
+ dcsIntermediate: 9,
12
+ dcsIgnore: 10,
13
+ dcsPassthrough: 11,
14
+ oscString: 12,
15
+ sosPmApcString: 13,
16
+ };
17
+ const NON_ASCII_IGNORED = new Set([
18
+ S.oscString, S.dcsPassthrough, S.csiIgnore, S.dcsIgnore,
19
+ ]);
20
+ const EXECUTES_C0 = new Set([
21
+ S.ground, S.escape, S.escapeIntermediate,
22
+ S.csiEntry, S.csiParam, S.csiIntermediate, S.csiIgnore,
23
+ ]);
24
+ const CURSOR_MOVING_C0 = new Set([0x08, 0x09, 0x0a, 0x0d]);
25
+ const REMAPPED = '\x00';
26
+ const CHARSET_REMAPS = {
27
+ '0': '`abcdefghijklmnopqrstuvwxyz{|}~',
28
+ '4': '#@[\\]{|}~',
29
+ '5': '[\\]^`{|}~',
30
+ '6': '@[\\]^`{|}~',
31
+ '7': '@[\\]^`{|}~',
32
+ '=': '#@[\\]^_`{|}~',
33
+ A: '#',
34
+ C: '[\\]^`{|}~',
35
+ E: '@[\\]^`{|}~',
36
+ H: '@[\\]^`{|}~',
37
+ K: '@[\\]{|}~',
38
+ Q: '@[\\]^`{|}~',
39
+ R: '#@[\\]{|}~',
40
+ Y: '#@[\\]`{|}~',
41
+ Z: '#@[\\]{|}',
42
+ };
43
+ const REMAPPED_CODES = new Map(Object.entries(CHARSET_REMAPS).map(([d, chars]) => [d, new Set([...chars].map(c => c.charCodeAt(0)))]));
44
+ const RECOGNISED_DESIGNATORS = new Set([...Object.keys(CHARSET_REMAPS), 'B']);
45
+ const MAX_CSI_PARAMS = 32;
46
+ const MAX_CSI_PARAM = 0x7fffffff;
47
+ const DEFAULT_COLUMNS = 80;
48
+ const DEFAULT_ROWS = 24;
49
+ const SGR_FINAL = 'm';
50
+ const POSITIONING_CSI_FINALS = new Set([...'ABCDEFGHILMZ`abdefr']);
51
+ const DESIGNATE_INTERMEDIATES = {
52
+ '(': 0, ')': 1, '*': 2, '+': 3, '-': 1, '.': 2,
53
+ };
54
+ const LOCKING_SHIFTS = { n: 2, o: 3, '|': 3, '}': 2, '~': 1 };
55
+ function anywhereTransition(code) {
56
+ if (code === 0x1b)
57
+ return S.escape;
58
+ if (code === 0x18 || code === 0x1a)
59
+ return S.ground;
60
+ if (code < 0x80 || code > 0x9f)
61
+ return undefined;
62
+ if (code === 0x9b)
63
+ return S.csiEntry;
64
+ if (code === 0x9d)
65
+ return S.oscString;
66
+ if (code === 0x90)
67
+ return S.dcsEntry;
68
+ if (code === 0x98 || code === 0x9e || code === 0x9f)
69
+ return S.sosPmApcString;
70
+ return S.ground;
71
+ }
72
+ export class VisibleTextExtractor {
73
+ state = S.ground;
74
+ pendingHigh = '';
75
+ active;
76
+ charsets = [undefined, undefined, undefined, undefined];
77
+ gl = 0;
78
+ savedByBuffer = [undefined, undefined];
79
+ cursorByBuffer = [
80
+ { row: 0, column: 0 },
81
+ { row: 0, column: 0 },
82
+ ];
83
+ cursorReliableByBuffer = [true, true];
84
+ tabStopsReliableByBuffer = [true, true];
85
+ scrollRegionByBuffer;
86
+ continuation;
87
+ carriageReturnContinuation;
88
+ contentInvalidatedByBuffer = [false, false];
89
+ printSequenceByBuffer = [0, 0];
90
+ wraparound = true;
91
+ originMode = false;
92
+ conceal = false;
93
+ altBuffer = 0;
94
+ pendingIntermediate;
95
+ csiPrefix = '';
96
+ csiIntermediates = '';
97
+ csiParamValues = [];
98
+ csiParamHasSub = [];
99
+ csiParamValue = 0;
100
+ csiParamStarted = false;
101
+ csiInSubParam = false;
102
+ csiOverflowed = false;
103
+ csiEightBit = false;
104
+ columns;
105
+ rows;
106
+ constructor(columns = DEFAULT_COLUMNS, rows = DEFAULT_ROWS) {
107
+ this.columns = this.normalizeColumns(columns);
108
+ this.rows = this.normalizeRows(rows);
109
+ this.scrollRegionByBuffer = [this.fullScrollRegion(), this.fullScrollRegion()];
110
+ }
111
+ resize(columns, rows = this.rows) {
112
+ const normalizedColumns = this.normalizeColumns(columns);
113
+ const normalizedRows = this.normalizeRows(rows);
114
+ if (normalizedColumns === this.columns && normalizedRows === this.rows)
115
+ return;
116
+ this.columns = normalizedColumns;
117
+ this.rows = normalizedRows;
118
+ this.scrollRegionByBuffer = [this.fullScrollRegion(), this.fullScrollRegion()];
119
+ for (const cursor of this.cursorByBuffer) {
120
+ cursor.column = Math.min(cursor.column, this.columns - 1);
121
+ cursor.row = Math.min(cursor.row, this.rows - 1);
122
+ }
123
+ this.contentInvalidatedByBuffer = [true, true];
124
+ this.cursorReliableByBuffer = [false, false];
125
+ }
126
+ reset() {
127
+ this.state = S.ground;
128
+ this.pendingHigh = '';
129
+ this.fullReset();
130
+ this.altBuffer = 0;
131
+ this.pendingIntermediate = undefined;
132
+ this.clearCsiCollect();
133
+ }
134
+ normalizeColumns(columns) {
135
+ if (!Number.isFinite(columns) || columns < 1)
136
+ return DEFAULT_COLUMNS;
137
+ return Math.min(Math.trunc(columns), MAX_CSI_PARAM);
138
+ }
139
+ normalizeRows(rows) {
140
+ if (!Number.isFinite(rows) || rows < 1)
141
+ return DEFAULT_ROWS;
142
+ return Math.min(Math.trunc(rows), MAX_CSI_PARAM);
143
+ }
144
+ fullScrollRegion() {
145
+ return { top: 0, bottom: this.rows - 1 };
146
+ }
147
+ collectCsiParam(ch) {
148
+ if (ch === ';') {
149
+ this.flushCsiParam();
150
+ return;
151
+ }
152
+ if (ch === ':') {
153
+ this.csiInSubParam = true;
154
+ return;
155
+ }
156
+ if (this.csiInSubParam)
157
+ return;
158
+ this.csiParamStarted = true;
159
+ const next = this.csiParamValue * 10 + (ch.charCodeAt(0) - 0x30);
160
+ this.csiParamValue = next > MAX_CSI_PARAM ? MAX_CSI_PARAM : next;
161
+ }
162
+ flushCsiParam() {
163
+ if (this.csiParamValues.length < MAX_CSI_PARAMS) {
164
+ this.csiParamValues.push(this.csiParamStarted ? this.csiParamValue : 0);
165
+ this.csiParamHasSub.push(this.csiInSubParam);
166
+ }
167
+ this.csiParamValue = 0;
168
+ this.csiParamStarted = false;
169
+ this.csiInSubParam = false;
170
+ }
171
+ collectCsiIntermediate(ch) {
172
+ if (this.csiIntermediates.length < 4)
173
+ this.csiIntermediates += ch;
174
+ else
175
+ this.csiOverflowed = true;
176
+ }
177
+ collectCsiPrefix(ch) {
178
+ if (this.csiPrefix === '')
179
+ this.csiPrefix = ch;
180
+ else
181
+ this.csiOverflowed = true;
182
+ }
183
+ clearCsiCollect() {
184
+ this.csiPrefix = '';
185
+ this.csiIntermediates = '';
186
+ this.csiParamValues = [];
187
+ this.csiParamHasSub = [];
188
+ this.csiParamValue = 0;
189
+ this.csiParamStarted = false;
190
+ this.csiInSubParam = false;
191
+ this.csiOverflowed = false;
192
+ this.csiEightBit = false;
193
+ }
194
+ setgCharset(slot, designator) {
195
+ this.charsets[slot] = designator;
196
+ if (this.gl === slot)
197
+ this.active = designator;
198
+ }
199
+ setgLevel(slot) {
200
+ this.gl = slot;
201
+ this.active = this.charsets[slot];
202
+ }
203
+ resetCharsetSlots() {
204
+ this.charsets.fill(undefined);
205
+ this.active = undefined;
206
+ }
207
+ softReset() {
208
+ this.resetCharsetSlots();
209
+ this.gl = 0;
210
+ this.conceal = false;
211
+ this.wraparound = true;
212
+ this.originMode = false;
213
+ this.scrollRegionByBuffer[this.altBuffer] = this.fullScrollRegion();
214
+ this.savedByBuffer[this.altBuffer] = undefined;
215
+ }
216
+ fullReset() {
217
+ this.resetCharsetSlots();
218
+ this.gl = 0;
219
+ this.conceal = false;
220
+ this.wraparound = true;
221
+ this.savedByBuffer = [undefined, undefined];
222
+ this.cursorByBuffer = [
223
+ { row: 0, column: 0 },
224
+ { row: 0, column: 0 },
225
+ ];
226
+ this.cursorReliableByBuffer = [true, true];
227
+ this.tabStopsReliableByBuffer = [true, true];
228
+ this.scrollRegionByBuffer = [this.fullScrollRegion(), this.fullScrollRegion()];
229
+ this.continuation = undefined;
230
+ this.carriageReturnContinuation = undefined;
231
+ this.contentInvalidatedByBuffer = [false, false];
232
+ this.printSequenceByBuffer = [0, 0];
233
+ this.originMode = false;
234
+ this.altBuffer = 0;
235
+ }
236
+ selectDefaultCharset() {
237
+ this.setgCharset(0, undefined);
238
+ this.setgLevel(0);
239
+ }
240
+ saveCursorState() {
241
+ const cursor = this.cursorByBuffer[this.altBuffer];
242
+ const continuation = this.continuation?.buffer === this.altBuffer
243
+ ? { ...this.continuation }
244
+ : undefined;
245
+ this.savedByBuffer[this.altBuffer] = {
246
+ charset: this.active,
247
+ conceal: this.conceal,
248
+ continuation,
249
+ printSequence: this.printSequenceByBuffer[this.altBuffer],
250
+ row: cursor.row,
251
+ column: cursor.column,
252
+ reliable: this.cursorReliableByBuffer[this.altBuffer],
253
+ };
254
+ }
255
+ restoreCursorState() {
256
+ const saved = this.savedByBuffer[this.altBuffer];
257
+ this.active = saved?.charset;
258
+ this.conceal = saved?.conceal ?? false;
259
+ const reliable = saved?.reliable ?? true;
260
+ if (!reliable || !this.cursorReliableByBuffer[this.altBuffer])
261
+ this.contentInvalidated = true;
262
+ const printedSinceSave = saved !== undefined
263
+ && saved.printSequence !== this.printSequenceByBuffer[this.altBuffer];
264
+ if (printedSinceSave && saved.continuation !== undefined)
265
+ this.contentInvalidated = true;
266
+ this.assignCursor(saved?.column ?? 0, saved?.row ?? 0);
267
+ this.cursorReliableByBuffer[this.altBuffer] = reliable;
268
+ if (saved?.continuation !== undefined && !printedSinceSave && !this.contentInvalidated) {
269
+ this.continuation = { ...saved.continuation };
270
+ }
271
+ }
272
+ dispatchSgr() {
273
+ for (let i = 0; i < this.csiParamValues.length; i++) {
274
+ const param = this.csiParamValues[i];
275
+ if (param === 38 || param === 48 || param === 58) {
276
+ i += this.extendedColourSpan(i);
277
+ }
278
+ else if (param === 8)
279
+ this.conceal = true;
280
+ else if (param === 0 || param === 28)
281
+ this.conceal = false;
282
+ }
283
+ }
284
+ extendedColourSpan(leader) {
285
+ let advance = 0;
286
+ let cSpace = 0;
287
+ for (;;) {
288
+ if (this.csiParamHasSub[leader + advance])
289
+ return advance;
290
+ const subtype = advance >= 1 ? this.csiParamValues[leader + 1] : 0;
291
+ if ((subtype === 5 && advance + cSpace >= 2) || (subtype === 2 && advance + cSpace >= 5))
292
+ return advance;
293
+ if (subtype)
294
+ cSpace = 1;
295
+ advance++;
296
+ if (leader + advance >= this.csiParamValues.length || advance + cSpace >= 6)
297
+ return advance;
298
+ }
299
+ }
300
+ csiParam(index = 0) {
301
+ return this.csiParamValues[index] || 1;
302
+ }
303
+ activeScrollRegion() {
304
+ return this.scrollRegionByBuffer[this.altBuffer];
305
+ }
306
+ get contentInvalidated() {
307
+ return this.contentInvalidatedByBuffer[this.altBuffer];
308
+ }
309
+ set contentInvalidated(value) {
310
+ this.contentInvalidatedByBuffer[this.altBuffer] = value;
311
+ }
312
+ assignCursor(column, row) {
313
+ const cursor = this.cursorByBuffer[this.altBuffer];
314
+ const region = this.activeScrollRegion();
315
+ const top = this.originMode ? region.top : 0;
316
+ const bottom = this.originMode ? region.bottom : this.rows - 1;
317
+ cursor.column = Math.max(0, Math.min(column, this.columns - 1));
318
+ cursor.row = Math.max(top, Math.min(row, bottom));
319
+ }
320
+ setAbsoluteCursor(column, row) {
321
+ const region = this.activeScrollRegion();
322
+ this.assignCursor(column, row + (this.originMode ? region.top : 0));
323
+ this.cursorReliableByBuffer[this.altBuffer] = true;
324
+ }
325
+ moveCursor(columns, rows) {
326
+ const cursor = this.cursorByBuffer[this.altBuffer];
327
+ this.assignCursor(Math.min(cursor.column, this.columns - 1) + columns, cursor.row + rows);
328
+ }
329
+ moveCursorToVerticalMargin(count, direction) {
330
+ const cursor = this.cursorByBuffer[this.altBuffer];
331
+ const region = this.activeScrollRegion();
332
+ const margin = direction === 1 ? region.bottom : region.top;
333
+ const inside = direction === 1 ? cursor.row <= margin : cursor.row >= margin;
334
+ const row = inside
335
+ ? direction === 1
336
+ ? Math.min(cursor.row + count, margin)
337
+ : Math.max(cursor.row - count, margin)
338
+ : cursor.row + direction * count;
339
+ this.assignCursor(cursor.column, row);
340
+ }
341
+ moveToTab(direction, count) {
342
+ const cursor = this.cursorByBuffer[this.altBuffer];
343
+ if (!this.tabStopsReliableByBuffer[this.altBuffer]) {
344
+ this.contentInvalidated = true;
345
+ this.cursorReliableByBuffer[this.altBuffer] = false;
346
+ return;
347
+ }
348
+ cursor.column = direction === 1
349
+ ? Math.min((Math.floor(cursor.column / 8) + count) * 8, this.columns - 1)
350
+ : Math.max(Math.ceil(cursor.column / 8) * 8 - 8 * count, 0);
351
+ }
352
+ invalidateTabStops() {
353
+ this.tabStopsReliableByBuffer[this.altBuffer] = false;
354
+ }
355
+ shiftContinuationForScroll(region, shiftPosition) {
356
+ const continuation = this.continuation;
357
+ if (continuation?.buffer !== this.altBuffer)
358
+ return;
359
+ if (region.top === 0
360
+ && region.bottom === this.rows - 1
361
+ && continuation.firstPrintedRow === region.top) {
362
+ if (this.altBuffer === 1) {
363
+ this.contentInvalidated = true;
364
+ return;
365
+ }
366
+ continuation.printedInScrollback = true;
367
+ }
368
+ const positionInRegion = continuation.row >= region.top && continuation.row <= region.bottom;
369
+ if (positionInRegion && continuation.row === region.top) {
370
+ this.contentInvalidated = true;
371
+ return;
372
+ }
373
+ if (positionInRegion && shiftPosition)
374
+ continuation.row--;
375
+ if (continuation.firstPrintedRow > region.top
376
+ && continuation.firstPrintedRow <= region.bottom) {
377
+ continuation.firstPrintedRow--;
378
+ }
379
+ if (continuation.lastPrintedRow > region.top
380
+ && continuation.lastPrintedRow <= region.bottom) {
381
+ continuation.lastPrintedRow--;
382
+ }
383
+ }
384
+ indexCursor(scrollContinuation) {
385
+ const cursor = this.cursorByBuffer[this.altBuffer];
386
+ const region = this.activeScrollRegion();
387
+ if (cursor.row === region.bottom) {
388
+ this.shiftContinuationForScroll(region, scrollContinuation);
389
+ return true;
390
+ }
391
+ if (cursor.row === this.rows - 1) {
392
+ if (!scrollContinuation)
393
+ this.contentInvalidated = true;
394
+ return false;
395
+ }
396
+ this.assignCursor(cursor.column, cursor.row + 1);
397
+ return true;
398
+ }
399
+ setScrollRegion() {
400
+ const top = this.csiParamValues[0] || 1;
401
+ const requestedBottom = this.csiParamValues[1] || this.rows;
402
+ const bottom = requestedBottom > this.rows ? this.rows : requestedBottom;
403
+ if (bottom <= top)
404
+ return;
405
+ this.scrollRegionByBuffer[this.altBuffer] = { top: top - 1, bottom: bottom - 1 };
406
+ this.setAbsoluteCursor(0, 0);
407
+ }
408
+ printedColumnsOnRow(continuation, row) {
409
+ if (row < continuation.firstPrintedRow || row > continuation.lastPrintedRow)
410
+ return undefined;
411
+ return [
412
+ row === continuation.firstPrintedRow ? continuation.firstPrintedColumn : 0,
413
+ row === continuation.lastPrintedRow ? continuation.lastPrintedColumn : this.columns - 1,
414
+ ];
415
+ }
416
+ eraseLineTouchesContinuation(mode) {
417
+ const continuation = this.continuation;
418
+ if (continuation?.buffer !== this.altBuffer)
419
+ return false;
420
+ if (!continuation.reliable || !this.cursorReliableByBuffer[this.altBuffer])
421
+ return true;
422
+ const cursor = this.cursorByBuffer[this.altBuffer];
423
+ const printed = this.printedColumnsOnRow(continuation, cursor.row);
424
+ if (printed === undefined)
425
+ return false;
426
+ if (mode === 2)
427
+ return true;
428
+ if (mode === 1)
429
+ return cursor.column >= printed[0];
430
+ if (mode !== 0 || cursor.column >= this.columns)
431
+ return false;
432
+ return cursor.column <= printed[1];
433
+ }
434
+ characterEditTouchesContinuation(final) {
435
+ const continuation = this.continuation;
436
+ if (continuation?.buffer !== this.altBuffer)
437
+ return false;
438
+ if (!continuation.reliable || !this.cursorReliableByBuffer[this.altBuffer])
439
+ return true;
440
+ const cursor = this.cursorByBuffer[this.altBuffer];
441
+ const printed = this.printedColumnsOnRow(continuation, cursor.row);
442
+ if (printed === undefined)
443
+ return false;
444
+ const start = Math.min(cursor.column, this.columns - 1);
445
+ if (final !== 'X')
446
+ return start <= printed[1];
447
+ const end = Math.min(start + this.csiParam() - 1, this.columns - 1);
448
+ return start <= printed[1] && end >= printed[0];
449
+ }
450
+ lineEditTouchesContinuation() {
451
+ const continuation = this.continuation;
452
+ if (continuation?.buffer !== this.altBuffer)
453
+ return false;
454
+ if (!continuation.reliable || !this.cursorReliableByBuffer[this.altBuffer])
455
+ return true;
456
+ const cursor = this.cursorByBuffer[this.altBuffer];
457
+ const region = this.activeScrollRegion();
458
+ if (cursor.row < region.top || cursor.row > region.bottom)
459
+ return false;
460
+ return continuation.firstPrintedRow <= region.bottom
461
+ && continuation.lastPrintedRow >= cursor.row;
462
+ }
463
+ columnEditTouchesContinuation() {
464
+ const continuation = this.continuation;
465
+ if (continuation?.buffer !== this.altBuffer)
466
+ return false;
467
+ if (!continuation.reliable || !this.cursorReliableByBuffer[this.altBuffer])
468
+ return true;
469
+ const cursor = this.cursorByBuffer[this.altBuffer];
470
+ const region = this.activeScrollRegion();
471
+ if (cursor.row < region.top || cursor.row > region.bottom)
472
+ return false;
473
+ const firstAffectedRow = Math.max(continuation.firstPrintedRow, region.top);
474
+ const lastAffectedRow = Math.min(continuation.lastPrintedRow, region.bottom);
475
+ if (firstAffectedRow > lastAffectedRow)
476
+ return false;
477
+ const start = Math.min(cursor.column, this.columns - 1);
478
+ return firstAffectedRow < continuation.lastPrintedRow
479
+ || start <= continuation.lastPrintedColumn;
480
+ }
481
+ eraseDisplayToEndTouchesContinuation() {
482
+ const continuation = this.continuation;
483
+ if (continuation?.buffer !== this.altBuffer)
484
+ return false;
485
+ if (!continuation.reliable || !this.cursorReliableByBuffer[this.altBuffer])
486
+ return true;
487
+ const cursor = this.cursorByBuffer[this.altBuffer];
488
+ if (cursor.column >= this.columns)
489
+ return false;
490
+ return cursor.row < continuation.lastPrintedRow
491
+ || (cursor.row === continuation.lastPrintedRow
492
+ && cursor.column <= continuation.lastPrintedColumn);
493
+ }
494
+ eraseDisplayToStartTouchesContinuation() {
495
+ const continuation = this.continuation;
496
+ if (continuation?.buffer !== this.altBuffer)
497
+ return false;
498
+ if (!continuation.reliable || !this.cursorReliableByBuffer[this.altBuffer])
499
+ return true;
500
+ const cursor = this.cursorByBuffer[this.altBuffer];
501
+ const column = Math.min(cursor.column, this.columns - 1);
502
+ return continuation.firstPrintedRow < cursor.row
503
+ || (continuation.firstPrintedRow === cursor.row
504
+ && continuation.firstPrintedColumn <= column);
505
+ }
506
+ dispatchCursorCsi(final) {
507
+ if (!this.cursorReliableByBuffer[this.altBuffer] && POSITIONING_CSI_FINALS.has(final)) {
508
+ this.contentInvalidated = true;
509
+ }
510
+ const cursor = this.cursorByBuffer[this.altBuffer];
511
+ switch (final) {
512
+ case '@':
513
+ case 'P':
514
+ case 'X':
515
+ if (this.characterEditTouchesContinuation(final))
516
+ this.contentInvalidated = true;
517
+ this.assignCursor(Math.min(cursor.column, this.columns - 1), cursor.row);
518
+ break;
519
+ case 'A':
520
+ this.moveCursorToVerticalMargin(this.csiParam(), -1);
521
+ break;
522
+ case 'B':
523
+ this.moveCursorToVerticalMargin(this.csiParam(), 1);
524
+ break;
525
+ case 'C':
526
+ case 'a':
527
+ this.moveCursor(this.csiParam(), 0);
528
+ break;
529
+ case 'D':
530
+ this.moveCursor(-this.csiParam(), 0);
531
+ break;
532
+ case 'E':
533
+ this.moveCursorToVerticalMargin(this.csiParam(), 1);
534
+ this.assignCursor(0, cursor.row);
535
+ break;
536
+ case 'F':
537
+ this.moveCursorToVerticalMargin(this.csiParam(), -1);
538
+ this.assignCursor(0, cursor.row);
539
+ break;
540
+ case 'G':
541
+ case '`':
542
+ this.assignCursor(this.csiParam() - 1, cursor.row);
543
+ break;
544
+ case 'H':
545
+ case 'f':
546
+ this.setAbsoluteCursor(this.csiParam(1) - 1, this.csiParam(0) - 1);
547
+ break;
548
+ case 'I':
549
+ this.moveToTab(1, this.csiParam());
550
+ break;
551
+ case 'J':
552
+ case 'K': {
553
+ const mode = this.csiParamValues[0] ?? 0;
554
+ const touches = final === 'K'
555
+ ? this.eraseLineTouchesContinuation(mode)
556
+ : mode === 2
557
+ || (mode === 0 && this.eraseDisplayToEndTouchesContinuation())
558
+ || (mode === 1 && this.eraseDisplayToStartTouchesContinuation())
559
+ || (mode === 3
560
+ && this.continuation?.buffer === this.altBuffer
561
+ && this.continuation.printedInScrollback);
562
+ if (touches) {
563
+ this.contentInvalidated = true;
564
+ }
565
+ break;
566
+ }
567
+ case 'L':
568
+ case 'M': {
569
+ const region = this.activeScrollRegion();
570
+ this.assignCursor(Math.min(cursor.column, this.columns - 1), cursor.row);
571
+ if (cursor.row >= region.top && cursor.row <= region.bottom) {
572
+ if (this.lineEditTouchesContinuation())
573
+ this.contentInvalidated = true;
574
+ this.assignCursor(0, cursor.row);
575
+ }
576
+ break;
577
+ }
578
+ case 'S':
579
+ case 'T':
580
+ this.contentInvalidated = true;
581
+ break;
582
+ case 'Z':
583
+ this.moveToTab(-1, this.csiParam());
584
+ break;
585
+ case 'b':
586
+ this.moveCursor(this.csiParam(), 0);
587
+ break;
588
+ case 'd':
589
+ this.assignCursor(cursor.column, this.csiParam() - 1 + (this.originMode ? this.activeScrollRegion().top : 0));
590
+ break;
591
+ case 'e':
592
+ this.moveCursor(0, this.csiParam());
593
+ break;
594
+ case 'g':
595
+ if (this.csiParamValues[0] === 0 || this.csiParamValues[0] === 3)
596
+ this.invalidateTabStops();
597
+ break;
598
+ case 'r':
599
+ this.setScrollRegion();
600
+ break;
601
+ default: break;
602
+ }
603
+ }
604
+ emitPrint(text, widthReliable = true) {
605
+ this.carriageReturnContinuation = undefined;
606
+ const cursor = this.cursorByBuffer[this.altBuffer];
607
+ const reliable = this.cursorReliableByBuffer[this.altBuffer];
608
+ const consumesPendingWrap = reliable && cursor.column >= this.columns && this.wraparound;
609
+ if (reliable && cursor.column >= this.columns) {
610
+ if (this.wraparound) {
611
+ cursor.column = 0;
612
+ this.indexCursor(false);
613
+ }
614
+ else {
615
+ cursor.column = this.columns - 1;
616
+ }
617
+ }
618
+ const printedRow = cursor.row;
619
+ const printedColumn = cursor.column;
620
+ const previous = this.continuation;
621
+ const continuous = this.continuation === undefined
622
+ || (this.continuation.buffer === this.altBuffer
623
+ && this.continuation.reliable === reliable
624
+ && (!this.continuation.wrapPending || consumesPendingWrap)
625
+ && ((this.continuation.row === cursor.row && this.continuation.column === cursor.column)
626
+ || (cursor.row === this.continuation.row + 1 && cursor.column === 0)));
627
+ const boundary = this.contentInvalidated || !continuous ? REMAPPED : '';
628
+ this.contentInvalidated = false;
629
+ this.printSequenceByBuffer[this.altBuffer]++;
630
+ const nextColumn = cursor.column + 1;
631
+ if (reliable) {
632
+ cursor.column = this.wraparound ? nextColumn : Math.min(nextColumn, this.columns - 1);
633
+ }
634
+ else {
635
+ cursor.column = Math.min(nextColumn, MAX_CSI_PARAM);
636
+ }
637
+ const nextReliable = reliable && widthReliable;
638
+ this.cursorReliableByBuffer[this.altBuffer] = nextReliable;
639
+ const region = this.activeScrollRegion();
640
+ const wraps = nextReliable && this.wraparound && nextColumn === this.columns;
641
+ const nextRow = wraps
642
+ ? cursor.row === region.bottom || cursor.row === this.rows - 1
643
+ ? cursor.row
644
+ : cursor.row + 1
645
+ : cursor.row;
646
+ this.continuation = {
647
+ buffer: this.altBuffer,
648
+ firstPrintedColumn: boundary === '' && previous?.buffer === this.altBuffer
649
+ ? previous.firstPrintedColumn
650
+ : printedColumn,
651
+ firstPrintedRow: boundary === '' && previous?.buffer === this.altBuffer
652
+ ? previous.firstPrintedRow
653
+ : printedRow,
654
+ lastPrintedColumn: printedColumn,
655
+ lastPrintedRow: printedRow,
656
+ printedInScrollback: boundary === '' && previous?.buffer === this.altBuffer
657
+ ? previous.printedInScrollback
658
+ : false,
659
+ row: nextRow,
660
+ column: wraps ? 0 : nextColumn,
661
+ reliable: nextReliable,
662
+ wrapPending: wraps && nextRow === cursor.row,
663
+ };
664
+ return boundary + text;
665
+ }
666
+ acceptCursorMovement() {
667
+ if (this.continuation?.buffer !== this.altBuffer)
668
+ return;
669
+ const cursor = this.cursorByBuffer[this.altBuffer];
670
+ this.continuation = {
671
+ ...this.continuation,
672
+ row: cursor.row,
673
+ column: cursor.column,
674
+ reliable: this.cursorReliableByBuffer[this.altBuffer],
675
+ wrapPending: false,
676
+ };
677
+ }
678
+ cursorIsAtContinuation() {
679
+ const continuation = this.continuation;
680
+ const cursor = this.cursorByBuffer[this.altBuffer];
681
+ return continuation?.buffer === this.altBuffer
682
+ && continuation.reliable === this.cursorReliableByBuffer[this.altBuffer]
683
+ && continuation.row === cursor.row
684
+ && continuation.column === cursor.column;
685
+ }
686
+ canAcceptVerticalMovement() {
687
+ if (this.cursorIsAtContinuation())
688
+ return true;
689
+ const continuation = this.continuation;
690
+ const cursor = this.cursorByBuffer[this.altBuffer];
691
+ return continuation !== undefined
692
+ && continuation === this.carriageReturnContinuation
693
+ && continuation.buffer === this.altBuffer
694
+ && continuation.reliable === this.cursorReliableByBuffer[this.altBuffer]
695
+ && continuation.row === cursor.row
696
+ && cursor.column === 0;
697
+ }
698
+ executeCursorC0(code, acceptMovement) {
699
+ const cursor = this.cursorByBuffer[this.altBuffer];
700
+ let moved = true;
701
+ let acceptsVerticalMovement = true;
702
+ if (code === 0x08)
703
+ this.moveCursor(-1, 0);
704
+ else if (code === 0x09)
705
+ this.moveToTab(1, 1);
706
+ else if (code === 0x0a || code === 0x0b || code === 0x0c) {
707
+ acceptsVerticalMovement = this.canAcceptVerticalMovement();
708
+ moved = this.indexCursor(true);
709
+ this.carriageReturnContinuation = undefined;
710
+ }
711
+ else if (code === 0x0d) {
712
+ this.carriageReturnContinuation = this.cursorIsAtContinuation()
713
+ ? this.continuation
714
+ : undefined;
715
+ this.assignCursor(0, cursor.row);
716
+ }
717
+ if (acceptMovement && moved && acceptsVerticalMovement)
718
+ this.acceptCursorMovement();
719
+ }
720
+ dispatchCsi(final) {
721
+ this.flushCsiParam();
722
+ if (!this.csiOverflowed) {
723
+ if (this.csiPrefix === '?' && this.csiIntermediates === '') {
724
+ if (final === 'J' || final === 'K')
725
+ this.dispatchCursorCsi(final);
726
+ else
727
+ this.dispatchPrivateMode(final);
728
+ }
729
+ else if (this.csiPrefix === '' && this.csiIntermediates === '' && final === 's') {
730
+ this.saveCursorState();
731
+ }
732
+ else if (this.csiPrefix === '' && this.csiIntermediates === '' && final === 'u') {
733
+ this.restoreCursorState();
734
+ }
735
+ else if (this.csiPrefix === '' && this.csiIntermediates === '' && final === SGR_FINAL) {
736
+ this.dispatchSgr();
737
+ }
738
+ else if (this.csiPrefix === '' && this.csiIntermediates === '') {
739
+ this.dispatchCursorCsi(final);
740
+ }
741
+ else if (this.csiPrefix === ''
742
+ && this.csiIntermediates === "'"
743
+ && (final === '}' || final === '~')) {
744
+ if (this.columnEditTouchesContinuation())
745
+ this.contentInvalidated = true;
746
+ }
747
+ else if (this.csiPrefix === '' && this.csiIntermediates === '!' && final === 'p') {
748
+ this.softReset();
749
+ }
750
+ else if (this.csiPrefix === '' && this.csiIntermediates === ' ' && (final === '@' || final === 'A')) {
751
+ this.contentInvalidated = true;
752
+ }
753
+ }
754
+ const transparent = this.csiPrefix === '' && this.csiIntermediates === '' && final === SGR_FINAL;
755
+ const boundary = this.csiEightBit && !transparent ? REMAPPED : '';
756
+ this.clearCsiCollect();
757
+ this.state = S.ground;
758
+ return boundary;
759
+ }
760
+ activateAltBuffer() {
761
+ if (this.altBuffer === 1)
762
+ return;
763
+ const saved = this.savedByBuffer[1];
764
+ if (saved !== undefined) {
765
+ this.savedByBuffer[1] = { ...saved, continuation: undefined };
766
+ }
767
+ if (this.continuation?.buffer === 1) {
768
+ this.continuation = undefined;
769
+ this.contentInvalidatedByBuffer[1] = true;
770
+ }
771
+ else {
772
+ this.contentInvalidatedByBuffer[1] = false;
773
+ }
774
+ const cursor = this.cursorByBuffer[0];
775
+ this.altBuffer = 1;
776
+ this.cursorByBuffer[1] = { ...cursor };
777
+ this.cursorReliableByBuffer[1] = this.cursorReliableByBuffer[0];
778
+ this.tabStopsReliableByBuffer[1] = true;
779
+ this.scrollRegionByBuffer[1] = this.fullScrollRegion();
780
+ }
781
+ activateMainBuffer() {
782
+ if (this.altBuffer === 0)
783
+ return;
784
+ const cursor = this.cursorByBuffer[1];
785
+ const cursorReliable = this.cursorReliableByBuffer[1];
786
+ this.altBuffer = 0;
787
+ this.cursorByBuffer[0] = { ...cursor };
788
+ this.cursorReliableByBuffer[0] = cursorReliable;
789
+ this.contentInvalidatedByBuffer[1] = false;
790
+ this.cursorByBuffer[1] = { row: 0, column: 0 };
791
+ this.cursorReliableByBuffer[1] = true;
792
+ this.tabStopsReliableByBuffer[1] = true;
793
+ this.scrollRegionByBuffer[1] = this.fullScrollRegion();
794
+ }
795
+ dispatchPrivateMode(final) {
796
+ if (final !== 'h' && final !== 'l')
797
+ return;
798
+ const set = final === 'h';
799
+ for (const param of this.csiParamValues) {
800
+ if (param === 1048) {
801
+ if (set)
802
+ this.saveCursorState();
803
+ else
804
+ this.restoreCursorState();
805
+ }
806
+ else if (param === 1049) {
807
+ if (set) {
808
+ this.saveCursorState();
809
+ this.activateAltBuffer();
810
+ }
811
+ else {
812
+ this.activateMainBuffer();
813
+ this.restoreCursorState();
814
+ }
815
+ }
816
+ else if (param === 47 || param === 1047) {
817
+ if (set)
818
+ this.activateAltBuffer();
819
+ else
820
+ this.activateMainBuffer();
821
+ }
822
+ else if (param === 6) {
823
+ if (!this.cursorReliableByBuffer[this.altBuffer])
824
+ this.contentInvalidated = true;
825
+ this.originMode = set;
826
+ this.setAbsoluteCursor(0, 0);
827
+ }
828
+ else if (param === 7) {
829
+ this.wraparound = set;
830
+ }
831
+ else if (param === 2 && set) {
832
+ this.resetCharsetSlots();
833
+ }
834
+ }
835
+ }
836
+ remapsCode(code) {
837
+ return this.active !== undefined && (REMAPPED_CODES.get(this.active)?.has(code) ?? false);
838
+ }
839
+ write(rawChunk) {
840
+ const chunk = this.pendingHigh + rawChunk;
841
+ this.pendingHigh = '';
842
+ let out = '';
843
+ for (let i = 0; i < chunk.length; i++) {
844
+ let code = chunk.charCodeAt(i);
845
+ let width = 1;
846
+ if (code >= 0xd800 && code <= 0xdbff) {
847
+ if (i + 1 === chunk.length) {
848
+ this.pendingHigh = chunk[i];
849
+ break;
850
+ }
851
+ if ((chunk.charCodeAt(i + 1) & 0xfc00) === 0xdc00) {
852
+ code = 0x10000;
853
+ width = 2;
854
+ }
855
+ }
856
+ if (code === 0xfeff)
857
+ continue;
858
+ if (code >= 0xa0) {
859
+ if (this.state === S.ground) {
860
+ out += this.emitPrint(this.conceal ? REMAPPED : chunk.slice(i, i + width), false);
861
+ }
862
+ else if (!NON_ASCII_IGNORED.has(this.state)) {
863
+ this.pendingIntermediate = undefined;
864
+ this.state = S.ground;
865
+ }
866
+ i += width - 1;
867
+ continue;
868
+ }
869
+ if (CURSOR_MOVING_C0.has(code)) {
870
+ if (EXECUTES_C0.has(this.state)) {
871
+ out += code === 0x0d && this.state !== S.ground ? REMAPPED : chunk[i];
872
+ this.executeCursorC0(code, code !== 0x0d && code !== 0x09);
873
+ }
874
+ continue;
875
+ }
876
+ if ((code === 0x0b || code === 0x0c) && EXECUTES_C0.has(this.state)) {
877
+ this.executeCursorC0(code, true);
878
+ continue;
879
+ }
880
+ if (code === 0x0e || code === 0x0f) {
881
+ if (EXECUTES_C0.has(this.state))
882
+ this.setgLevel(code === 0x0e ? 1 : 0);
883
+ continue;
884
+ }
885
+ if (code === 0x88) {
886
+ this.invalidateTabStops();
887
+ this.pendingIntermediate = undefined;
888
+ this.state = S.ground;
889
+ continue;
890
+ }
891
+ const jump = anywhereTransition(code);
892
+ if (jump !== undefined) {
893
+ this.pendingIntermediate = undefined;
894
+ if (jump === S.csiEntry) {
895
+ this.clearCsiCollect();
896
+ this.csiEightBit = true;
897
+ }
898
+ this.state = jump;
899
+ continue;
900
+ }
901
+ switch (this.state) {
902
+ case S.ground:
903
+ if (code >= 0x20 && code <= 0x7e) {
904
+ out += this.emitPrint(this.conceal || this.remapsCode(code) ? REMAPPED : chunk[i]);
905
+ }
906
+ break;
907
+ case S.escape:
908
+ if (code <= 0x1f || code === 0x7f)
909
+ break;
910
+ if (code <= 0x2f) {
911
+ this.pendingIntermediate = chunk[i];
912
+ this.state = S.escapeIntermediate;
913
+ }
914
+ else if (code === 0x50)
915
+ this.state = S.dcsEntry;
916
+ else if (code === 0x58 || code === 0x5e || code === 0x5f)
917
+ this.state = S.sosPmApcString;
918
+ else if (code === 0x5b) {
919
+ this.clearCsiCollect();
920
+ this.csiEightBit = false;
921
+ this.state = S.csiEntry;
922
+ }
923
+ else if (code === 0x5d)
924
+ this.state = S.oscString;
925
+ else {
926
+ const shifted = LOCKING_SHIFTS[chunk[i]];
927
+ if (shifted !== undefined)
928
+ this.setgLevel(shifted);
929
+ else if (code === 0x37)
930
+ this.saveCursorState();
931
+ else if (code === 0x38)
932
+ this.restoreCursorState();
933
+ else if (code === 0x63) {
934
+ this.fullReset();
935
+ out += REMAPPED;
936
+ }
937
+ else if (code === 0x44) {
938
+ const acceptsMovement = this.canAcceptVerticalMovement();
939
+ const moved = this.indexCursor(true);
940
+ this.carriageReturnContinuation = undefined;
941
+ if (moved && acceptsMovement)
942
+ this.acceptCursorMovement();
943
+ }
944
+ else if (code === 0x45) {
945
+ const cursor = this.cursorByBuffer[this.altBuffer];
946
+ const acceptsMovement = this.canAcceptVerticalMovement();
947
+ const moved = this.indexCursor(true);
948
+ this.assignCursor(0, cursor.row);
949
+ this.carriageReturnContinuation = undefined;
950
+ if (moved && acceptsMovement)
951
+ this.acceptCursorMovement();
952
+ }
953
+ else if (code === 0x4d) {
954
+ this.moveCursor(0, -1);
955
+ out += REMAPPED;
956
+ this.continuation = undefined;
957
+ }
958
+ else if (code === 0x48)
959
+ this.invalidateTabStops();
960
+ this.state = S.ground;
961
+ }
962
+ break;
963
+ case S.escapeIntermediate:
964
+ if (code >= 0x30 && code <= 0x7e) {
965
+ const intermediate = this.pendingIntermediate;
966
+ this.pendingIntermediate = undefined;
967
+ const slot = intermediate === undefined ? undefined : DESIGNATE_INTERMEDIATES[intermediate];
968
+ if (slot !== undefined) {
969
+ if (RECOGNISED_DESIGNATORS.has(chunk[i]))
970
+ this.setgCharset(slot, chunk[i]);
971
+ }
972
+ else if (intermediate === '%' && (code === 0x47 || code === 0x40)) {
973
+ this.selectDefaultCharset();
974
+ }
975
+ else if (intermediate === '#' && code === 0x38)
976
+ out += REMAPPED;
977
+ this.state = S.ground;
978
+ }
979
+ else if (code >= 0x20 && code <= 0x2f) {
980
+ this.pendingIntermediate = undefined;
981
+ }
982
+ break;
983
+ case S.csiEntry:
984
+ if (code >= 0x40 && code <= 0x7e)
985
+ out += this.dispatchCsi(chunk[i]);
986
+ else if (code >= 0x30 && code <= 0x3f) {
987
+ if (code >= 0x3c)
988
+ this.collectCsiPrefix(chunk[i]);
989
+ else
990
+ this.collectCsiParam(chunk[i]);
991
+ this.state = S.csiParam;
992
+ }
993
+ else if (code >= 0x20 && code <= 0x2f) {
994
+ this.collectCsiIntermediate(chunk[i]);
995
+ this.state = S.csiIntermediate;
996
+ }
997
+ break;
998
+ case S.csiParam:
999
+ if (code >= 0x40 && code <= 0x7e)
1000
+ out += this.dispatchCsi(chunk[i]);
1001
+ else if (code >= 0x3c && code <= 0x3f)
1002
+ this.state = S.csiIgnore;
1003
+ else if (code >= 0x20 && code <= 0x2f) {
1004
+ this.collectCsiIntermediate(chunk[i]);
1005
+ this.state = S.csiIntermediate;
1006
+ }
1007
+ else if (code >= 0x30 && code <= 0x3b)
1008
+ this.collectCsiParam(chunk[i]);
1009
+ break;
1010
+ case S.csiIntermediate:
1011
+ if (code >= 0x40 && code <= 0x7e)
1012
+ out += this.dispatchCsi(chunk[i]);
1013
+ else if (code >= 0x30 && code <= 0x3f)
1014
+ this.state = S.csiIgnore;
1015
+ else if (code >= 0x20 && code <= 0x2f)
1016
+ this.collectCsiIntermediate(chunk[i]);
1017
+ break;
1018
+ case S.csiIgnore:
1019
+ if (code >= 0x40 && code <= 0x7e)
1020
+ this.state = S.ground;
1021
+ break;
1022
+ case S.dcsEntry:
1023
+ if (code >= 0x40 && code <= 0x7e)
1024
+ this.state = S.dcsPassthrough;
1025
+ else if (code >= 0x30 && code <= 0x3f)
1026
+ this.state = S.dcsParam;
1027
+ else if (code >= 0x20 && code <= 0x2f)
1028
+ this.state = S.dcsIntermediate;
1029
+ break;
1030
+ case S.dcsParam:
1031
+ if (code >= 0x40 && code <= 0x7e)
1032
+ this.state = S.dcsPassthrough;
1033
+ else if (code >= 0x3c && code <= 0x3f)
1034
+ this.state = S.dcsIgnore;
1035
+ else if (code >= 0x20 && code <= 0x2f)
1036
+ this.state = S.dcsIntermediate;
1037
+ break;
1038
+ case S.dcsIntermediate:
1039
+ if (code >= 0x40 && code <= 0x7e)
1040
+ this.state = S.dcsPassthrough;
1041
+ else if (code >= 0x30 && code <= 0x3f)
1042
+ this.state = S.dcsIgnore;
1043
+ break;
1044
+ case S.oscString:
1045
+ if (code === 0x07)
1046
+ this.state = S.ground;
1047
+ break;
1048
+ default:
1049
+ break;
1050
+ }
1051
+ }
1052
+ return out;
1053
+ }
1054
+ }
1055
+ export function visibleText(text, columns = DEFAULT_COLUMNS, rows = DEFAULT_ROWS) {
1056
+ return new VisibleTextExtractor(columns, rows).write(text);
1057
+ }
1058
+ //# sourceMappingURL=vt-visible-text.js.map