@effect-tui/react 0.12.0 → 0.12.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.
- package/dist/src/hosts/base.d.ts.map +1 -1
- package/dist/src/hosts/base.js +4 -0
- package/dist/src/hosts/base.js.map +1 -1
- package/dist/src/renderer/input/InputProcessor.d.ts +2 -0
- package/dist/src/renderer/input/InputProcessor.d.ts.map +1 -1
- package/dist/src/renderer/input/InputProcessor.js +21 -2
- package/dist/src/renderer/input/InputProcessor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/hosts/base.ts +4 -0
- package/src/renderer/input/InputProcessor.ts +22 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-tui/react",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "React bindings for @effect-tui/core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"prepublishOnly": "bun run typecheck && bun run build"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@effect-tui/core": "^0.12.
|
|
86
|
+
"@effect-tui/core": "^0.12.3",
|
|
87
87
|
"@effect/platform": "^0.94.0",
|
|
88
88
|
"@effect/platform-bun": "^0.87.0",
|
|
89
89
|
"@effect/rpc": "^0.73.0",
|
package/src/hosts/base.ts
CHANGED
|
@@ -342,6 +342,10 @@ export abstract class BaseHost implements HostInstance {
|
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
insertBefore(child: HostInstance, before: HostInstance): void {
|
|
345
|
+
const existingIdx = this.children.indexOf(child)
|
|
346
|
+
if (existingIdx >= 0) {
|
|
347
|
+
this.children.splice(existingIdx, 1)
|
|
348
|
+
}
|
|
345
349
|
const idx = this.children.indexOf(before)
|
|
346
350
|
if (idx >= 0) {
|
|
347
351
|
this.children.splice(idx, 0, child)
|
|
@@ -16,6 +16,7 @@ export interface InputProcessorConfig {
|
|
|
16
16
|
export class InputProcessor {
|
|
17
17
|
private pasteActive = false
|
|
18
18
|
private pasteBuffer = ""
|
|
19
|
+
private pendingInput = ""
|
|
19
20
|
|
|
20
21
|
constructor(private config: InputProcessorConfig) {}
|
|
21
22
|
|
|
@@ -24,7 +25,8 @@ export class InputProcessor {
|
|
|
24
25
|
* Handles bracketed paste detection, key/mouse event decoding, and dispatch.
|
|
25
26
|
*/
|
|
26
27
|
process(data: Buffer): void {
|
|
27
|
-
let chunk = data.toString("utf8")
|
|
28
|
+
let chunk = this.pendingInput + data.toString("utf8")
|
|
29
|
+
this.pendingInput = ""
|
|
28
30
|
|
|
29
31
|
while (chunk.length > 0) {
|
|
30
32
|
if (this.pasteActive) {
|
|
@@ -64,7 +66,12 @@ export class InputProcessor {
|
|
|
64
66
|
|
|
65
67
|
private emitInput(str: string): void {
|
|
66
68
|
if (!str) return
|
|
67
|
-
const
|
|
69
|
+
const { complete, pending } = this.splitIncompleteCsi(str)
|
|
70
|
+
if (pending) {
|
|
71
|
+
this.pendingInput = pending
|
|
72
|
+
}
|
|
73
|
+
if (!complete) return
|
|
74
|
+
const events = decodeInput(Buffer.from(complete, "utf8"))
|
|
68
75
|
|
|
69
76
|
for (const event of events) {
|
|
70
77
|
if (event.type === "mouse") {
|
|
@@ -96,4 +103,17 @@ export class InputProcessor {
|
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
105
|
}
|
|
106
|
+
|
|
107
|
+
private splitIncompleteCsi(input: string): { complete: string; pending: string } {
|
|
108
|
+
const lastEsc = input.lastIndexOf("\x1b")
|
|
109
|
+
if (lastEsc < 0) return { complete: input, pending: "" }
|
|
110
|
+
|
|
111
|
+
const tail = input.slice(lastEsc)
|
|
112
|
+
// Only buffer if tail looks like the start of a CSI sequence (ESC[...) without a final byte.
|
|
113
|
+
if (tail.startsWith("\x1b[") && !/[A-Za-z~]$/.test(tail)) {
|
|
114
|
+
return { complete: input.slice(0, lastEsc), pending: tail }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { complete: input, pending: "" }
|
|
118
|
+
}
|
|
99
119
|
}
|