Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit b6ac893

Browse files
committed
feat: add xterm.js dependence #4
Signed-off-by: seven <[email protected]>
1 parent 4849bcf commit b6ac893

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

package-lock.json

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
},
1818
"dependencies": {
1919
"@tauri-apps/api": "^1.5.2",
20+
"@xterm/xterm": "^5.4.0",
2021
"oh-vue-icons": "^1.0.0-rc3",
2122
"pinia": "^2.1.7",
2223
"pinia-plugin-persistedstate": "^3.2.1",
2324
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
2425
"ulidx": "^2.3.0",
2526
"vue": "^3.3.4",
2627
"vue-i18n": "^9.9.0",
27-
"vue-router": "^4.2.5"
28+
"vue-router": "^4.2.5",
29+
"xterm-addon-fit": "^0.8.0"
2830
},
2931
"devDependencies": {
3032
"@tauri-apps/cli": "^1.5.8",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<div>
3+
<div ref="terminalContainer"></div>
4+
</div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import '@xterm/xterm/css/xterm.css';
9+
import { Terminal } from '@xterm/xterm';
10+
import { FitAddon } from 'xterm-addon-fit';
11+
12+
const terminal = new Terminal({
13+
cursorBlink: true, // 光标闪烁
14+
cursorStyle: 'bar',
15+
cursorInactiveStyle: 'underline', // 光标样式
16+
});
17+
const fitAddon = new FitAddon();
18+
19+
const terminalContainer = ref();
20+
21+
// Handle the key event
22+
terminal.onKey(e => {
23+
const code = e.domEvent.code.toLowerCase();
24+
const enter = () => terminal.write('\r\n');
25+
const backspace = () => terminal.write('\b \b');
26+
const write = (key: string) => terminal.write(key);
27+
const keyActions: { [key: string]: () => void } = {
28+
enter,
29+
backspace,
30+
};
31+
(keyActions[code] || (() => write(e.key)))();
32+
});
33+
34+
onMounted(() => {
35+
terminal.loadAddon(fitAddon);
36+
// Attach the terminal to the container
37+
terminal.open(terminalContainer.value);
38+
fitAddon.fit();
39+
40+
// Example: Write text to the terminal
41+
terminal.write('Welcome to the Vue 3 + xterm.js example!\r\n');
42+
43+
// Optional: Add terminal handling logic, e.g., for executing commands
44+
// terminal.onData((data: string) => {
45+
// terminal.write(data);
46+
// console.log('terminal on data', data);
47+
// });
48+
});
49+
</script>
50+
51+
<style lang="scss" scoped></style>

src/views/ssh/index.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<div class="table-select">
1212
<ssh-selector />
1313
</div>
14-
<div class="editor-container"></div>
14+
<div class="editor-container">
15+
<ssh-terminal />
16+
</div>
1517
</div>
1618
</div>
1719
<ssh-modal ref="sshModalRef" />
@@ -21,6 +23,7 @@
2123
import sshModal from './components/ssh-dialog.vue';
2224
import sshList from './components/ssh-list.vue';
2325
import sshSelector from './components/ssh-selector.vue';
26+
import sshTerminal from './components/ssh-terminal.vue';
2427
import { useAppStore } from '../../store';
2528
2629
const appStore = useAppStore();

0 commit comments

Comments
 (0)