@tui-sandbox/library 7.0.1 → 7.2.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/CHANGELOG.md +19 -0
- package/dist/browser/assets/{index-Bup5cvb2.js → index-D3uBGfVO.js} +7 -7
- package/dist/browser/assets/{index-Bf37MeF1.css → index-D6fBrqAi.css} +1 -1
- package/dist/browser/index.html +2 -2
- package/dist/src/browser/neovim-client.d.ts +4 -2
- package/dist/src/browser/neovim-client.js +6 -0
- package/dist/src/client/terminal-client.d.ts +4 -2
- package/dist/src/client/terminal-client.js +14 -0
- package/dist/src/server/cypress-support/contents.js +26 -3
- package/dist/src/server/cypress-support/contents.test.js +25 -1
- package/dist/src/server/neovim/index.d.ts +4 -2
- package/dist/src/server/neovim/index.js +36 -0
- package/dist/src/server/server.d.ts +62 -0
- package/dist/src/server/server.js +8 -0
- package/dist/src/server/types.d.ts +7 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/browser/neovim-client.ts +18 -2
- package/src/client/style.css +6 -0
- package/src/client/terminal-client.ts +29 -2
- package/src/server/cypress-support/contents.test.ts +25 -1
- package/src/server/cypress-support/contents.ts +26 -3
- package/src/server/neovim/index.ts +60 -2
- package/src/server/server.ts +16 -0
- package/src/server/types.ts +9 -0
- package/tsconfig.json +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tui-sandbox/library",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@catppuccin/palette": "1.7.1",
|
|
11
|
-
"@trpc/client": "11.0.0-rc.
|
|
12
|
-
"@trpc/server": "11.0.0-rc.
|
|
11
|
+
"@trpc/client": "11.0.0-rc.643",
|
|
12
|
+
"@trpc/server": "11.0.0-rc.643",
|
|
13
13
|
"@xterm/addon-attach": "0.11.0",
|
|
14
14
|
"@xterm/addon-fit": "0.10.0",
|
|
15
15
|
"@xterm/xterm": "5.5.0",
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { TerminalClient } from "../client/index.js"
|
|
2
|
-
import type { BlockingCommandClientInput } from "../server/server.js"
|
|
3
|
-
import type {
|
|
2
|
+
import type { BlockingCommandClientInput, ExCommandClientInput, LuaCodeClientInput } from "../server/server.js"
|
|
3
|
+
import type {
|
|
4
|
+
BlockingShellCommandOutput,
|
|
5
|
+
RunExCommandOutput,
|
|
6
|
+
RunLuaCodeOutput,
|
|
7
|
+
StartNeovimGenericArguments,
|
|
8
|
+
TestDirectory,
|
|
9
|
+
} from "../server/types.js"
|
|
4
10
|
|
|
5
11
|
const app = document.querySelector<HTMLElement>("#app")
|
|
6
12
|
if (!app) {
|
|
@@ -26,9 +32,19 @@ window.runBlockingShellCommand = async function (
|
|
|
26
32
|
return client.runBlockingShellCommand(input)
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
window.runLuaCode = async function (input: LuaCodeClientInput): Promise<RunLuaCodeOutput> {
|
|
36
|
+
return client.runLuaCode(input)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
window.runExCommand = async function (input: ExCommandClientInput): Promise<RunExCommandOutput> {
|
|
40
|
+
return client.runExCommand(input)
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
declare global {
|
|
30
44
|
interface Window {
|
|
31
45
|
startNeovim(startArguments?: StartNeovimGenericArguments): Promise<TestDirectory>
|
|
32
46
|
runBlockingShellCommand(input: BlockingCommandClientInput): Promise<BlockingShellCommandOutput>
|
|
47
|
+
runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
|
|
48
|
+
runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
|
|
33
49
|
}
|
|
34
50
|
}
|
package/src/client/style.css
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { createTRPCClient, httpBatchLink, splitLink, unstable_httpSubscriptionLink } from "@trpc/client"
|
|
2
2
|
import type { Terminal } from "@xterm/xterm"
|
|
3
3
|
import "@xterm/xterm/css/xterm.css"
|
|
4
|
-
import type {
|
|
5
|
-
|
|
4
|
+
import type {
|
|
5
|
+
AppRouter,
|
|
6
|
+
BlockingCommandClientInput,
|
|
7
|
+
ExCommandClientInput,
|
|
8
|
+
LuaCodeClientInput,
|
|
9
|
+
} from "../server/server.js"
|
|
10
|
+
import type {
|
|
11
|
+
BlockingShellCommandOutput,
|
|
12
|
+
RunExCommandOutput,
|
|
13
|
+
RunLuaCodeOutput,
|
|
14
|
+
StartNeovimGenericArguments,
|
|
15
|
+
TestDirectory,
|
|
16
|
+
} from "../server/types.js"
|
|
6
17
|
import "./style.css"
|
|
7
18
|
import { getTabId, startTerminal } from "./websocket-client.js"
|
|
8
19
|
|
|
@@ -92,4 +103,20 @@ export class TerminalClient {
|
|
|
92
103
|
tabId: this.tabId,
|
|
93
104
|
})
|
|
94
105
|
}
|
|
106
|
+
|
|
107
|
+
public async runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput> {
|
|
108
|
+
await this.ready
|
|
109
|
+
return this.trpc.neovim.runLuaCode.mutate({
|
|
110
|
+
luaCode: input.luaCode,
|
|
111
|
+
tabId: this.tabId,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public async runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput> {
|
|
116
|
+
await this.ready
|
|
117
|
+
return this.trpc.neovim.runExCommand.mutate({
|
|
118
|
+
command: input.command,
|
|
119
|
+
tabId: this.tabId,
|
|
120
|
+
})
|
|
121
|
+
}
|
|
95
122
|
}
|
|
@@ -7,9 +7,15 @@ it("should return the expected contents", async () => {
|
|
|
7
7
|
//
|
|
8
8
|
// This file is autogenerated by tui-sandbox. Do not edit it directly.
|
|
9
9
|
//
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
BlockingCommandClientInput,
|
|
12
|
+
ExCommandClientInput,
|
|
13
|
+
LuaCodeClientInput,
|
|
14
|
+
} from "@tui-sandbox/library/dist/src/server/server"
|
|
11
15
|
import type {
|
|
12
16
|
BlockingShellCommandOutput,
|
|
17
|
+
RunExCommandOutput,
|
|
18
|
+
RunLuaCodeOutput,
|
|
13
19
|
StartNeovimGenericArguments,
|
|
14
20
|
} from "@tui-sandbox/library/dist/src/server/types"
|
|
15
21
|
import type { OverrideProperties } from "type-fest"
|
|
@@ -24,6 +30,8 @@ it("should return the expected contents", async () => {
|
|
|
24
30
|
interface Window {
|
|
25
31
|
startNeovim(startArguments?: MyStartNeovimServerArguments): Promise<NeovimContext>
|
|
26
32
|
runBlockingShellCommand(input: BlockingCommandClientInput): Promise<BlockingShellCommandOutput>
|
|
33
|
+
runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
|
|
34
|
+
runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
|
|
@@ -54,6 +62,18 @@ it("should return the expected contents", async () => {
|
|
|
54
62
|
cy.get("textarea").focus().type(text, options)
|
|
55
63
|
})
|
|
56
64
|
|
|
65
|
+
Cypress.Commands.add("runLuaCode", (input: LuaCodeClientInput) => {
|
|
66
|
+
cy.window().then(async win => {
|
|
67
|
+
return await win.runLuaCode(input)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
Cypress.Commands.add("runExCommand", (input: ExCommandClientInput) => {
|
|
72
|
+
cy.window().then(async win => {
|
|
73
|
+
return await win.runExCommand(input)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
57
77
|
before(function () {
|
|
58
78
|
// disable Cypress's default behavior of logging all XMLHttpRequests and
|
|
59
79
|
// fetches to the Command Log
|
|
@@ -73,6 +93,10 @@ it("should return the expected contents", async () => {
|
|
|
73
93
|
/** Runs a shell command in a blocking manner, waiting for the command to
|
|
74
94
|
* finish before returning. Requires neovim to be running. */
|
|
75
95
|
runBlockingShellCommand(input: BlockingCommandClientInput): Chainable<BlockingShellCommandOutput>
|
|
96
|
+
|
|
97
|
+
runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>
|
|
98
|
+
|
|
99
|
+
runExCommand(input: ExCommandClientInput): Chainable<RunExCommandOutput>
|
|
76
100
|
}
|
|
77
101
|
}
|
|
78
102
|
}
|
|
@@ -6,14 +6,19 @@ const __filename = fileURLToPath(import.meta.url)
|
|
|
6
6
|
export async function createCypressSupportFileContents(): Promise<string> {
|
|
7
7
|
// this is the interface of tui-sandbox as far as cypress in the user's
|
|
8
8
|
// application is concerned
|
|
9
|
-
let text =
|
|
10
|
-
/// <reference types="cypress" />
|
|
9
|
+
let text = `/// <reference types="cypress" />
|
|
11
10
|
//
|
|
12
11
|
// This file is autogenerated by tui-sandbox. Do not edit it directly.
|
|
13
12
|
//
|
|
14
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
BlockingCommandClientInput,
|
|
15
|
+
ExCommandClientInput,
|
|
16
|
+
LuaCodeClientInput,
|
|
17
|
+
} from "@tui-sandbox/library/dist/src/server/server"
|
|
15
18
|
import type {
|
|
16
19
|
BlockingShellCommandOutput,
|
|
20
|
+
RunExCommandOutput,
|
|
21
|
+
RunLuaCodeOutput,
|
|
17
22
|
StartNeovimGenericArguments,
|
|
18
23
|
} from "@tui-sandbox/library/dist/src/server/types"
|
|
19
24
|
import type { OverrideProperties } from "type-fest"
|
|
@@ -28,6 +33,8 @@ declare global {
|
|
|
28
33
|
interface Window {
|
|
29
34
|
startNeovim(startArguments?: MyStartNeovimServerArguments): Promise<NeovimContext>
|
|
30
35
|
runBlockingShellCommand(input: BlockingCommandClientInput): Promise<BlockingShellCommandOutput>
|
|
36
|
+
runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
|
|
37
|
+
runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
40
|
|
|
@@ -58,6 +65,18 @@ Cypress.Commands.add("typeIntoTerminal", (text: string, options?: Partial<Cypres
|
|
|
58
65
|
cy.get("textarea").focus().type(text, options)
|
|
59
66
|
})
|
|
60
67
|
|
|
68
|
+
Cypress.Commands.add("runLuaCode", (input: LuaCodeClientInput) => {
|
|
69
|
+
cy.window().then(async win => {
|
|
70
|
+
return await win.runLuaCode(input)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
Cypress.Commands.add("runExCommand", (input: ExCommandClientInput) => {
|
|
75
|
+
cy.window().then(async win => {
|
|
76
|
+
return await win.runExCommand(input)
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
61
80
|
before(function () {
|
|
62
81
|
// disable Cypress's default behavior of logging all XMLHttpRequests and
|
|
63
82
|
// fetches to the Command Log
|
|
@@ -77,6 +96,10 @@ declare global {
|
|
|
77
96
|
/** Runs a shell command in a blocking manner, waiting for the command to
|
|
78
97
|
* finish before returning. Requires neovim to be running. */
|
|
79
98
|
runBlockingShellCommand(input: BlockingCommandClientInput): Chainable<BlockingShellCommandOutput>
|
|
99
|
+
|
|
100
|
+
runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>
|
|
101
|
+
|
|
102
|
+
runExCommand(input: ExCommandClientInput): Chainable<RunExCommandOutput>
|
|
80
103
|
}
|
|
81
104
|
}
|
|
82
105
|
}
|
|
@@ -2,8 +2,14 @@ import assert from "assert"
|
|
|
2
2
|
import { exec } from "child_process"
|
|
3
3
|
import "core-js/proposals/async-explicit-resource-management.js"
|
|
4
4
|
import util from "util"
|
|
5
|
-
import type { BlockingCommandInput } from "../server.js"
|
|
6
|
-
import type {
|
|
5
|
+
import type { BlockingCommandInput, ExCommandInput, LuaCodeInput } from "../server.js"
|
|
6
|
+
import type {
|
|
7
|
+
BlockingShellCommandOutput,
|
|
8
|
+
RunExCommandOutput,
|
|
9
|
+
RunLuaCodeOutput,
|
|
10
|
+
StartNeovimGenericArguments,
|
|
11
|
+
TestDirectory,
|
|
12
|
+
} from "../types.js"
|
|
7
13
|
import type { TestServerConfig } from "../updateTestdirectorySchemaFile.js"
|
|
8
14
|
import { convertEventEmitterToAsyncGenerator } from "../utilities/generator.js"
|
|
9
15
|
import type { TabId } from "../utilities/tabId.js"
|
|
@@ -110,3 +116,55 @@ export async function runBlockingShellCommand(
|
|
|
110
116
|
throw new Error(`Error running shell blockingCommand (${input.command})`, { cause: e })
|
|
111
117
|
}
|
|
112
118
|
}
|
|
119
|
+
|
|
120
|
+
export async function runLuaCode(options: LuaCodeInput): Promise<RunLuaCodeOutput> {
|
|
121
|
+
const neovim = neovims.get(options.tabId.tabId)
|
|
122
|
+
assert(
|
|
123
|
+
neovim !== undefined,
|
|
124
|
+
`Neovim instance for clientId not found - cannot run Lua code. Maybe neovim's not started yet?`
|
|
125
|
+
)
|
|
126
|
+
assert(
|
|
127
|
+
neovim.application,
|
|
128
|
+
`Neovim application not found for client id ${options.tabId.tabId}. Maybe it's not started yet?`
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
const api = await neovim.state?.client.get()
|
|
132
|
+
if (!api) {
|
|
133
|
+
throw new Error(`Neovim API not available for client id ${options.tabId.tabId}. Maybe it's not started yet?`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.log(`Neovim ${neovim.application.processId()} running Lua code: ${options.luaCode}`)
|
|
137
|
+
try {
|
|
138
|
+
const value = await api.lua(options.luaCode)
|
|
139
|
+
return { value }
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.warn(`Error running Lua code: ${options.luaCode}`, e)
|
|
142
|
+
throw new Error(`Error running Lua code: ${options.luaCode}`, { cause: e })
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function runExCommand(options: ExCommandInput): Promise<RunExCommandOutput> {
|
|
147
|
+
const neovim = neovims.get(options.tabId.tabId)
|
|
148
|
+
assert(
|
|
149
|
+
neovim !== undefined,
|
|
150
|
+
`Neovim instance for clientId not found - cannot runExCommand. Maybe neovim's not started yet?`
|
|
151
|
+
)
|
|
152
|
+
assert(
|
|
153
|
+
neovim.application,
|
|
154
|
+
`Neovim application not found for client id ${options.tabId.tabId}. Maybe it's not started yet?`
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
const api = await neovim.state?.client.get()
|
|
158
|
+
if (!api) {
|
|
159
|
+
throw new Error(`Neovim API not available for client id ${options.tabId.tabId}. Maybe it's not started yet?`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(`Neovim ${neovim.application.processId()} running Ex command: ${options.command}`)
|
|
163
|
+
try {
|
|
164
|
+
const output = await api.commandOutput(options.command)
|
|
165
|
+
return { value: output }
|
|
166
|
+
} catch (e) {
|
|
167
|
+
console.warn(`Error running Ex command: ${options.command}`, e)
|
|
168
|
+
throw new Error(`Error running Ex command: ${options.command}`, { cause: e })
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/server/server.ts
CHANGED
|
@@ -25,6 +25,14 @@ const blockingCommandInputSchema = z.object({
|
|
|
25
25
|
export type BlockingCommandClientInput = Except<BlockingCommandInput, "tabId">
|
|
26
26
|
export type BlockingCommandInput = z.infer<typeof blockingCommandInputSchema>
|
|
27
27
|
|
|
28
|
+
const luaCodeInputSchema = z.object({ tabId: tabIdSchema, luaCode: z.string() })
|
|
29
|
+
export type LuaCodeClientInput = Except<LuaCodeInput, "tabId">
|
|
30
|
+
export type LuaCodeInput = z.infer<typeof luaCodeInputSchema>
|
|
31
|
+
|
|
32
|
+
const exCommandInputSchema = z.object({ tabId: tabIdSchema, command: z.string() })
|
|
33
|
+
export type ExCommandClientInput = Except<ExCommandInput, "tabId">
|
|
34
|
+
export type ExCommandInput = z.infer<typeof exCommandInputSchema>
|
|
35
|
+
|
|
28
36
|
/** @private */
|
|
29
37
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
30
38
|
export async function createAppRouter(config: TestServerConfig) {
|
|
@@ -72,6 +80,14 @@ export async function createAppRouter(config: TestServerConfig) {
|
|
|
72
80
|
runBlockingShellCommand: trpc.procedure.input(blockingCommandInputSchema).mutation(async options => {
|
|
73
81
|
return neovim.runBlockingShellCommand(options.signal, options.input, options.input.allowFailure ?? false)
|
|
74
82
|
}),
|
|
83
|
+
|
|
84
|
+
runLuaCode: trpc.procedure.input(luaCodeInputSchema).mutation(options => {
|
|
85
|
+
return neovim.runLuaCode(options.input)
|
|
86
|
+
}),
|
|
87
|
+
|
|
88
|
+
runExCommand: trpc.procedure.input(exCommandInputSchema).mutation(options => {
|
|
89
|
+
return neovim.runExCommand(options.input)
|
|
90
|
+
}),
|
|
75
91
|
}),
|
|
76
92
|
})
|
|
77
93
|
|
package/src/server/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { VimValue } from "neovim/lib/types/VimValue.js"
|
|
2
|
+
|
|
1
3
|
/** Describes the contents of the test directory, which is a blueprint for
|
|
2
4
|
* files and directories. Tests can create a unique, safe environment for
|
|
3
5
|
* interacting with the contents of such a directory.
|
|
@@ -42,3 +44,10 @@ export type BlockingShellCommandOutput =
|
|
|
42
44
|
// for now we log the error to the server's console output. It will be
|
|
43
45
|
// visible when running the tests.
|
|
44
46
|
}
|
|
47
|
+
|
|
48
|
+
export type RunLuaCodeOutput = {
|
|
49
|
+
value?: VimValue
|
|
50
|
+
// to catch errors, use pcall() in the Lua code
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type RunExCommandOutput = { value?: string }
|