当前位置:   article > 正文

vue + xterm 前端终端terminal

vue + xterm 前端终端terminal

引入

import {Terminal} from "xterm";
import {FitAddon} from "xterm-addon-fit";
import "xterm/css/xterm.css";
  • 1
  • 2
  • 3

html

<div id="terminal"></div>
  • 1

vue

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)
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

write

命令含义
term.write(‘\n’)换行
term.write(‘\r’+内容)从头替换当前行内容
write(‘\x1b[2K\r’)删除当前整行

调整光标位置

term._core.buffer.x = 0;
  • 1
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/904273
推荐阅读
  

闽ICP备14008679号