8
8
import { onBeforeUnmount , onMounted , ref , watch } from " vue"
9
9
import { IDisposable , Terminal } from " xterm"
10
10
import { FitAddon } from " xterm-addon-fit"
11
+ import { WebglAddon } from " xterm-addon-webgl"
11
12
import { Base64 } from " js-base64"
12
13
import { useResizeObserver , useWebSocket } from " @vueuse/core"
13
14
import { ws_uri } from " @/utils/const"
14
15
import { webttyRx , webttyTx } from " @/utils/webtty"
15
16
16
- import " xterm/css/xterm.css"
17
17
import { ActionEvent , actionBus } from " @/utils/action"
18
+ import " xterm/css/xterm.css"
18
19
19
- interface PropDef {
20
- cmd: string
21
- connected: boolean
22
- }
23
- const props = withDefaults (defineProps <PropDef >(), { connected: true })
24
- const emit = defineEmits ([" update:connected" ])
25
- defineExpose ({ focus })
20
+ const props = withDefaults (
21
+ defineProps <{
22
+ /** The command to execute */
23
+ cmd: string
24
+ connected: boolean
25
+ }>(),
26
+ { connected: true }
27
+ )
28
+ const emit = defineEmits <{
29
+ (e : " update:connected" , connected : boolean ): void
30
+ }>()
31
+ defineExpose ({ focus , fit })
26
32
27
33
const terminal = ref ()
28
34
35
+ function fit() {
36
+ fitAddon .fit ()
37
+
38
+ term .refresh (0 , term .rows - 1 )
39
+ console .log (" fit" )
40
+ }
41
+
29
42
const term = new Terminal ({
30
43
rows: 24 ,
31
44
cols: 80 ,
@@ -139,6 +152,7 @@ useResizeObserver(terminal, (el) => {
139
152
onMounted (() => {
140
153
open ()
141
154
term .loadAddon (fitAddon )
155
+ term .loadAddon (new WebglAddon ())
142
156
term .open (terminal .value )
143
157
term .writeln (` $ \x1B [1;3;31m${props .cmd }\x1B [0m ` )
144
158
focus ()
@@ -152,12 +166,12 @@ onBeforeUnmount(() => {
152
166
})
153
167
154
168
function focus() {
155
- terminal .value .scrollIntoView ()
169
+ terminal .value ? .scrollIntoView ()
156
170
term .focus ()
157
171
}
158
172
159
173
actionBus .on ((action : ActionEvent ) => {
160
- if (action .action == " ssh " && props .cmd .endsWith (action .command )) {
174
+ if (action .action == " focus " && props .cmd .endsWith (action .command )) {
161
175
// console.log("focus", action.command, props.cmd)
162
176
focus ()
163
177
}
0 commit comments