xterm.js 终端输出格式

使用xterm.js和websocket做一个简单的命令行终端, 现在每次输入命令有返回内容, 但是在xterm中显示的格式不是想要的, 就是换行没有左对齐,怎么解决这个问题? 如图。

图片描述

        let terminalContainer = document.getElementById('terminal')
        this.term = new Terminal({
            cols: 80,
            rows: 24,
            cursorBlink: true
        })
        this.term.open(terminalContainer)
        this.term._initialized = true

        this.term.writeln("welcome to use web terminal!");
        this.term.write("~$ ")
        let input = '';
        let that = this;
        this.term.on("data", function(data){
            let code = data.charCodeAt(0);
            if(code == 13 ){
                that.term.write('\r\n');
                that.socket.send(input);
                that.socket.onmessage = function(e) {
                    that.term.writeln(e.data);
                    that.term.write("~$ ")
                    console.log(e.data);
                }
                input = '';
            }else{
                input += data
                that.term.write(data);

            }
        })
阅读 12.3k
2 个回答
新手上路,请多包涵
推荐问题