dsh-remote-vs 0.23.0 → 0.25.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/README.en.md +49 -15
- package/README.md +40 -14
- package/lib/client.js +45978 -43338
- package/lib/index.js +388 -90
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/CodeEditor.d.ts +17 -0
- package/lib/types/client/EditorPane.d.ts +16 -5
- package/lib/types/client/FloatingPlaceholder.d.ts +16 -5
- package/lib/types/client/RemoteEditorView.d.ts +13 -10
- package/lib/types/client/RemoteRoot.d.ts +5 -5
- package/lib/types/client/SettingsHosts.d.ts +3 -0
- package/lib/types/client/TerminalSnippets.d.ts +36 -0
- package/lib/types/client/TerminalView.d.ts +1 -1
- package/lib/types/client/XTerm.d.ts +33 -0
- package/lib/types/client/api.d.ts +4 -1
- package/lib/types/client/auto-open-remote.d.ts +41 -0
- package/lib/types/client/editor-capability.d.ts +27 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/store.d.ts +59 -4
- package/lib/types/client/terminal-input.d.ts +23 -0
- package/lib/types/client/terminal-snippets.d.ts +86 -0
- package/lib/types/client/use-remote-chat-target.d.ts +2 -0
- package/lib/types/client/view-settings.d.ts +40 -0
- package/lib/types/client/vsc/breadcrumb.d.ts +30 -0
- package/lib/types/client/vsc/editor-caret.d.ts +32 -0
- package/lib/types/client/vsc/editor-langs.d.ts +9 -0
- package/lib/types/client/vsc/editor-settings.d.ts +55 -0
- package/lib/types/client/vsc/image-preview.d.ts +36 -0
- package/lib/types/client/vsc/kit.d.ts +2 -0
- package/lib/types/client/vsc/terminal-clipboard.d.ts +15 -0
- package/lib/types/client/vsc/terminal-line.d.ts +25 -0
- package/lib/types/client/vsc/terminal-links.d.ts +62 -0
- package/lib/types/client/vsc/terminal-theme.d.ts +22 -0
- package/lib/types/client/vsc/terminal-writer.d.ts +52 -0
- package/lib/types/paths.d.ts +9 -0
- package/lib/types/pool.d.ts +25 -0
- package/lib/types/protocol.d.ts +35 -0
- package/lib/types/routes.d.ts +7 -0
- package/lib/types/terminal.d.ts +25 -1
- package/lib/types/view-settings.d.ts +26 -0
- package/lib/{worlds-DXdP4SMn.js → worlds-B7gEDBzC.js} +13 -1
- package/package.json +36 -36
- package/src/client/CodeEditor.tsx +54 -2
- package/src/client/EditorPane.tsx +485 -107
- package/src/client/FloatingPlaceholder.tsx +34 -5
- package/src/client/RemoteEditorView.tsx +14 -11
- package/src/client/RemoteRoot.tsx +20 -125
- package/src/client/SettingsHosts.tsx +81 -3
- package/src/client/TerminalSnippets.tsx +357 -0
- package/src/client/TerminalView.tsx +50 -1
- package/src/client/XTerm.tsx +228 -58
- package/src/client/api.ts +7 -0
- package/src/client/auto-open-remote.ts +439 -0
- package/src/client/editor-capability.ts +42 -0
- package/src/client/i18n.ts +158 -6
- package/src/client/index.tsx +30 -6
- package/src/client/store.tsx +165 -13
- package/src/client/terminal-input.ts +44 -0
- package/src/client/terminal-snippets.ts +216 -0
- package/src/client/use-remote-chat-target.ts +1 -1
- package/src/client/view-settings.ts +99 -0
- package/src/client/vsc/breadcrumb.tsx +251 -0
- package/src/client/vsc/editor-caret.ts +30 -0
- package/src/client/vsc/editor-langs.ts +20 -0
- package/src/client/vsc/editor-settings.ts +146 -0
- package/src/client/vsc/editor-theme.ts +4 -5
- package/src/client/vsc/image-preview.tsx +110 -0
- package/src/client/vsc/kit.tsx +20 -1
- package/src/client/vsc/terminal-clipboard.ts +19 -0
- package/src/client/vsc/terminal-line.ts +101 -0
- package/src/client/vsc/terminal-links.ts +166 -0
- package/src/client/vsc/terminal-theme.ts +71 -0
- package/src/client/vsc/terminal-writer.ts +112 -0
- package/src/client/vsc/vsc.css +687 -48
- package/src/index.ts +6 -0
- package/src/paths.ts +13 -0
- package/src/pool.ts +99 -27
- package/src/protocol.ts +45 -0
- package/src/routes.ts +47 -0
- package/src/terminal.ts +160 -6
- package/src/view-settings.ts +133 -0
package/src/client/XTerm.tsx
CHANGED
|
@@ -5,27 +5,41 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import '@xterm/xterm/css/xterm.css'
|
|
7
7
|
import { useEffect, useRef, type ReactNode } from 'react'
|
|
8
|
-
import { Terminal } from '@xterm/xterm'
|
|
9
|
-
import type { ITheme } from '@xterm/xterm'
|
|
8
|
+
import { Terminal, type ILink, type ILinkProvider } from '@xterm/xterm'
|
|
10
9
|
import { FitAddon } from '@xterm/addon-fit'
|
|
11
10
|
import type { TerminalClientFrame, TerminalServerFrame } from '../protocol.ts'
|
|
12
11
|
import { isDarkScheme, subscribeColorScheme } from './theme.ts'
|
|
13
12
|
import { ContextMenu, useContextMenu, type MenuEntry } from './vsc/kit.tsx'
|
|
14
13
|
import {
|
|
15
|
-
clipboardChordFor,
|
|
16
14
|
createPasteFallback,
|
|
17
15
|
stripBracketedPasteMarkers,
|
|
16
|
+
terminalKeyCommand,
|
|
18
17
|
terminalMenuState,
|
|
19
18
|
} from './vsc/terminal-clipboard.ts'
|
|
19
|
+
import { terminalTheme } from './vsc/terminal-theme.ts'
|
|
20
|
+
import { findTerminalPathTokens } from './vsc/terminal-links.ts'
|
|
21
|
+
import { registerTerminalPaste } from './terminal-input.ts'
|
|
22
|
+
import { createTerminalWriter } from './vsc/terminal-writer.ts'
|
|
23
|
+
import { applyTerminalInput } from './vsc/terminal-line.ts'
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Send one frame; `false` means it was NOT handed to the socket.
|
|
27
|
+
*
|
|
28
|
+
* The caller that tracks "the PTY already knows this size" depends on that
|
|
29
|
+
* answer (see `pushSize`): recording a size that never left is how a terminal
|
|
30
|
+
* used to sit at the URL's 80x24 for the rest of its life.
|
|
31
|
+
*/
|
|
32
|
+
function send(ws: WebSocket, frame: TerminalClientFrame): boolean {
|
|
22
33
|
if (ws.readyState === WebSocket.OPEN) {
|
|
23
34
|
try {
|
|
24
35
|
ws.send(JSON.stringify(frame))
|
|
36
|
+
return true
|
|
25
37
|
} catch {
|
|
26
38
|
// Socket raced away.
|
|
39
|
+
return false
|
|
27
40
|
}
|
|
28
41
|
}
|
|
42
|
+
return false
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
/** Clipboard write with a legacy execCommand fallback (non-secure contexts). */
|
|
@@ -59,53 +73,6 @@ async function readClipboard(): Promise<string | undefined> {
|
|
|
59
73
|
}
|
|
60
74
|
}
|
|
61
75
|
|
|
62
|
-
/** Opaque high-readability palette (opaque: the contrast engine cannot reason about transparency). */
|
|
63
|
-
function buildTheme(dark: boolean): ITheme {
|
|
64
|
-
return dark
|
|
65
|
-
? {
|
|
66
|
-
background: '#0e0e13',
|
|
67
|
-
foreground: '#e8e8e8',
|
|
68
|
-
cursor: '#e8e8e8',
|
|
69
|
-
black: '#000000',
|
|
70
|
-
red: '#cd3131',
|
|
71
|
-
green: '#0dbc79',
|
|
72
|
-
yellow: '#e5e910',
|
|
73
|
-
blue: '#2472c8',
|
|
74
|
-
magenta: '#bc3fbc',
|
|
75
|
-
cyan: '#11a8cd',
|
|
76
|
-
white: '#e5e5e5',
|
|
77
|
-
brightBlack: '#7a7a7a',
|
|
78
|
-
brightRed: '#f14c4c',
|
|
79
|
-
brightGreen: '#23d18b',
|
|
80
|
-
brightYellow: '#f5f543',
|
|
81
|
-
brightBlue: '#3b8eea',
|
|
82
|
-
brightMagenta: '#d670d6',
|
|
83
|
-
brightCyan: '#29b8db',
|
|
84
|
-
brightWhite: '#ffffff',
|
|
85
|
-
}
|
|
86
|
-
: {
|
|
87
|
-
background: '#ffffff',
|
|
88
|
-
foreground: '#1a1a1a',
|
|
89
|
-
cursor: '#1a1a1a',
|
|
90
|
-
black: '#000000',
|
|
91
|
-
red: '#cd3131',
|
|
92
|
-
green: '#00bc67',
|
|
93
|
-
yellow: '#949800',
|
|
94
|
-
blue: '#0451a5',
|
|
95
|
-
magenta: '#bc05bc',
|
|
96
|
-
cyan: '#0598bc',
|
|
97
|
-
white: '#555555',
|
|
98
|
-
brightBlack: '#666666',
|
|
99
|
-
brightRed: '#f14c4c',
|
|
100
|
-
brightGreen: '#23d18b',
|
|
101
|
-
brightYellow: '#f5f543',
|
|
102
|
-
brightBlue: '#3b8eea',
|
|
103
|
-
brightMagenta: '#d670d6',
|
|
104
|
-
brightCyan: '#29b8db',
|
|
105
|
-
brightWhite: '#ffffff',
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
76
|
export function XTerm(props: {
|
|
110
77
|
wsUrl: string
|
|
111
78
|
onReady: (id: string) => void
|
|
@@ -121,6 +88,33 @@ export function XTerm(props: {
|
|
|
121
88
|
initialInput?: string
|
|
122
89
|
/** Translator for the right-click menu (copy / paste / select all). */
|
|
123
90
|
t: (key: string) => string
|
|
91
|
+
/** Tab identity, used by the snippet panel to target THIS terminal. */
|
|
92
|
+
tabId: string
|
|
93
|
+
/**
|
|
94
|
+
* Ctrl/Cmd+B inside the terminal: open the "add snippet" form.
|
|
95
|
+
*
|
|
96
|
+
* Receives a best-effort draft so the form can pre-fill its command: the
|
|
97
|
+
* current terminal SELECTION when there is one (the user picked exactly what
|
|
98
|
+
* they want), else the line reconstructed from this session's keystrokes.
|
|
99
|
+
*
|
|
100
|
+
* Absent → the keystroke stays the shell's (readline's backward-char), which
|
|
101
|
+
* is what a host that did not wire the panel should keep.
|
|
102
|
+
*/
|
|
103
|
+
onQuickAddSnippet?: (draft: { selection?: string; line?: string }) => void
|
|
104
|
+
/**
|
|
105
|
+
* Remote home directory of this tab's host, when known.
|
|
106
|
+
*
|
|
107
|
+
* Used to resolve a `~/x` token printed by the shell. The SSH user's home is
|
|
108
|
+
* the only honest source — the terminal protocol carries no home directory.
|
|
109
|
+
*/
|
|
110
|
+
home?: string
|
|
111
|
+
/**
|
|
112
|
+
* Ctrl/Cmd + click on a path printed in the terminal.
|
|
113
|
+
*
|
|
114
|
+
* Receives the path AS PRINTED plus the hints that make sense of a relative
|
|
115
|
+
* one: the shell's cwd when it reports it (OSC 7) and the remote home.
|
|
116
|
+
*/
|
|
117
|
+
onPathClick?: (token: string, context: { cwd?: string; home?: string }) => void
|
|
124
118
|
}): ReactNode {
|
|
125
119
|
const hostRef = useRef<HTMLDivElement>(null)
|
|
126
120
|
const propsRef = useRef(props)
|
|
@@ -148,12 +142,12 @@ export function XTerm(props: {
|
|
|
148
142
|
fontSize: 13,
|
|
149
143
|
fontFamily: propsRef.current.fontFamily ?? 'var(--ds-font-family-code, ui-monospace, monospace)',
|
|
150
144
|
minimumContrastRatio: 7,
|
|
151
|
-
theme:
|
|
145
|
+
theme: terminalTheme(isDarkScheme()),
|
|
152
146
|
})
|
|
153
147
|
// Re-theme live when the user flips the DSH scheme.
|
|
154
148
|
const unflip = subscribeColorScheme(() => {
|
|
155
149
|
try {
|
|
156
|
-
term.options.theme =
|
|
150
|
+
term.options.theme = terminalTheme(isDarkScheme())
|
|
157
151
|
} catch {
|
|
158
152
|
// Terminal gone.
|
|
159
153
|
}
|
|
@@ -163,8 +157,105 @@ export function XTerm(props: {
|
|
|
163
157
|
term.open(host)
|
|
164
158
|
fit.fit()
|
|
165
159
|
|
|
160
|
+
/**
|
|
161
|
+
* The shell's working directory, when it reports it.
|
|
162
|
+
*
|
|
163
|
+
* OSC 7 (`ESC ] 7 ; file://host/path BEL`) is the standard, prompt-hook-driven
|
|
164
|
+
* way shells announce `pwd`; bash/zsh print it when their profile enables it.
|
|
165
|
+
* It is the only trustworthy anchor for a RELATIVE path printed by a command:
|
|
166
|
+
* without it the click falls back to the workspace roots (see
|
|
167
|
+
* `jumpToTerminalPath`). Silent when absent — nothing to report.
|
|
168
|
+
*/
|
|
169
|
+
let cwd: string | undefined
|
|
170
|
+
const osc7 = term.parser.registerOscHandler(7, (data) => {
|
|
171
|
+
const match = /^file:\/\/[^/]*(\/.*)$/.exec(data)
|
|
172
|
+
if (match?.[1] !== undefined && match[1] !== '') {
|
|
173
|
+
try {
|
|
174
|
+
cwd = decodeURIComponent(match[1])
|
|
175
|
+
} catch {
|
|
176
|
+
// A malformed escape is not worth failing over; keep the raw bytes.
|
|
177
|
+
cwd = match[1]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return true
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Ctrl/Cmd + click on a path printed in the terminal jumps to that folder in
|
|
185
|
+
* the directory tree (`jumpToTerminalPath` validates against the host first).
|
|
186
|
+
*
|
|
187
|
+
* Only paths the tokenizer accepts become links, and the modifier is checked
|
|
188
|
+
* in `activate`: plain clicks keep their normal text-selection behaviour.
|
|
189
|
+
*/
|
|
190
|
+
const linkProvider: ILinkProvider = {
|
|
191
|
+
provideLinks: (lineNumber, callback) => {
|
|
192
|
+
if (propsRef.current.onPathClick === undefined) {
|
|
193
|
+
callback(undefined)
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
const line = term.buffer.active.getLine(lineNumber - 1)
|
|
197
|
+
if (line === undefined) {
|
|
198
|
+
callback(undefined)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
// `trimRight` keeps the columns aligned with the buffer (a wrapped line's
|
|
202
|
+
// trailing blanks must not shift the token indexes).
|
|
203
|
+
const text = line.translateToString(true)
|
|
204
|
+
const tokens = findTerminalPathTokens(text)
|
|
205
|
+
if (tokens.length === 0) {
|
|
206
|
+
callback(undefined)
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
const links: ILink[] = tokens.map(token => ({
|
|
210
|
+
range: {
|
|
211
|
+
start: { x: token.start + 1, y: lineNumber },
|
|
212
|
+
end: { x: token.end + 1, y: lineNumber },
|
|
213
|
+
},
|
|
214
|
+
text: token.path,
|
|
215
|
+
activate: (event: MouseEvent, linkText: string) => {
|
|
216
|
+
// Ctrl (or Cmd on a Mac): a plain click stays a plain click, so
|
|
217
|
+
// selecting text near a path is not hijacked.
|
|
218
|
+
if (!event.ctrlKey && !event.metaKey) return
|
|
219
|
+
propsRef.current.onPathClick?.(linkText, {
|
|
220
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
221
|
+
...(propsRef.current.home === undefined ? {} : { home: propsRef.current.home }),
|
|
222
|
+
})
|
|
223
|
+
},
|
|
224
|
+
}))
|
|
225
|
+
callback(links)
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
const linkRegistration = term.registerLinkProvider(linkProvider)
|
|
229
|
+
/**
|
|
230
|
+
* The snippet panel's handle on THIS terminal: insert a command at the prompt
|
|
231
|
+
* without pressing Enter (see `terminal-input.ts`).
|
|
232
|
+
*
|
|
233
|
+
* `term.paste` is the honest primitive — it goes through xterm's own bracketed
|
|
234
|
+
* paste handling and the normal input path, so the shell sees typed text and
|
|
235
|
+
* still decides when to run it.
|
|
236
|
+
*/
|
|
237
|
+
const unregisterPaste = registerTerminalPaste(propsRef.current.tabId, (text: string) => {
|
|
238
|
+
try {
|
|
239
|
+
term.paste(text)
|
|
240
|
+
term.focus()
|
|
241
|
+
} catch {
|
|
242
|
+
// Terminal disposed mid-call.
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
|
|
166
246
|
const ws = new WebSocket(propsRef.current.wsUrl)
|
|
167
247
|
let opened = false
|
|
248
|
+
/**
|
|
249
|
+
* True once the HOST said `ready` for this socket.
|
|
250
|
+
*
|
|
251
|
+
* Frames sent before that are lost, not queued: the host only attaches its
|
|
252
|
+
* message listener after the shell exists (a cold dial takes seconds), so a
|
|
253
|
+
* `resize` sent on the WebSocket `open` event never reached the PTY — and
|
|
254
|
+
* because the client had already recorded the size, the later push (once the
|
|
255
|
+
* host was listening) was deduped away. The shell then stayed at the URL's
|
|
256
|
+
* 80x24 for its whole life. Sizes are only sent after `ready`.
|
|
257
|
+
*/
|
|
258
|
+
let hostReady = false
|
|
168
259
|
/** The seeded line is typed at most once per mount (a reconnect re-mounts). */
|
|
169
260
|
let seeded = false
|
|
170
261
|
let exitReported = false
|
|
@@ -174,6 +265,12 @@ export function XTerm(props: {
|
|
|
174
265
|
propsRef.current.onExit(code, message)
|
|
175
266
|
}
|
|
176
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Size last pushed to the PTY (`0` = nothing sent yet, so the first push
|
|
270
|
+
* always goes). Declared BEFORE `pushSize` reads it: a `let` declared below
|
|
271
|
+
* would be in its temporal dead zone on the first call.
|
|
272
|
+
*/
|
|
273
|
+
let lastSize = { cols: 0, rows: 0 }
|
|
177
274
|
const pushSize = (): void => {
|
|
178
275
|
if (host.clientWidth < 20 || host.clientHeight < 20) return
|
|
179
276
|
try {
|
|
@@ -181,7 +278,19 @@ export function XTerm(props: {
|
|
|
181
278
|
} catch {
|
|
182
279
|
// Not laid out yet.
|
|
183
280
|
}
|
|
184
|
-
|
|
281
|
+
// Nothing may be sent before the host is listening (see `hostReady`); the
|
|
282
|
+
// `ready` handler pushes the measured size itself.
|
|
283
|
+
if (!hostReady) return
|
|
284
|
+
// Only a CHANGED size is news: the observer fires on every pixel of a
|
|
285
|
+
// window drag, and a resize frame per tick makes the remote shell re-run
|
|
286
|
+
// SIGWINCH handling (full-screen apps redraw) for nothing.
|
|
287
|
+
if (term.cols === lastSize.cols && term.rows === lastSize.rows) return
|
|
288
|
+
// Record the size only once it really left: the observer can fire before
|
|
289
|
+
// the socket is OPEN (and `send` then drops the frame), and remembering a
|
|
290
|
+
// size the PTY never received left the shell at the URL's 80x24 until the
|
|
291
|
+
// user dragged the window.
|
|
292
|
+
const sent = send(ws, { t: 'resize', cols: term.cols, rows: term.rows })
|
|
293
|
+
if (sent) lastSize = { cols: term.cols, rows: term.rows }
|
|
185
294
|
}
|
|
186
295
|
liveRef.current = {
|
|
187
296
|
refit: () => {
|
|
@@ -203,9 +312,20 @@ export function XTerm(props: {
|
|
|
203
312
|
* characters — far under that cap either way, and far above a keystroke.
|
|
204
313
|
*/
|
|
205
314
|
const INPUT_CHUNK_CHARS = 64 * 1024
|
|
315
|
+
/**
|
|
316
|
+
* Best-effort reconstruction of the line the user is typing, for Ctrl+B.
|
|
317
|
+
*
|
|
318
|
+
* Fed from the SAME `onData` stream that goes to the PTY (see
|
|
319
|
+
* `vsc/terminal-line.ts`): printable text appends, backspace removes,
|
|
320
|
+
* Enter/Ctrl+C/Ctrl+U clear, escape sequences are ignored. Used only to
|
|
321
|
+
* pre-fill the snippet form, so an inexact line (history recall, cursor
|
|
322
|
+
* movement) costs nothing.
|
|
323
|
+
*/
|
|
324
|
+
let inputLine = ''
|
|
206
325
|
const sendInput = (rawData: string): void => {
|
|
207
326
|
const data = stripBracketedPasteMarkers(rawData)
|
|
208
327
|
if (data === '') return
|
|
328
|
+
inputLine = applyTerminalInput(inputLine, data)
|
|
209
329
|
if (data.length <= INPUT_CHUNK_CHARS) {
|
|
210
330
|
send(ws, { t: 'in', d: data })
|
|
211
331
|
return
|
|
@@ -221,6 +341,21 @@ export function XTerm(props: {
|
|
|
221
341
|
if (chunk !== '') send(ws, { t: 'in', d: chunk })
|
|
222
342
|
}
|
|
223
343
|
term.onData(sendInput)
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Output writer (see `vsc/terminal-writer.ts` for the full reasoning).
|
|
347
|
+
*
|
|
348
|
+
* Frames are appended to ONE ordered buffer and handed to xterm on a timer,
|
|
349
|
+
* instead of one `term.write` per frame — and, importantly, NOT chained on
|
|
350
|
+
* the xterm write callback. That callback waits for parse+render, which a
|
|
351
|
+
* throttled/occluded window can delay indefinitely; the echo of what the user
|
|
352
|
+
* types then sat in this queue with no echo on screen until the callback
|
|
353
|
+
* finally fired. Nothing here waits for a write to finish.
|
|
354
|
+
*/
|
|
355
|
+
const writer = createTerminalWriter({ write: (text) => { term.write(text) } })
|
|
356
|
+
const writeOut = (text: string): void => {
|
|
357
|
+
writer.push(text)
|
|
358
|
+
}
|
|
224
359
|
ws.addEventListener('open', () => {
|
|
225
360
|
opened = true
|
|
226
361
|
pushSize()
|
|
@@ -233,6 +368,9 @@ export function XTerm(props: {
|
|
|
233
368
|
return
|
|
234
369
|
}
|
|
235
370
|
if (frame.t === 'ready') {
|
|
371
|
+
hostReady = true
|
|
372
|
+
// The host is listening now: apply the size this client really has.
|
|
373
|
+
pushSize()
|
|
236
374
|
propsRef.current.onReady(frame.id)
|
|
237
375
|
// The shell exists now: type the seeded line (a menu entry's `cd`), as a
|
|
238
376
|
// normal input line so the shell echoes it and redraws its prompt.
|
|
@@ -242,7 +380,7 @@ export function XTerm(props: {
|
|
|
242
380
|
send(ws, { t: 'in', d: `${seed}\n` })
|
|
243
381
|
}
|
|
244
382
|
} else if (frame.t === 'out') {
|
|
245
|
-
|
|
383
|
+
writeOut(frame.d)
|
|
246
384
|
} else if (frame.t === 'exit') {
|
|
247
385
|
reportExit(frame.code)
|
|
248
386
|
try {
|
|
@@ -251,7 +389,7 @@ export function XTerm(props: {
|
|
|
251
389
|
// Ignore.
|
|
252
390
|
}
|
|
253
391
|
} else if (frame.t === 'error') {
|
|
254
|
-
|
|
392
|
+
writeOut(`\r\n[dsh-remote] ${frame.message}\r\n`)
|
|
255
393
|
reportExit(null, frame.message)
|
|
256
394
|
}
|
|
257
395
|
})
|
|
@@ -330,14 +468,43 @@ export function XTerm(props: {
|
|
|
330
468
|
}
|
|
331
469
|
host.addEventListener('paste', onPasteEvent, true)
|
|
332
470
|
term.attachCustomKeyEventHandler((e) => {
|
|
333
|
-
|
|
471
|
+
// `terminalKeyCommand` answers undefined for keyup/keypress: xterm invokes
|
|
472
|
+
// this hook for all three, and acting on keyup pasted twice.
|
|
473
|
+
const chord = terminalKeyCommand({
|
|
474
|
+
type: e.type,
|
|
334
475
|
key: e.key,
|
|
335
476
|
ctrl: e.ctrlKey,
|
|
336
477
|
shift: e.shiftKey,
|
|
337
478
|
alt: e.altKey,
|
|
338
479
|
meta: e.metaKey,
|
|
339
480
|
})
|
|
340
|
-
if (chord === undefined)
|
|
481
|
+
if (chord === undefined) {
|
|
482
|
+
/**
|
|
483
|
+
* Ctrl/Cmd+B opens "add snippet".
|
|
484
|
+
*
|
|
485
|
+
* Note the trade-off: in a plain readline, ^B is backward-char. The
|
|
486
|
+
* shortcut is a user requirement, and it is only claimed while the panel
|
|
487
|
+
* is wired (`onQuickAddSnippet` present) — the terminal's own Ctrl+F etc.
|
|
488
|
+
* stay untouched because they go through xterm's keymap, not here.
|
|
489
|
+
*/
|
|
490
|
+
if (
|
|
491
|
+
e.type === 'keydown'
|
|
492
|
+
&& (e.ctrlKey || e.metaKey)
|
|
493
|
+
&& !e.shiftKey
|
|
494
|
+
&& !e.altKey
|
|
495
|
+
&& (e.key === 'b' || e.key === 'B')
|
|
496
|
+
&& propsRef.current.onQuickAddSnippet !== undefined
|
|
497
|
+
) {
|
|
498
|
+
e.preventDefault()
|
|
499
|
+
const selection = term.getSelection()
|
|
500
|
+
propsRef.current.onQuickAddSnippet({
|
|
501
|
+
...(selection !== '' ? { selection } : {}),
|
|
502
|
+
...(inputLine !== '' ? { line: inputLine } : {}),
|
|
503
|
+
})
|
|
504
|
+
return false
|
|
505
|
+
}
|
|
506
|
+
return true
|
|
507
|
+
}
|
|
341
508
|
if (chord === 'copy-interrupt') {
|
|
342
509
|
// Ctrl+C: with a selection the convention is COPY (never SIGINT); without
|
|
343
510
|
// one the key falls through so the remote shell interrupts as usual.
|
|
@@ -387,6 +554,9 @@ export function XTerm(props: {
|
|
|
387
554
|
return () => {
|
|
388
555
|
liveRef.current = undefined
|
|
389
556
|
unflip()
|
|
557
|
+
unregisterPaste()
|
|
558
|
+
linkRegistration.dispose()
|
|
559
|
+
osc7.dispose()
|
|
390
560
|
window.clearTimeout(timer)
|
|
391
561
|
window.removeEventListener('resize', onWindowResize)
|
|
392
562
|
host.removeEventListener('paste', onPasteEvent, true)
|
package/src/client/api.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type RemoteRead,
|
|
27
27
|
type RemoteRoutingStatus,
|
|
28
28
|
type RemoteTimeouts,
|
|
29
|
+
type RemoteViewSettings,
|
|
29
30
|
type RemoteWorkspaceBinding,
|
|
30
31
|
type RemoteWriteConflict,
|
|
31
32
|
type RemoteWriteResult,
|
|
@@ -564,6 +565,12 @@ export const api = {
|
|
|
564
565
|
// -- routing mode (volatile, persists to the profile patch)
|
|
565
566
|
setRoutingMode: (mode: 'off' | 'shadow' | 'enforce') =>
|
|
566
567
|
post<{ mode: 'off' | 'shadow' | 'enforce' }>(REMOTE_API.routing, { mode }).then((r) => r.mode),
|
|
568
|
+
// -- view preferences (auto-open remote page + its width share)
|
|
569
|
+
getViewSettings: () =>
|
|
570
|
+
call<{ settings: RemoteViewSettings }>(REMOTE_API.viewSettings).then((r) => r.settings),
|
|
571
|
+
/** Flat patch: unknown keys are ignored, unusable values keep the stored one. */
|
|
572
|
+
setViewSettings: (patch: Partial<RemoteViewSettings>) =>
|
|
573
|
+
post<{ settings: RemoteViewSettings }>(REMOTE_API.viewSettings, patch).then((r) => r.settings),
|
|
567
574
|
// -- deploy
|
|
568
575
|
deployStatus: (alias: string) =>
|
|
569
576
|
call<{ deploy: RemoteDeployState; helpers: HelperAvailability[] }>(
|