为什么光标会这样弄乱?
我的终端是这样的:
import { useEffect } from "react";
import { Terminal as TerminalType } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
//import { SearchAddon } from 'xterm-addon-search'
import 'xterm/css/xterm.css';
export const Terminal = ({
initialValue
} : {
initialValue?: string
}) => {
const id = 'xterm-container';
useEffect(() => {
const terminal = new TerminalType({
cursorBlink: true,
cursorStyle: window.api.isWindows ? "bar" : "underline"
});
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
window.api.receive('terminal.incomingData', (data) => {
terminal.write(data);
});
terminal.open(document.getElementById(id) as HTMLElement);
terminal.onData(key => {
window.api.send('terminal.keystroke', key);
});
terminal.focus();
window.api.send('terminal.keystroke', "cd C:\\\r\n");
}, []);
return (
<div id={id}></div>
)
}
在后端我将XTERM连接到这样的真实终端:
ipcMain.on('terminal.keystroke', (_, key) => {
ptyProcess.write(key);
});
const shell = isWindows ? 'powershell.exe' : 'bash';
ptyProcess = spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
env: process.env as INonUndefinedEnv
});
ptyProcess.onData(data =>
EnforceNonNull(win).webContents.send('terminal.incomingData', data)
);
但是,当发送文本时,由于某种原因,光标会像下面的图像中一样混乱。发送这样的文本会重现错误:
window.api.send('terminal.keystroke', "cd C:\\\r\n");
由Mysed我的意思。 CD
在顶部,然后CD C:\
和&gt;&gt;
下面ps
。应该是这样的:
https://i.sstatic.net/l8s93.png“ rel =” nofollow noreferrer“>
编辑2:这似乎仅在第一行发生。之后,居民的位置似乎不再搞砸了
My terminal goes like this:
import { useEffect } from "react";
import { Terminal as TerminalType } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
//import { SearchAddon } from 'xterm-addon-search'
import 'xterm/css/xterm.css';
export const Terminal = ({
initialValue
} : {
initialValue?: string
}) => {
const id = 'xterm-container';
useEffect(() => {
const terminal = new TerminalType({
cursorBlink: true,
cursorStyle: window.api.isWindows ? "bar" : "underline"
});
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
window.api.receive('terminal.incomingData', (data) => {
terminal.write(data);
});
terminal.open(document.getElementById(id) as HTMLElement);
terminal.onData(key => {
window.api.send('terminal.keystroke', key);
});
terminal.focus();
window.api.send('terminal.keystroke', "cd C:\\\r\n");
}, []);
return (
<div id={id}></div>
)
}
where in the backend I connect xterm to real terminal like this:
ipcMain.on('terminal.keystroke', (_, key) => {
ptyProcess.write(key);
});
const shell = isWindows ? 'powershell.exe' : 'bash';
ptyProcess = spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
env: process.env as INonUndefinedEnv
});
ptyProcess.onData(data =>
EnforceNonNull(win).webContents.send('terminal.incomingData', data)
);
but when send the text, the cursor for some reason gets messed like in the below image. Sending a text like this reproduce the error:
window.api.send('terminal.keystroke', "cd C:\\\r\n");
By messed I mean this. cd
is on top, then cd c:\
and the >>
below PS
. it's supposed to be something like this:
EDIT 2:
if i went to say type dir
it goes like this:
EDIT 2: this seems to happen only in the very first line. After that, the curson position didn't seem to get messed anymore
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论