Skip to content

Commit 92da89d

Browse files
committed
fix: fix line indent issue and send correct command to server #3
Signed-off-by: seven <[email protected]>
1 parent afe5f18 commit 92da89d

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/views/ssh/components/ssh-terminal.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@ const terminal = new Terminal({
2424
cursorBlink: true, // 光标闪烁
2525
cursorStyle: 'bar',
2626
cursorInactiveStyle: 'underline', // 光标样式
27+
convertEol: true, // 回车换行
2728
});
2829
const fitAddon = new FitAddon();
2930
3031
const terminalContainer = ref();
3132
32-
const enter = () => terminal.write('\r\n');
33-
const backspace = () => terminal.write('\b \b');
34-
35-
const keyActions: { [key: string]: (terminal: Terminal) => void } = {
36-
enter,
37-
backspace,
33+
const sequenceMap: { [key: string]: string } = {
34+
enter: '\r\n',
35+
backspace: '\b \b',
3836
};
3937
const commands: Array<string> = [];
4038
let command = '';
4139
// Handle the key event
4240
terminal.onKey(e => {
4341
const code = e.domEvent.code.toLowerCase();
4442
45-
const keyAction = keyActions[code];
43+
const sequence = sequenceMap[code];
4644
47-
if (keyAction) {
48-
keyAction(terminal);
49-
exec(command);
45+
if (code === 'enter') {
5046
commands.push(command);
47+
terminal.write(sequence);
48+
exec(command);
5149
command = '';
52-
return;
50+
} else if (code === 'backspace') {
51+
command = command.slice(0, -1);
52+
terminal.write(sequence);
5353
} else {
5454
terminal.write(e.key);
5555
command += e.key;
@@ -62,8 +62,12 @@ const exec = (command: string) => {
6262
// eslint-disable-next-line
6363
console.log(`exec res ${res}`);
6464
terminal.writeln(res as string);
65+
terminal.writeln('');
6566
})
66-
.catch(e => terminal.writeln(e));
67+
.catch(e => {
68+
terminal.writeln(e);
69+
terminal.writeln('');
70+
});
6771
};
6872
6973
onMounted(async () => {
@@ -72,10 +76,10 @@ onMounted(async () => {
7276
// Attach the terminal to the container
7377
terminal.open(terminalContainer.value);
7478
fitAddon.fit();
79+
terminal.focus();
7580
7681
// Example: Write text to the terminal
7782
terminal.write('Welcome to AnyTerm!\r\n');
78-
7983
// Optional: Add terminal handling logic, e.g., for executing commands
8084
// terminal.onData((data: string) => {
8185
// terminal.write(data);

src/views/ssh/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const handleClose = (name: string) => {
9595
<style lang="scss" scoped>
9696
.ssh-tab-container {
9797
width: 100%;
98-
height: 99%;
98+
height: 100%;
9999
.tab-pane-container {
100100
height: 100%;
101101
width: 100%;

0 commit comments

Comments
 (0)