zoukankan      html  css  js  c++  java
  • Js 之xterm.js终端插件

    这个终端插件通常与websocket一起使用。

    下载地址:https://pan.baidu.com/s/1WbyLNOYbwwikOi_iMU7oKA 

    提取码:6mc7 

    一、效果图

     二、代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>xterm.js</title>
        <link rel="stylesheet" href="node_modules/xterm/css/xterm.css">
        <script src="node_modules/xterm/lib/xterm.js"></script>
    </head>
    <body>
    <div id="terminal"></div>
    <script>
        let term = new Terminal({
            cursorStyle: 'underline', //光标样式
            cursorBlink: true, // 光标闪烁
            convertEol: true, //启用时,光标将设置为下一行的开头
            disableStdin: false, //是否应禁用输入。
            theme: {
                foreground: 'yellow', //字体
                background: '#060101', //背景色
                cursor: 'help',//设置光标
            }
        });
        term.open(document.getElementById('terminal'));
        function runFakeTerminal() {
            if (term._initialized) {
                return;
            }
    
            term._initialized = true;
    
            term.prompt = () => {
                term.write('
    ~$ ');
            };
    
            term.writeln('Welcome to xterm.js');
            prompt(term);
    
            term.onKey(e => {
                const printable = !e.domEvent.altKey && !e.domEvent.altGraphKey && !e.domEvent.ctrlKey && !e.domEvent.metaKey;
    
                if (e.domEvent.keyCode === 13) {
                    prompt(term);
                } else if (e.domEvent.keyCode === 8) {
                    // Do not delete the prompt
                    if (term._core.buffer.x > 2) {
                        term.write(' ');
                    }
                } else if (printable) {
                    term.write(e.key);
                }
                console.log(e.key);
            });
        }
    
        function prompt(term) {
            term.write('
    ~$ ');
        }
        runFakeTerminal();
    </script>
    </body>
    </html>
  • 相关阅读:
    剑指office--------重建二叉树
    剑指office--------二进制中1的个数
    剑指office--------最小的K个数 (待补充)
    剑指office--------二维数组的查找
    剑指office--------替换空格
    Redis集群
    一致性hash算法
    Zab协议(转)
    Redis线程模型
    Http Cookie和session
  • 原文地址:https://www.cnblogs.com/yang-2018/p/12187617.html
Copyright © 2011-2022 走看看