@elefunc/send 0.1.2 → 0.1.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/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/tui/rezi-input-caret.ts +46 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { cac, type CAC } from "cac"
|
|
|
4
4
|
import { cleanRoom } from "./core/protocol"
|
|
5
5
|
import { SendSession, type SessionConfig, type SessionEvent } from "./core/session"
|
|
6
6
|
import { resolvePeerTargets } from "./core/targeting"
|
|
7
|
-
import {
|
|
7
|
+
import { ensureReziInputCaretPatch } from "./tui/rezi-input-caret"
|
|
8
8
|
|
|
9
9
|
export class ExitError extends Error {
|
|
10
10
|
constructor(message: string, readonly code = 1) {
|
|
@@ -194,6 +194,8 @@ const acceptCommand = async (options: Record<string, unknown>) => {
|
|
|
194
194
|
|
|
195
195
|
const tuiCommand = async (options: Record<string, unknown>) => {
|
|
196
196
|
const initialConfig = sessionConfigFrom(options, { autoAcceptIncoming: true, autoSaveIncoming: true })
|
|
197
|
+
await ensureReziInputCaretPatch()
|
|
198
|
+
const { startTui } = await import("./tui/app")
|
|
197
199
|
await startTui(initialConfig, !!options.events)
|
|
198
200
|
}
|
|
199
201
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises"
|
|
2
|
+
import { fileURLToPath } from "node:url"
|
|
3
|
+
|
|
4
|
+
const PATCH_FLAG = Symbol.for("send.rezi.inputCaretPatchInstalled")
|
|
5
|
+
|
|
6
|
+
type PatchedRuntime = {
|
|
7
|
+
[PATCH_FLAG]?: Set<string>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type FilePatchSpec = {
|
|
11
|
+
relativeUrl: string
|
|
12
|
+
before: string
|
|
13
|
+
after: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const INPUT_PATCHES: readonly FilePatchSpec[] = [
|
|
17
|
+
{
|
|
18
|
+
relativeUrl: "./layout/engine/intrinsic.js",
|
|
19
|
+
before: "return ok(clampSize({ w: textW + 2, h: 1 }));",
|
|
20
|
+
after: "return ok(clampSize({ w: textW + 3, h: 1 }));",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
relativeUrl: "./layout/kinds/leaf.js",
|
|
24
|
+
before: "const w = Math.min(maxW, textW + 2);",
|
|
25
|
+
after: "const w = Math.min(maxW, textW + 3);",
|
|
26
|
+
},
|
|
27
|
+
] as const
|
|
28
|
+
|
|
29
|
+
const patchRuntime = globalThis as PatchedRuntime
|
|
30
|
+
|
|
31
|
+
const patchFile = async (spec: FilePatchSpec, coreIndexUrl: string) => {
|
|
32
|
+
const path = fileURLToPath(new URL(spec.relativeUrl, coreIndexUrl))
|
|
33
|
+
const source = await readFile(path, "utf8")
|
|
34
|
+
if (source.includes(spec.after)) return
|
|
35
|
+
if (!source.includes(spec.before)) throw new Error(`Unsupported @rezi-ui/core input layout at ${path}`)
|
|
36
|
+
await writeFile(path, source.replace(spec.before, spec.after))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ensureReziInputCaretPatch = async () => {
|
|
40
|
+
const coreIndexUrl = await import.meta.resolve("@rezi-ui/core")
|
|
41
|
+
const patchedRoots = patchRuntime[PATCH_FLAG] ?? new Set<string>()
|
|
42
|
+
if (patchedRoots.has(coreIndexUrl)) return
|
|
43
|
+
for (const spec of INPUT_PATCHES) await patchFile(spec, coreIndexUrl)
|
|
44
|
+
patchedRoots.add(coreIndexUrl)
|
|
45
|
+
patchRuntime[PATCH_FLAG] = patchedRoots
|
|
46
|
+
}
|