xtermjs / xterm.js

A terminal for the web
https://xtermjs.org/
MIT License
17.72k stars 1.63k forks source link

re-create term obj ,no mouse event repsoned. Is there some re-enter limitation existed in xterm.js #5161

Open wellcomez opened 1 month ago

wellcomez commented 1 month ago

Details

Steps to reproduce

  1. clear and close term obj

    • xterm.js and add-on
      <script src="https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/lib/xterm.min.js"></script>
      <link href="https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/css/xterm.min.css" rel="stylesheet">
      <script src="https://cdn.jsdelivr.net/npm/axios@1.6.7/dist/axios.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/@xterm/addon-webgl@0.18.0/lib/addon-webgl.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/@xterm/addon-fit@0.10.0/lib/addon-fit.min.js"></script>
    • clean code
      //clean object
      this.term.clear();
      this.term.dispose();
      this.term.reset()
      //remove node
      let terminalContainer = document.getElementById('terminal');
      let parent = terminalContainer.parentElement;
      terminalContainer.remove();
      terminalContainer = document.createElement('div');
      terminalContainer.id = "terminal";
  2. Then create obj again

    let term = new Terminal({
        allowProposedApi: true,
        cursorStyle: 'bar',  
        allowTransparency: true,
        cursorBlink: false,
        cursorWidth: 4,
        rows: rows,
        cols: cols,
        vt200Mouse: true,
        x10Mouse: true,
        vt300Mouse: true,
        MouseEvent: true,
        fontSize: fontSize,
        // fontFamily: 'SymbolsNerdFontMono "Fira Code", courier-new, courier, monospace, "Powerline Extra Symbols"',
        // fontFamily: 'Hack, "Fira Code", monospace',
        // fontFamily: 'HackNerdFontMono,monospace'
        fontFamily: 'SymbolsNerdFontMono,courier-new, courier, monospace'
    
        // minimumContrastRatio: 1,
    });
  3. term key event still ok but mouse event not

  4. About mouse support

After I read and trace xterm.js, it will be enable after v100/drag protocol is registered . First time create term object , register will be called but second time not. So I wonder whether there are global variables existed which prevent call re-enter

jerch commented 1 month ago

So I wonder whether there are global variables existed which prevent call re-enter

I dont think so, if there is, than it is prolly a dangling listener, that should have been disposed.

Its not clear, what you do on initial startup, because none of the mouse tracking protocols are active on startup by default. There has to be some payload triggering a mouse tracking sequence. Otherwise mouse tracking is always off after startup.

Tyriar commented 1 month ago
        //clean object
        this.term.clear();
        this.term.dispose();
        this.term.reset()

term.dispose() is all you need here, dispose is for when you want to dispose the object and all its components and never use it again. clear clears the buffer (keeps modes, etc.), reset resets it to a clean slate (similar to calling dispose and new Terminal).

wellcomez commented 1 month ago
        //clean object
        this.term.clear();
        this.term.dispose();
        this.term.reset()

term.dispose() is all you need here, dispose is for when you want to dispose the object and all its components and never use it again. clear clears the buffer (keeps modes, etc.), reset resets it to a clean slate (similar to calling dispose and new Terminal).

It looks , necessary function is called, is there any other step should be done ?