引入
javascript">import {Terminal} from "xterm";
import {FitAddon} from "xterm-addon-fit";
import "xterm/css/xterm.css";
html
javascript"><div id="terminal"></div>
vue
javascript">onMounted(() => {nextTick(() => {initTerm();})
})const initTerm = async () => {let termContainer = document.getElementById("terminal");term = new Terminal({lineHeight: 1.3,fontSize: 15,fontFamily:"WenQuanYi Micro Hei, Monaco, Menlo, Consolas, 'Courier New', monospace",theme: {background: '#181d28',},unicodeVersion: 12,convertEol: true,cursorBlink: true,cursorStyle: 'underline',scrollback: 100,tabStopWidth: 4,});term.open(termContainer)
};
write
命令 | 含义 |
---|
term.write(‘\n’) | 换行 |
term.write(‘\r’+内容) | 从头替换当前行内容 |
write(‘\x1b[2K\r’) | 删除当前整行 |
调整光标位置
javascript">term._core.buffer.x = 0;