xterm.js的深入学习

摘要:
版本。Alt键&&!版本。altGraphKey&&!电子控制键&&!

demo

<template>
  <div   class="app-box">Hello</div>
</template>

<script>
  import {
    Terminal
  } from 'xterm'
  import 'xterm/dist/xterm.css'
  export default {
    name: 'app',
    mounted() {
      let term = new Terminal({
        rendererType: "canvas", //渲染类型
        rows: 40, //行数
        convertEol: true, //启用时,光标将设置为下一行的开头
        scrollback:10,//终端中的回滚量
        disableStdin: false, //是否应禁用输入。
        cursorStyle: 'underline', //光标样式
        cursorBlink: true, //光标闪烁
        theme: {
          foreground: 'yellow', //字体
          background: '#060101', //背景色
          cursor: 'help',//设置光标
        }
      })
      term.open(document.getElementById('app'))

      term.writeln(`✔ Installed 1 packages
    ✔ Linked 0 latest versions
    ✔ Run 0 scripts
    Recently updated (since 2019-05-10): 1 packages (detail see file
    /Users/baolilei/Desktop/project/felab/xterm.js/fe-source-stage/src/xterm/node_modules/.recently_updates.txt)
    Today:
    → xterm@*(3.13.1) (01:15:03)
    ✔ All packages installed (1 packages installed from npm registry, used 1s(network 1s), speed 365.87kB/s, json
    1(7.12kB), tarball 509.49kB)`)

      function runFakeTerminal() {
        if (term._initialized) {
          return;
        }

        term._initialized = true;

        term.prompt = () => {
          term.write('
$ ');
        };

        term.writeln('Welcome to xterm.js');
        term.writeln('This is a local terminal emulation, without a real terminal in the back-end.');
        term.writeln('Type some keys and commands to play around.');
        term.writeln('');
        term.prompt();

        term.on('key', function (key, ev) {
          const printable = !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey;
          console.log(key,ev.keyCode);
          console.log(term._core.buffer.x);

          if (ev.keyCode === 13) {
            term.prompt();
          } else if (ev.keyCode === 8) {
            // Do not delete the prompt
            if (term._core.buffer.x > 2) {
              term.write(' ');
            }
          } else if (printable) {
            term.write(key);
          }
        });

        term.on('paste', function (data) {
          term.write(data);
        });
      }
      runFakeTerminal();
    }

  }

</script>

<style lang="scss">
  html,
  body {
     100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
  }
</style>

  参考资料:

- [xterm的配置](https://github.com/xtermjs/xterm.js/blob/3.12.0/typings/xterm.d.ts#L16)
 

免责声明:文章转载自《xterm.js的深入学习》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇[LOJ6220] sumnetbeans工具使用xdebug断点调试php源码下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

制作CentOS7.6 自动安装ISO镜像光盘

制作CentOS7.6 自动安装ISO镜像光盘1. 系统安装包说明目录树结构|-- .discinfo|-- .treeinfo|-- Packages|-- base|-- images|-- isolinux|-- ks.cfg|-- repodata.discinfo 文件是安装价质的识别信息.treeinfo 文件是系统版本,创建时间及文件目录树结...

adb shell 命令之----pm

常用的用法: 查看已经安装的包: pm list packages 查看已经安装的包以及apk路径(-3:只看第三方应用; -s:只看系统应用) -f: see their associated file. -d: filter to only show disbled packages. -e: filter to only show enabled p...

R包的安装 卸载 加载 移除等

R包的安装 1)使用 Rstudio 手动安装 Rstudio的窗口默认为四个,在右下角的窗口的 packages 下会显示所有安装的 R 包 点击 Install -> 输入R 包名 -> 点击 Install 2)使用命令安装 install.packages("R包名") R包的卸载 remove.packages("R包名") R包的...

linux 服务器配置 ASF 云挂卡

关于社区打不开:https://github.com/zyfworks/AnotherSteamCommunityFix 下载asf:https://github.com/JustArchi/ArchiSteamFarm/releases 依赖包: ubuntu: sudo apt-get install libunwind8 libunwind8-dev...

Redhat更新源

1.注册系统给我们提供了什么?如果我们点击系统的RHN,会提示注册系统的种种好处: 1)从官方获得软件源 2)免费或者系统的安装镜像和升级 3)系统故障以后,有专门的维护人员来协同我们处理 对于大部分人员,我们往往只关系,系统能否正常安装软件就够了。而redhat上yum的机理是这样的,通过yum读取配置文件/etc/yum.repos.d/file.re...

centos重装yum

入坑原因:执行了yum -y update(欲哭无泪) 一、 清除已有的应用与依赖 1、删除现有Python[root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联 [root@test ~]# whereis python |xargs...