-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathViewBuiltinTerminalPanel.vue
More file actions
75 lines (62 loc) · 2.1 KB
/
ViewBuiltinTerminalPanel.vue
File metadata and controls
75 lines (62 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!-- eslint-disable vue/no-mutating-props -->
<script setup lang="ts">
import type { DocksContext } from '@vitejs/devtools-kit/client'
import type { TerminalState } from '../state/terminals'
import { useEventListener } from '@vueuse/core'
import { FitAddon } from '@xterm/addon-fit'
import { Terminal } from '@xterm/xterm'
import { markRaw, nextTick, onMounted, onUnmounted, ref } from 'vue'
const props = defineProps<{
context: DocksContext
terminal: TerminalState
}>()
const container = ref<HTMLElement>()
let term: Terminal
onMounted(async () => {
term = markRaw(new Terminal({
convertEol: true,
cols: 80,
screenReaderMode: true,
}))
const fitAddon = new FitAddon()
term.loadAddon(fitAddon)
term.open(container.value!)
fitAddon.fit()
useEventListener(window, 'resize', () => {
fitAddon.fit()
})
nextTick(() => {
fitAddon.fit()
})
props.terminal.terminal = term
if (props.terminal.buffer == null) {
const { buffer } = await props.context.rpc.call('vite:internal:terminals:read', props.terminal.info.id)
props.terminal.buffer = markRaw(buffer)
}
for (const chunk of props.terminal.buffer)
term.writeln(chunk)
})
onUnmounted(() => {
term.dispose()
props.terminal.terminal = null
})
// async function clear() {
// rpc.runTerminalAction(await ensureDevAuthToken(), props.id, 'clear')
// term?.clear()
// }
// async function restart() {
// rpc.runTerminalAction(await ensureDevAuthToken(), props.id, 'restart')
// }
// async function terminate() {
// rpc.runTerminalAction(await ensureDevAuthToken(), props.id, 'terminate')
// }
</script>
<template>
<div ref="container" class="h-full w-full of-auto bg-black" />
<!-- <div border="t base" flex="~ gap-2" items-center p2>
<button title="Clear" icon="i-carbon-clean" :border="false" @click="clear()" />
<button v-if="info?.restartable" title="Restart" icon="carbon-renew" :border="false" @click="restart()" />
<button v-if="info?.terminatable" title="Terminate" icon="carbon-delete" :border="false" @click="terminate()" />
<span text-sm op50>{{ info?.description }}</span>
</div> -->
</template>