问题描述
xterm.js+websocket+vue实现xshell使用vi无法正常编辑文件
问题出现的环境背景及自己尝试过哪些方法
尝试不用固定的rows,和cols
相关代码
<script setup>
//远程登录=====
import 'xterm/css/xterm.css';
import { Terminal } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { AttachAddon } from 'xterm-addon-attach';
import useFormData from '@/utils/use-form-data';
import { opsTstWebshell } from '@/api/operation';
import { message } from 'ant-design-vue/es';
//远程登录=====
const inputContent = ref(''); //shell中输入的内容
const showShell = ref(false);
const terminalRef = ref(null); //找到shell的容器
const term = ref(null);
const socket = ref(null);
const rows = ref(32);
const initTerm = () => {
const terminal = new Terminal({
rendererType: 'canvas', //渲染类型
rows: rows.value, //行数
// cols: cols.value, // 设置之后会输入多行之后覆盖现象
convertEol: false, //启用时,光标将设置为下一行的开头
fontSize: 14, //字体大小
disableStdin: false, //是否应禁用输入。
cursorStyle: 'block', //光标样式
// cursorBlink: true, //光标闪烁
scrollback: 30, //终端中的回滚量
tabStopWidth: 4,
theme: {
foreground: 'white', //字体
background: '#060101', //背景色
cursor: 'help' //设置光标
}
});
const attachAddon = new AttachAddon(socket.value);
const fitAddon = new FitAddon();
terminal.loadAddon(attachAddon);
terminal.loadAddon(fitAddon);
terminal.open(terminalRef.value);
terminal.focus();
fitAddon.fit();
//限制和后端交互,只有输入回车键才显示结果
terminal.prompt = () => {
terminal.write('\r\n$ ');
};
terminal.prompt();
};
你期待的结果是什么?实际看到的错误信息又是什么?
能够正常编辑,现在输入 vi a.txt后输入,前一次输入的内容会向上隐藏,并且一排只能输入10来个字符就自动换行