node-pty icon indicating copy to clipboard operation
node-pty copied to clipboard

Use the Vim editor to open a.c file or.cpp file. The results show blank content

Open OSrcD opened this issue 6 years ago • 1 comments

Environment details

  • OS:masOS Catalina
  • OS version: 10.15
  • node-pty version: 0.9.0

Issue description

Use the Vim editor to open a .c file or .cpp file. The results show blank content: image vim main.cpp image

Electron window width greater than 1300 pixels, shown. Content of the normal: image vim main.cpp image

code: image image

-------------------------------------------------------------------------------------------------------------------------------
<template>

        
    <div id="xterm" :style="{backgroundImage: 'url(' + background + ')'} "></div>
       

</template>

<style scoped>
    #xterm{
        
        
        margin-left: 4.7px;
        height: 100%;
        width: 100%;
        background: no-repeat center;
        background-size: contain;
    }

    
    

    

</style>
  
<script>

const os = require('os');
const pty = require('node-pty');

import { Terminal } from 'xterm';

import { FitAddon } from 'xterm-addon-fit';
const { remote } = require('electron')
import background from '@/assets/background.png'
import { send } from 'process';

export default {
    name: 'Terminal',

    props: {
        terminalProperties: {
            type: Object,
            default: function(){
                return {}
            }
        }
    },

    data(){
        return{
            xterm: null,
            ptyProcess: null,
            shell: null,
            fitAddon: null,
            background: background
        }
    },

    methods: {
        initializeTerminal: function(){
        this.shell = process.env[os.platform() === 'win32' ? 'COMSPEC' : 'SHELL'];
        this.ptyProcess = pty.spawn(this.shell,[],{
            name: 'xterm-color',
            cols: 80,
            rows: 30,
            cwd: process.env.HOME,
            env: process.env
        });
        this.ptyProcess.write('source ~/.bash_profile\r');
        const that = this;
        this.xterm = new Terminal({
            
            
            
            
            cursorBlink: true, //光标闪烁
            fontSize: 25,
            
            theme: {
                
                foreground:'white',
                background: "#0000",
               
             
            },
            allowTransparency: true
            
        });
        
        this.fitAddon = new FitAddon();
        this.xterm.loadAddon(this.fitAddon);
        this.xterm.open(document.getElementById('xterm')); 
        this.fitAddon.fit();
        this.ptyProcess.write('clear\r');
        this.xterm.onData(send => {

            this.ptyProcess.write(send);
            console.log('send:',send);


            });
        
        this.ptyProcess.onData(recv => {
            this.xterm.write(recv);
            console.log('recv:',recv);
            });

     

        window.addEventListener("resize", resizeScreen);

        function resizeScreen(){
           
            that.fitAddon.fit();
        }

        
        }
        
    },




    mounted(){
        
       this.initializeTerminal();
       remote.getCurrentWindow().setSize(858, 481)
        
       
    }



}



</script>
-------------------------------------------------------------------------------------------------------------------------------

OSrcD avatar Aug 21 '20 14:08 OSrcD

I've solved it

OSrcD avatar Aug 23 '20 19:08 OSrcD