@fish-under-sea/dsh-ssh-fish 1.0.2 → 1.1.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/NOTICE +1 -1
- package/README.en.md +5 -5
- package/README.md +5 -5
- package/README.zh.md +5 -5
- package/lib/client.js +783 -170
- package/lib/client.js.map +1 -1
- package/lib/index.js +128 -14
- package/lib/types/client/api.d.ts +21 -0
- package/lib/types/client/locales.d.ts +13 -2
- package/lib/types/client/panel/TerminalTab.d.ts +12 -7
- package/lib/types/client/panel/controller.d.ts +185 -21
- package/lib/types/engine/connection-pool.d.ts +52 -1
- package/lib/types/engine.d.ts +7 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +18 -1
- package/lib/types/store.d.ts +7 -0
- package/lib/types/tool-surface.d.ts +1 -0
- package/lib/types/tools.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +24 -21
- package/src/client/api.ts +70 -0
- package/src/client/index.ts +1 -2
- package/src/client/locales.ts +26 -4
- package/src/client/panel/HostFormDialog.tsx +16 -2
- package/src/client/panel/HostsTab.tsx +3 -0
- package/src/client/panel/SshPanel.tsx +7 -15
- package/src/client/panel/TerminalTab.tsx +371 -151
- package/src/client/panel/controller.ts +370 -30
- package/src/client/panel/panel.module.css +108 -0
- package/src/client/settings-binding.ts +0 -1
- package/src/engine/connection-pool.ts +96 -4
- package/src/engine.ts +10 -0
- package/src/index.ts +16 -1
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +18 -1
- package/src/routes.ts +4 -1
- package/src/store.ts +26 -0
- package/src/tool-surface.ts +1 -0
- package/src/tools.ts +9 -4
|
@@ -5,24 +5,75 @@
|
|
|
5
5
|
* style) so the sidebar row and the React panel share one tiny subscription
|
|
6
6
|
* surface. The state lives only for the browser session (no persistence).
|
|
7
7
|
*
|
|
8
|
-
* The active tab, the hosts-tab connect request
|
|
9
|
-
*
|
|
10
|
-
* keyed page only while its panel is selected, so
|
|
11
|
-
* reset the tab on every panel switch and lose
|
|
8
|
+
* The active tab, the hosts-tab connect request, the terminal tabs and their
|
|
9
|
+
* host session ids live here rather than inside the panel components: the
|
|
10
|
+
* layout mounts a keyed page only while its panel is selected, so
|
|
11
|
+
* component-local state would reset the tab on every panel switch and lose
|
|
12
|
+
* the ids a reattach needs.
|
|
13
|
+
*
|
|
14
|
+
* Terminal tabs (issue #1950) are records, not sockets. One tab is the tab
|
|
15
|
+
* shown in the single xterm; a tab that is not shown either owns a detached
|
|
16
|
+
* host session (reattached by id, which replays the host scrollback) or no
|
|
17
|
+
* session at all. The controller is also the place where a still-connecting
|
|
18
|
+
* socket is adopted when a view goes away: a connection that has not reported
|
|
19
|
+
* its session id yet cannot be detached, so dropping it would leave the host
|
|
20
|
+
* PTY with no owner (the orphan the reference implementation produced).
|
|
12
21
|
*/
|
|
13
22
|
|
|
23
|
+
import type { TerminalConnection } from '../api.ts'
|
|
24
|
+
|
|
14
25
|
/** The panel's tab identifiers. */
|
|
15
26
|
export type SshTab = 'hosts' | 'terminal' | 'transfer' | 'tunnels' | 'cluster'
|
|
16
27
|
|
|
17
|
-
/**
|
|
18
|
-
export
|
|
28
|
+
/** Stable id shared by the sidebar panel row and the main-slot page. */
|
|
29
|
+
export const SSH_PANEL_ID = 'ssh'
|
|
30
|
+
|
|
31
|
+
/** Lifecycle of one terminal tab. */
|
|
32
|
+
export type TerminalTabStatus =
|
|
33
|
+
/** Socket open, the host has not reported a session id yet. */
|
|
34
|
+
| 'connecting'
|
|
35
|
+
/** The host reported a session id; the shell is live. */
|
|
36
|
+
| 'connected'
|
|
37
|
+
/** The remote shell ended. The tab keeps its screen; the session id is cleared. */
|
|
38
|
+
| 'exited'
|
|
39
|
+
/** The connection failed. The tab keeps the reason; the session id is cleared. */
|
|
40
|
+
| 'error'
|
|
41
|
+
|
|
42
|
+
/** A keyboard-interactive challenge waiting for this tab's answer. */
|
|
43
|
+
export interface TerminalAuthPrompt {
|
|
44
|
+
name: string
|
|
45
|
+
instructions: string
|
|
46
|
+
prompts: Array<{ prompt: string; echo: boolean }>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One terminal tab, independent of the socket that currently serves it. */
|
|
50
|
+
export interface TerminalTabRecord {
|
|
51
|
+
/** Local tab id, stable across panel switches (never the host session id). */
|
|
52
|
+
id: string
|
|
53
|
+
/** Host alias this tab opened. Several tabs may share one alias. */
|
|
19
54
|
alias: string
|
|
20
|
-
|
|
21
|
-
|
|
55
|
+
status: TerminalTabStatus
|
|
56
|
+
/** Host-side PTY session id, present only while the shell is live. */
|
|
57
|
+
sessionId?: string
|
|
58
|
+
/** Exit or failure text for the `exited` / `error` states. */
|
|
59
|
+
detail?: string
|
|
60
|
+
/** Code of a close that never reached the host; the tab is kept. */
|
|
61
|
+
closeError?: string
|
|
62
|
+
/** Challenge captured for this tab, whoever was on screen when it arrived. */
|
|
63
|
+
authPrompt?: TerminalAuthPrompt
|
|
64
|
+
/**
|
|
65
|
+
* The answer being typed for {@link TerminalTabRecord.authPrompt}, owned by
|
|
66
|
+
* this tab: one shared draft let a challenge on tab B inherit (and submit)
|
|
67
|
+
* the characters typed for tab A.
|
|
68
|
+
*/
|
|
69
|
+
authAnswers?: string[]
|
|
22
70
|
}
|
|
23
71
|
|
|
24
|
-
/**
|
|
25
|
-
export
|
|
72
|
+
/** The terminal fields a later step may change on one tab. */
|
|
73
|
+
export type TerminalTabPatch = Omit<TerminalTabRecord, 'id' | 'alias'>
|
|
74
|
+
|
|
75
|
+
/** What to do with an adopted connection once the host reports its session. */
|
|
76
|
+
export type TerminalLinkIntent = 'detach' | 'close'
|
|
26
77
|
|
|
27
78
|
/** Immutable controller snapshot for UI subscriptions. */
|
|
28
79
|
export interface PanelControllerSnapshot {
|
|
@@ -30,10 +81,12 @@ export interface PanelControllerSnapshot {
|
|
|
30
81
|
panelOpen: boolean
|
|
31
82
|
/** The tab the panel is showing. */
|
|
32
83
|
activeTab: SshTab
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
|
|
84
|
+
/** Every terminal tab, in strip order. */
|
|
85
|
+
terminalTabs: readonly TerminalTabRecord[]
|
|
86
|
+
/** The tab the single xterm is bound to, or undefined when there is none. */
|
|
87
|
+
activeTerminalTabId: string | undefined
|
|
88
|
+
/** Host picked in the terminal toolbar; the next tab opens on it. */
|
|
89
|
+
draftAlias: string
|
|
37
90
|
}
|
|
38
91
|
|
|
39
92
|
/**
|
|
@@ -53,19 +106,52 @@ export interface PanelControllerDeps {
|
|
|
53
106
|
panel?: PanelNavigationFace
|
|
54
107
|
}
|
|
55
108
|
|
|
109
|
+
/** Byte cap for the retained screen of one tab (the host buffers 256 KiB too). */
|
|
110
|
+
const MAX_RETAINED_BYTES = 256 * 1024
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* UTF-8 byte length of one chunk, without node's Buffer (this half is bundled
|
|
114
|
+
* for the browser). Surrogate pairs count as the four bytes they encode to.
|
|
115
|
+
* @param text - the output chunk.
|
|
116
|
+
* @returns its UTF-8 byte length.
|
|
117
|
+
*/
|
|
118
|
+
function utf8Bytes(text: string): number {
|
|
119
|
+
let bytes = 0
|
|
120
|
+
for (const char of text) {
|
|
121
|
+
const code = char.codePointAt(0) ?? 0
|
|
122
|
+
bytes += code < 0x80 ? 1 : code < 0x800 ? 2 : code < 0x10000 ? 3 : 4
|
|
123
|
+
}
|
|
124
|
+
return bytes
|
|
125
|
+
}
|
|
126
|
+
|
|
56
127
|
/** The panel state owner the sidebar row and the view both read. */
|
|
57
128
|
export class PanelController {
|
|
58
129
|
private panelOpen = false
|
|
59
130
|
private activeTab: SshTab = 'hosts'
|
|
60
|
-
private
|
|
61
|
-
private
|
|
131
|
+
private terminalTabs: readonly TerminalTabRecord[] = []
|
|
132
|
+
private activeTerminalTabId: string | undefined
|
|
133
|
+
private draftAlias = ''
|
|
134
|
+
private nextTerminalTabSeq = 0
|
|
62
135
|
private listeners = new Set<() => void>()
|
|
136
|
+
/**
|
|
137
|
+
* Last screen of each tab, kept outside the snapshot: terminal output must
|
|
138
|
+
* not re-render the panel on every chunk, and only the terminal view reads
|
|
139
|
+
* this (when a tab has no session left to replay from).
|
|
140
|
+
*/
|
|
141
|
+
private readonly retainedScreens = new Map<string, { chunks: string[]; bytes: number }>()
|
|
142
|
+
/**
|
|
143
|
+
* Sockets that outlived their view while still connecting. Their session id
|
|
144
|
+
* is unknown, so they cannot be detached yet; keeping them here is what
|
|
145
|
+
* prevents a host PTY with no owner.
|
|
146
|
+
*/
|
|
147
|
+
private readonly adoptedLinks = new Map<string, { connection: TerminalConnection; intent: TerminalLinkIntent }>()
|
|
63
148
|
/** Cached so getSnapshot is referentially stable between changes. */
|
|
64
149
|
private snapshot: PanelControllerSnapshot = {
|
|
65
150
|
panelOpen: false,
|
|
66
151
|
activeTab: 'hosts',
|
|
67
|
-
|
|
68
|
-
|
|
152
|
+
terminalTabs: [],
|
|
153
|
+
activeTerminalTabId: undefined,
|
|
154
|
+
draftAlias: '',
|
|
69
155
|
}
|
|
70
156
|
|
|
71
157
|
constructor(private readonly deps: PanelControllerDeps = {}) {}
|
|
@@ -124,33 +210,287 @@ export class PanelController {
|
|
|
124
210
|
this.commit()
|
|
125
211
|
}
|
|
126
212
|
|
|
127
|
-
/**
|
|
213
|
+
/**
|
|
214
|
+
* Hand the terminal tab a host to connect to (the hosts-tab "connect"
|
|
215
|
+
* action): the tab exists before the view does, so a panel switch during the
|
|
216
|
+
* handshake still shows the connecting tab and adopts its socket.
|
|
217
|
+
* @param alias - the configured host alias.
|
|
218
|
+
*/
|
|
128
219
|
requestConnect(alias: string): void {
|
|
129
|
-
this.connectRequest = { alias, nonce: Date.now() }
|
|
130
220
|
this.activeTab = 'terminal'
|
|
221
|
+
this.openTerminalTab(alias)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Add a terminal tab on the alias and make it the shown one. Several tabs
|
|
226
|
+
* may target one alias on purpose: each owns its own host PTY.
|
|
227
|
+
* @param alias - the configured host alias.
|
|
228
|
+
* @returns the new tab id.
|
|
229
|
+
*/
|
|
230
|
+
openTerminalTab(alias: string): string {
|
|
231
|
+
this.nextTerminalTabSeq += 1
|
|
232
|
+
const id = 'tab-' + String(this.nextTerminalTabSeq)
|
|
233
|
+
this.terminalTabs = [...this.terminalTabs, { id, alias, status: 'connecting' }]
|
|
234
|
+
this.activeTerminalTabId = id
|
|
235
|
+
this.draftAlias = alias
|
|
236
|
+
this.retainedScreens.delete(id)
|
|
237
|
+
this.commit()
|
|
238
|
+
return id
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Show an existing tab and make the toolbar follow its host, so a new tab
|
|
243
|
+
* opens on the host the user is looking at.
|
|
244
|
+
* @param id - the tab id.
|
|
245
|
+
*/
|
|
246
|
+
setActiveTerminalTab(id: string): void {
|
|
247
|
+
if (this.activeTerminalTabId === id) return
|
|
248
|
+
const tab = this.terminalTab(id)
|
|
249
|
+
if (tab === undefined) return
|
|
250
|
+
this.activeTerminalTabId = id
|
|
251
|
+
this.draftAlias = tab.alias
|
|
131
252
|
this.commit()
|
|
132
253
|
}
|
|
133
254
|
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Remove one tab and forget its screen. When the shown tab closes, the
|
|
257
|
+
* neighbours decide what the xterm shows next: the tab that took its place,
|
|
258
|
+
* else the one before it, else nothing.
|
|
259
|
+
* @param id - the tab id.
|
|
260
|
+
*/
|
|
261
|
+
closeTerminalTab(id: string): void {
|
|
262
|
+
const index = this.terminalTabs.findIndex(tab => tab.id === id)
|
|
263
|
+
this.retainedScreens.delete(id)
|
|
264
|
+
// A still-connecting socket was adopted, not detached, and the tab is going
|
|
265
|
+
// away: its session must end rather than be left without an owner. The
|
|
266
|
+
// intent is retargeted in the live entry instead of being forgotten, because
|
|
267
|
+
// forgetting it leaves the old detach handler in charge of the ready frame.
|
|
268
|
+
const adopted = this.adoptedLinks.get(id)
|
|
269
|
+
if (adopted !== undefined) adopted.intent = 'close'
|
|
270
|
+
if (index < 0) return
|
|
271
|
+
const wasActive = this.activeTerminalTabId === id
|
|
272
|
+
this.terminalTabs = this.terminalTabs.filter(tab => tab.id !== id)
|
|
273
|
+
if (wasActive) {
|
|
274
|
+
const neighbour = this.terminalTabs[index] ?? this.terminalTabs[index - 1]
|
|
275
|
+
this.activeTerminalTabId = neighbour?.id
|
|
276
|
+
if (neighbour !== undefined) this.draftAlias = neighbour.alias
|
|
277
|
+
}
|
|
138
278
|
this.commit()
|
|
139
279
|
}
|
|
140
280
|
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
281
|
+
/** The tab record with this id, or undefined when it no longer exists. */
|
|
282
|
+
terminalTab(id: string): TerminalTabRecord | undefined {
|
|
283
|
+
return this.terminalTabs.find(tab => tab.id === id)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Apply a partial update to one tab; a tab that was closed in the meantime
|
|
288
|
+
* is left alone rather than resurrected.
|
|
289
|
+
* @param id - the tab id.
|
|
290
|
+
* @param patch - the fields to change.
|
|
291
|
+
*/
|
|
292
|
+
patchTerminalTab(id: string, patch: Partial<TerminalTabPatch>): void {
|
|
293
|
+
let found = false
|
|
294
|
+
const next = this.terminalTabs.map(tab => {
|
|
295
|
+
if (tab.id !== id) return tab
|
|
296
|
+
found = true
|
|
297
|
+
return { ...tab, ...patch }
|
|
298
|
+
})
|
|
299
|
+
if (!found) return
|
|
300
|
+
this.terminalTabs = next
|
|
145
301
|
this.commit()
|
|
146
302
|
}
|
|
147
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Record the host session of a ready tab and clear the challenge it carried.
|
|
306
|
+
* @param id - the tab id.
|
|
307
|
+
* @param sessionId - the id the host reported on its ready frame.
|
|
308
|
+
*/
|
|
309
|
+
readyTerminalTab(id: string, sessionId: string): void {
|
|
310
|
+
this.patchTerminalTab(id, {
|
|
311
|
+
status: 'connected',
|
|
312
|
+
sessionId,
|
|
313
|
+
detail: undefined,
|
|
314
|
+
closeError: undefined,
|
|
315
|
+
authPrompt: undefined,
|
|
316
|
+
authAnswers: undefined,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The remote shell ended: the tab keeps its screen and its place, and the
|
|
322
|
+
* dead session id is dropped so nothing tries to reattach to it.
|
|
323
|
+
* @param id - the tab id.
|
|
324
|
+
* @param detail - why it ended, when the transport said.
|
|
325
|
+
*/
|
|
326
|
+
exitTerminalTab(id: string, detail?: string): void {
|
|
327
|
+
// The close failure belonged to a session that no longer exists: keeping it
|
|
328
|
+
// would leave a tab that keeps reporting a close it already got.
|
|
329
|
+
this.patchTerminalTab(id, {
|
|
330
|
+
status: 'exited',
|
|
331
|
+
sessionId: undefined,
|
|
332
|
+
detail,
|
|
333
|
+
authPrompt: undefined,
|
|
334
|
+
authAnswers: undefined,
|
|
335
|
+
closeError: undefined,
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* The connection failed. The tab stays with the reason so the user can read
|
|
341
|
+
* it and close the tab themselves.
|
|
342
|
+
* @param id - the tab id.
|
|
343
|
+
* @param detail - the failure text.
|
|
344
|
+
*/
|
|
345
|
+
failTerminalTab(id: string, detail: string): void {
|
|
346
|
+
this.patchTerminalTab(id, {
|
|
347
|
+
status: 'error',
|
|
348
|
+
sessionId: undefined,
|
|
349
|
+
detail,
|
|
350
|
+
authPrompt: undefined,
|
|
351
|
+
authAnswers: undefined,
|
|
352
|
+
closeError: undefined,
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* A background close never reached the host. The tab keeps its live session
|
|
358
|
+
* id (so a retry can still end it) and says so instead of vanishing.
|
|
359
|
+
* @param id - the tab id.
|
|
360
|
+
* @param reason - the reason code shown by the view.
|
|
361
|
+
*/
|
|
362
|
+
markTerminalCloseFailed(id: string, reason: string): void {
|
|
363
|
+
this.patchTerminalTab(id, { closeError: reason })
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Store the keyboard-interactive challenge this tab has to answer, with a
|
|
368
|
+
* blank answer of this challenge's own length. A prompt on another tab never
|
|
369
|
+
* touches this record, which is what keeps two challenges from sharing input.
|
|
370
|
+
* @param id - the tab id.
|
|
371
|
+
* @param prompt - the challenge the host asked for.
|
|
372
|
+
*/
|
|
373
|
+
setTerminalAuthPrompt(id: string, prompt: TerminalAuthPrompt): void {
|
|
374
|
+
this.patchTerminalTab(id, { authPrompt: prompt, authAnswers: prompt.prompts.map(() => '') })
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Record one character typed for this tab's challenge.
|
|
379
|
+
* @param id - the tab id.
|
|
380
|
+
* @param index - which prompt of the challenge.
|
|
381
|
+
* @param value - the field's current text.
|
|
382
|
+
*/
|
|
383
|
+
setTerminalAuthAnswer(id: string, index: number, value: string): void {
|
|
384
|
+
const tab = this.terminalTab(id)
|
|
385
|
+
if (tab === undefined || tab.authPrompt === undefined) return
|
|
386
|
+
const answers = [...(tab.authAnswers ?? tab.authPrompt.prompts.map(() => ''))]
|
|
387
|
+
answers[index] = value
|
|
388
|
+
this.patchTerminalTab(id, { authAnswers: answers })
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Drop the challenge once it was answered, cancelled, or could not apply. */
|
|
392
|
+
clearTerminalAuthPrompt(id: string): void {
|
|
393
|
+
if (this.terminalTab(id)?.authPrompt === undefined) return
|
|
394
|
+
this.patchTerminalTab(id, { authPrompt: undefined, authAnswers: undefined })
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** Choose the alias the next terminal tab opens on. */
|
|
398
|
+
setDraftAlias(alias: string): void {
|
|
399
|
+
if (this.draftAlias === alias) return
|
|
400
|
+
this.draftAlias = alias
|
|
401
|
+
this.commit()
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Append one output chunk to the retained screen of a tab. */
|
|
405
|
+
appendTerminalOutput(id: string, chunk: string): void {
|
|
406
|
+
const screen = this.retainedScreens.get(id) ?? { chunks: [], bytes: 0 }
|
|
407
|
+
screen.chunks.push(chunk)
|
|
408
|
+
screen.bytes += utf8Bytes(chunk)
|
|
409
|
+
while (screen.bytes > MAX_RETAINED_BYTES && screen.chunks.length > 1) {
|
|
410
|
+
const dropped = screen.chunks.shift() ?? ''
|
|
411
|
+
screen.bytes -= utf8Bytes(dropped)
|
|
412
|
+
}
|
|
413
|
+
this.retainedScreens.set(id, screen)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** The retained screen of a tab, concatenated for a redraw. */
|
|
417
|
+
readTerminalOutput(id: string): string {
|
|
418
|
+
return (this.retainedScreens.get(id)?.chunks ?? []).join('')
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** Forget the retained screen (a fresh replay from the host replaces it). */
|
|
422
|
+
clearTerminalOutput(id: string): void {
|
|
423
|
+
this.retainedScreens.delete(id)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Keep a still-connecting socket alive after its view went away. The socket
|
|
428
|
+
* cannot be detached yet (no session id), so the intent is applied when the
|
|
429
|
+
* host reports it: `detach` leaves the shell for a later reattach, `close`
|
|
430
|
+
* ends the session of a tab the user closed.
|
|
431
|
+
* @param tabId - the tab the socket belongs to.
|
|
432
|
+
* @param connection - the live connection.
|
|
433
|
+
* @param intent - what to do once the session id arrives.
|
|
434
|
+
*/
|
|
435
|
+
adoptTerminalLink(tabId: string, connection: TerminalConnection, intent: TerminalLinkIntent): void {
|
|
436
|
+
const entry = { connection, intent }
|
|
437
|
+
this.adoptedLinks.set(tabId, entry)
|
|
438
|
+
// Output that arrives while no view is bound still belongs to the tab, so it
|
|
439
|
+
// goes into the retained screen: reclaiming the socket then replays the
|
|
440
|
+
// whole adopt window instead of showing a gap. A tab that was closed in the
|
|
441
|
+
// meantime stays closed — appending would recreate its retained entry and
|
|
442
|
+
// hand a deleted tab a screen again.
|
|
443
|
+
connection.onOutput = (data) => {
|
|
444
|
+
if (this.terminalTab(tabId) === undefined) return
|
|
445
|
+
this.appendTerminalOutput(tabId, data)
|
|
446
|
+
}
|
|
447
|
+
connection.onAuthPrompt = (name, instructions, prompts) => {
|
|
448
|
+
if (this.terminalTab(tabId) === undefined) return
|
|
449
|
+
this.setTerminalAuthPrompt(tabId, { name, instructions, prompts })
|
|
450
|
+
}
|
|
451
|
+
connection.onReady = (sessionId) => {
|
|
452
|
+
// The intent is read now, not when the socket was adopted: closing the tab
|
|
453
|
+
// while it connects retargets the entry to `close`, and a detach here
|
|
454
|
+
// would leave a host PTY nobody owns.
|
|
455
|
+
const decided = this.adoptedLinks.get(tabId)?.intent ?? entry.intent
|
|
456
|
+
this.adoptedLinks.delete(tabId)
|
|
457
|
+
this.readyTerminalTab(tabId, sessionId)
|
|
458
|
+
if (decided === 'close') connection.close()
|
|
459
|
+
else connection.detach()
|
|
460
|
+
}
|
|
461
|
+
connection.onExit = (_code, error) => {
|
|
462
|
+
this.adoptedLinks.delete(tabId)
|
|
463
|
+
this.failTerminalTab(tabId, error ?? 'connection closed')
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Take an adopted socket back when its tab is shown again, so the host never
|
|
469
|
+
* opens a second PTY for the same tab.
|
|
470
|
+
* @param tabId - the tab id.
|
|
471
|
+
* @returns the connection, or undefined when nothing was adopted.
|
|
472
|
+
*/
|
|
473
|
+
reclaimTerminalLink(tabId: string): TerminalConnection | undefined {
|
|
474
|
+
const adopted = this.adoptedLinks.get(tabId)
|
|
475
|
+
if (adopted === undefined) return undefined
|
|
476
|
+
// A close intent is already on its way out; leave it to finish.
|
|
477
|
+
if (adopted.intent === 'close') return undefined
|
|
478
|
+
this.adoptedLinks.delete(tabId)
|
|
479
|
+
adopted.connection.onReady = undefined
|
|
480
|
+
adopted.connection.onExit = undefined
|
|
481
|
+
adopted.connection.onAuthPrompt = undefined
|
|
482
|
+
// onOutput stays: the view replaces it when it binds, and keeping it until
|
|
483
|
+
// then means no chunk is lost between reclaim and bind.
|
|
484
|
+
return adopted.connection
|
|
485
|
+
}
|
|
486
|
+
|
|
148
487
|
private commit(): void {
|
|
149
488
|
this.snapshot = {
|
|
150
489
|
panelOpen: this.panelOpen,
|
|
151
490
|
activeTab: this.activeTab,
|
|
152
|
-
|
|
153
|
-
|
|
491
|
+
terminalTabs: this.terminalTabs,
|
|
492
|
+
activeTerminalTabId: this.activeTerminalTabId,
|
|
493
|
+
draftAlias: this.draftAlias,
|
|
154
494
|
}
|
|
155
495
|
for (const fn of [...this.listeners]) fn()
|
|
156
496
|
}
|
|
@@ -338,6 +338,12 @@
|
|
|
338
338
|
border-color: var(--dsw-alias-state-business-primary);
|
|
339
339
|
}
|
|
340
340
|
|
|
341
|
+
.badge[data-kind='forward-agent'] {
|
|
342
|
+
margin-left: 6px;
|
|
343
|
+
color: var(--dsw-alias-state-warn-primary);
|
|
344
|
+
border-color: var(--dsw-alias-state-warn-primary);
|
|
345
|
+
}
|
|
346
|
+
|
|
341
347
|
.badge[data-status='ok'] {
|
|
342
348
|
color: var(--dsw-alias-state-success-primary);
|
|
343
349
|
border-color: var(--dsw-alias-state-success-primary);
|
|
@@ -636,6 +642,108 @@
|
|
|
636
642
|
overflow: hidden;
|
|
637
643
|
}
|
|
638
644
|
|
|
645
|
+
/* Terminal tab strip (issue #1950): one row of host PTY sessions above the
|
|
646
|
+
toolbar. It scrolls sideways instead of wrapping so the controls above the
|
|
647
|
+
terminal never move as tabs accumulate. */
|
|
648
|
+
.termTabs {
|
|
649
|
+
display: flex;
|
|
650
|
+
align-items: stretch;
|
|
651
|
+
gap: 2px;
|
|
652
|
+
flex: none;
|
|
653
|
+
overflow-x: auto;
|
|
654
|
+
scrollbar-width: thin;
|
|
655
|
+
border-bottom: 1px solid var(--dsw-alias-border-l1);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
.termTab {
|
|
659
|
+
display: inline-flex;
|
|
660
|
+
align-items: center;
|
|
661
|
+
flex: none;
|
|
662
|
+
max-width: 200px;
|
|
663
|
+
border-radius: 6px 6px 0 0;
|
|
664
|
+
border-bottom: 2px solid transparent;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
.termTab[data-active] {
|
|
668
|
+
background: var(--dsw-alias-bg-layer-2);
|
|
669
|
+
border-bottom-color: var(--dsw-alias-state-business-primary);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
.termTabLabel {
|
|
673
|
+
display: inline-flex;
|
|
674
|
+
align-items: baseline;
|
|
675
|
+
gap: 6px;
|
|
676
|
+
min-width: 0;
|
|
677
|
+
padding: 5px 4px 5px 10px;
|
|
678
|
+
font-size: 12.5px;
|
|
679
|
+
color: var(--dsw-alias-label-secondary);
|
|
680
|
+
background: transparent;
|
|
681
|
+
border: none;
|
|
682
|
+
cursor: pointer;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
.termTab[data-active] .termTabLabel {
|
|
686
|
+
color: var(--dsw-alias-label-primary);
|
|
687
|
+
font-weight: 600;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
.termTabAlias {
|
|
691
|
+
overflow: hidden;
|
|
692
|
+
text-overflow: ellipsis;
|
|
693
|
+
white-space: nowrap;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
.termTabState {
|
|
697
|
+
flex: none;
|
|
698
|
+
font-size: 11px;
|
|
699
|
+
font-weight: 400;
|
|
700
|
+
color: var(--dsw-alias-label-tertiary);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
.termTabState[data-state='error'] {
|
|
704
|
+
color: var(--dsw-alias-state-error-primary);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
.termTabState[data-state='exited'] {
|
|
708
|
+
color: var(--dsw-alias-label-secondary);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.termTabClose,
|
|
712
|
+
.termTabNew {
|
|
713
|
+
flex: none;
|
|
714
|
+
display: inline-flex;
|
|
715
|
+
align-items: center;
|
|
716
|
+
justify-content: center;
|
|
717
|
+
width: 20px;
|
|
718
|
+
height: 20px;
|
|
719
|
+
margin-right: 4px;
|
|
720
|
+
padding: 0;
|
|
721
|
+
font-size: 13px;
|
|
722
|
+
line-height: 1;
|
|
723
|
+
color: var(--dsw-alias-label-tertiary);
|
|
724
|
+
background: transparent;
|
|
725
|
+
border: none;
|
|
726
|
+
border-radius: 5px;
|
|
727
|
+
cursor: pointer;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
.termTabNew {
|
|
731
|
+
width: 24px;
|
|
732
|
+
margin: 2px 0 2px 4px;
|
|
733
|
+
font-size: 15px;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
.termTabClose:hover,
|
|
737
|
+
.termTabNew:hover:not(:disabled) {
|
|
738
|
+
color: var(--dsw-alias-label-primary);
|
|
739
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
.termTabNew:disabled {
|
|
743
|
+
opacity: 0.45;
|
|
744
|
+
cursor: default;
|
|
745
|
+
}
|
|
746
|
+
|
|
639
747
|
.termWrap {
|
|
640
748
|
position: relative;
|
|
641
749
|
flex: 1;
|