前言:xterm 终端多余空行的出现,大多数原因是数据源结尾有 `\n` 导致的。
1. 手动处理输出
假设 array 里的元素为输入到终端的数据。
import { Terminal } from "@xterm/xterm";
const term = new Terminal({
convertEol: true, //启用时,光标将设置为下一行的开头
disableStdin: false, //是否应禁用输入。
cursorStyle: "underline", //光标样式
cursorBlink: true, //光标闪烁
theme: {
foreground: "#7e9192", //字体
background: "#002833", //背景色
cursor: "help", //设置光标
},
});
const array = ["xxxx\n\n", "xxxx\n\n"];
array.forEach((item) => {
const lines = item.split("\n");
const nonEmptyLines = lines.filter((line) => line.trim() !== "");
const processedData = nonEmptyLines.join("\n");
term.writeln(processedData);
});