Skip to content

Commit fd037fd

Browse files
committed
fix: terminals
1 parent 2cadee5 commit fd037fd

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

packages/core/src/client/webcomponents/components/Dock.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const context = props.context
1616
1717
const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')
1818
19-
const PANEL_MARGIN = 5
19+
const PANEL_MARGIN = 2
2020
const panelMargins = reactive({
2121
left: PANEL_MARGIN,
2222
top: PANEL_MARGIN,

packages/core/src/client/webcomponents/components/ViewBuiltinTerminalPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ onMounted(async () => {
3434
const { buffer } = await props.context.rpc.$call('vite:internal:terminals:read', props.terminal.info.id)
3535
props.terminal.buffer = markRaw(buffer)
3636
for (const chunk of buffer)
37-
term.write(chunk)
37+
term.writeln(chunk)
3838
}
3939
4040
props.terminal.terminal = term

packages/core/src/client/webcomponents/state/terminals.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { DevToolsRpcClientFunctions, DevToolsTerminalSessionStreamChunkEvent } from '@vitejs/devtools-kit'
1+
import type { DevToolsRpcClientFunctions, DevToolsTerminalSessionBase, DevToolsTerminalSessionStreamChunkEvent } from '@vitejs/devtools-kit'
22
import type { DocksContext } from '@vitejs/devtools-kit/client'
33
import type { Terminal } from '@xterm/xterm'
44
import type { Reactive } from 'vue'
5-
import type { DevToolsTerminalSessionBase } from '../../../../../kit/src'
65
import { reactive } from 'vue'
76

87
export interface TerminalState {
@@ -16,7 +15,7 @@ export function useTerminals(context: DocksContext): Reactive<Map<string, Termin
1615
if (_terminalsMap) {
1716
return _terminalsMap
1817
}
19-
const map = _terminalsMap = reactive(new Map())
18+
const map: Reactive<Map<string, TerminalState>> = _terminalsMap = reactive(new Map())
2019
async function udpateTerminals() {
2120
const terminals = await context.rpc.$call('vite:internal:terminals:list')
2221

@@ -51,7 +50,7 @@ export function useTerminals(context: DocksContext): Reactive<Map<string, Termin
5150
}
5251
terminal.buffer?.push(...data.chunks)
5352
for (const chunk of data.chunks)
54-
terminal.terminal?.write(chunk)
53+
terminal.terminal?.writeln(chunk)
5554
},
5655
})
5756
udpateTerminals()

packages/core/src/node/host-terminals.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,11 @@ export class DevToolsTerminalHost implements DevToolsTerminalHostType {
8888
const { exec } = await import('tinyexec')
8989

9090
let controller: ReadableStreamDefaultController<string> | undefined
91-
const buffer = new ReadableStream<string>({
92-
async start(_controller) {
91+
const stream = new ReadableStream<string>({
92+
start(_controller) {
9393
controller = _controller
9494
},
9595
})
96-
const writer = new WritableStream<string>({
97-
write(chunk) {
98-
controller?.enqueue(chunk)
99-
},
100-
})
10196

10297
function createChildProcess() {
10398
const cp = exec(
@@ -116,14 +111,12 @@ export class DevToolsTerminalHost implements DevToolsTerminalHostType {
116111
},
117112
)
118113

119-
const stream = new ReadableStream<string>({
120-
async start(controller) {
121-
for await (const chunk of cp) {
122-
controller.enqueue(chunk)
123-
}
124-
},
125-
})
126-
stream.pipeTo(writer)
114+
;(async () => {
115+
for await (const chunk of cp) {
116+
controller?.enqueue(chunk)
117+
}
118+
})()
119+
127120
return cp
128121
}
129122

@@ -141,14 +134,14 @@ export class DevToolsTerminalHost implements DevToolsTerminalHostType {
141134
const session: DevToolsChildProcessTerminalSession = {
142135
...terminal,
143136
status: 'running',
144-
stream: buffer,
137+
stream,
145138
type: 'child-process',
146139
executeOptions,
147140
getChildProcess: () => cp?.process,
148141
terminate,
149142
restart,
150143
}
151-
this.sessions.set(session.id, session)
144+
this.register(session)
152145

153146
return Promise.resolve(session)
154147
}

0 commit comments

Comments
 (0)