• xterm.js的深入学习


    demo

    <template>
      <div id="app" 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)
     
  • 相关阅读:
    Jquery日历插件e-calendar升级版
    jquery双击事件(dblclick)时,不触发单击事件(click)
    js实现的点击div区域外隐藏div区域
    IE浏览器new Date()带参返回NaN解决方法
    RequireJs中使用layer的问题
    AngularJs规范
    js调用Angular的方法
    游标cursor
    bigint数据类型
    ANSI_NULLS和QUOTED_IDENTIFIER
  • 原文地址:https://www.cnblogs.com/yiyi17/p/10881339.html
Copyright © 2020-2023  润新知