@tui-sandbox/library 7.1.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tui-sandbox/library",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,7 +1,8 @@
1
1
  import { TerminalClient } from "../client/index.js"
2
- import type { BlockingCommandClientInput, LuaCodeClientInput } from "../server/server.js"
2
+ import type { BlockingCommandClientInput, ExCommandClientInput, LuaCodeClientInput } from "../server/server.js"
3
3
  import type {
4
4
  BlockingShellCommandOutput,
5
+ RunExCommandOutput,
5
6
  RunLuaCodeOutput,
6
7
  StartNeovimGenericArguments,
7
8
  TestDirectory,
@@ -35,10 +36,15 @@ window.runLuaCode = async function (input: LuaCodeClientInput): Promise<RunLuaCo
35
36
  return client.runLuaCode(input)
36
37
  }
37
38
 
39
+ window.runExCommand = async function (input: ExCommandClientInput): Promise<RunExCommandOutput> {
40
+ return client.runExCommand(input)
41
+ }
42
+
38
43
  declare global {
39
44
  interface Window {
40
45
  startNeovim(startArguments?: StartNeovimGenericArguments): Promise<TestDirectory>
41
46
  runBlockingShellCommand(input: BlockingCommandClientInput): Promise<BlockingShellCommandOutput>
42
47
  runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
48
+ runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
43
49
  }
44
50
  }
@@ -1,9 +1,15 @@
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 { AppRouter, BlockingCommandClientInput, LuaCodeClientInput } from "../server/server.js"
4
+ import type {
5
+ AppRouter,
6
+ BlockingCommandClientInput,
7
+ ExCommandClientInput,
8
+ LuaCodeClientInput,
9
+ } from "../server/server.js"
5
10
  import type {
6
11
  BlockingShellCommandOutput,
12
+ RunExCommandOutput,
7
13
  RunLuaCodeOutput,
8
14
  StartNeovimGenericArguments,
9
15
  TestDirectory,
@@ -105,4 +111,12 @@ export class TerminalClient {
105
111
  tabId: this.tabId,
106
112
  })
107
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
+ }
108
122
  }
@@ -7,9 +7,14 @@ 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 { BlockingCommandClientInput, LuaCodeClientInput } from "@tui-sandbox/library/dist/src/server/server"
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,
13
18
  RunLuaCodeOutput,
14
19
  StartNeovimGenericArguments,
15
20
  } from "@tui-sandbox/library/dist/src/server/types"
@@ -26,6 +31,7 @@ it("should return the expected contents", async () => {
26
31
  startNeovim(startArguments?: MyStartNeovimServerArguments): Promise<NeovimContext>
27
32
  runBlockingShellCommand(input: BlockingCommandClientInput): Promise<BlockingShellCommandOutput>
28
33
  runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
34
+ runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
29
35
  }
30
36
  }
31
37
 
@@ -62,6 +68,12 @@ it("should return the expected contents", async () => {
62
68
  })
63
69
  })
64
70
 
71
+ Cypress.Commands.add("runExCommand", (input: ExCommandClientInput) => {
72
+ cy.window().then(async win => {
73
+ return await win.runExCommand(input)
74
+ })
75
+ })
76
+
65
77
  before(function () {
66
78
  // disable Cypress's default behavior of logging all XMLHttpRequests and
67
79
  // fetches to the Command Log
@@ -83,6 +95,8 @@ it("should return the expected contents", async () => {
83
95
  runBlockingShellCommand(input: BlockingCommandClientInput): Chainable<BlockingShellCommandOutput>
84
96
 
85
97
  runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>
98
+
99
+ runExCommand(input: ExCommandClientInput): Chainable<RunExCommandOutput>
86
100
  }
87
101
  }
88
102
  }
@@ -6,14 +6,18 @@ 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 { BlockingCommandClientInput, LuaCodeClientInput } from "@tui-sandbox/library/dist/src/server/server"
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,
17
21
  RunLuaCodeOutput,
18
22
  StartNeovimGenericArguments,
19
23
  } from "@tui-sandbox/library/dist/src/server/types"
@@ -30,6 +34,7 @@ declare global {
30
34
  startNeovim(startArguments?: MyStartNeovimServerArguments): Promise<NeovimContext>
31
35
  runBlockingShellCommand(input: BlockingCommandClientInput): Promise<BlockingShellCommandOutput>
32
36
  runLuaCode(input: LuaCodeClientInput): Promise<RunLuaCodeOutput>
37
+ runExCommand(input: ExCommandClientInput): Promise<RunExCommandOutput>
33
38
  }
34
39
  }
35
40
 
@@ -66,6 +71,12 @@ Cypress.Commands.add("runLuaCode", (input: LuaCodeClientInput) => {
66
71
  })
67
72
  })
68
73
 
74
+ Cypress.Commands.add("runExCommand", (input: ExCommandClientInput) => {
75
+ cy.window().then(async win => {
76
+ return await win.runExCommand(input)
77
+ })
78
+ })
79
+
69
80
  before(function () {
70
81
  // disable Cypress's default behavior of logging all XMLHttpRequests and
71
82
  // fetches to the Command Log
@@ -87,6 +98,8 @@ declare global {
87
98
  runBlockingShellCommand(input: BlockingCommandClientInput): Chainable<BlockingShellCommandOutput>
88
99
 
89
100
  runLuaCode(input: LuaCodeClientInput): Chainable<RunLuaCodeOutput>
101
+
102
+ runExCommand(input: ExCommandClientInput): Chainable<RunExCommandOutput>
90
103
  }
91
104
  }
92
105
  }
@@ -2,9 +2,10 @@ 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, LuaCodeInput } from "../server.js"
5
+ import type { BlockingCommandInput, ExCommandInput, LuaCodeInput } from "../server.js"
6
6
  import type {
7
7
  BlockingShellCommandOutput,
8
+ RunExCommandOutput,
8
9
  RunLuaCodeOutput,
9
10
  StartNeovimGenericArguments,
10
11
  TestDirectory,
@@ -141,3 +142,29 @@ export async function runLuaCode(options: LuaCodeInput): Promise<RunLuaCodeOutpu
141
142
  throw new Error(`Error running Lua code: ${options.luaCode}`, { cause: e })
142
143
  }
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
+ }
@@ -29,6 +29,10 @@ const luaCodeInputSchema = z.object({ tabId: tabIdSchema, luaCode: z.string() })
29
29
  export type LuaCodeClientInput = Except<LuaCodeInput, "tabId">
30
30
  export type LuaCodeInput = z.infer<typeof luaCodeInputSchema>
31
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
+
32
36
  /** @private */
33
37
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
34
38
  export async function createAppRouter(config: TestServerConfig) {
@@ -80,6 +84,10 @@ export async function createAppRouter(config: TestServerConfig) {
80
84
  runLuaCode: trpc.procedure.input(luaCodeInputSchema).mutation(options => {
81
85
  return neovim.runLuaCode(options.input)
82
86
  }),
87
+
88
+ runExCommand: trpc.procedure.input(exCommandInputSchema).mutation(options => {
89
+ return neovim.runExCommand(options.input)
90
+ }),
83
91
  }),
84
92
  })
85
93
 
@@ -49,3 +49,5 @@ export type RunLuaCodeOutput = {
49
49
  value?: VimValue
50
50
  // to catch errors, use pcall() in the Lua code
51
51
  }
52
+
53
+ export type RunExCommandOutput = { value?: string }