xterm.js icon indicating copy to clipboard operation
xterm.js copied to clipboard

Resizing when writing causes text to disappear and spaces to appear

Open xReav3r opened this issue 1 year ago • 7 comments

If not resizing when writing (now I can resize as I want and text is correct): image

If resizing when writing: image

Tried fitAddon.fit() and even terminal.resize(fitAddon.proposeDimensions()). Also tried to debounce to 500 ms with no luck.

Data is written by chunks as Uint8Array from ReadableStream.

Details

  • Browser and browser version: Chrome 114.0.5735.133 (Official Build) (64-bit)
  • OS version: Linux 5.15.114-2-MANJARO x86_64 GNU/Linux
  • xterm.js version: 5.2.1

Steps to reproduce

  1. Call write periodically.
  2. Call resize.

xReav3r avatar Aug 02 '23 19:08 xReav3r

@xReav3r any more details on how you're writing and what you mean by writing periodically? I can't reproduce this but it would be great to fix it.

Tyriar avatar Aug 03 '23 14:08 Tyriar

Managed to simulate it here (just resize the window width under line width): https://codesandbox.io/s/kind-http-xkj3jt?file=/src/App.js&resolutionWidth=802&resolutionHeight=675

xReav3r avatar Aug 05 '23 11:08 xReav3r

Do you mean how it goes like this when you make it really narrow?

image

Tyriar avatar Aug 05 '23 13:08 Tyriar

Yes, but it just need to be narrower than line, even if it is one character, but looks like it depends on the text that goes before endline. In real usage I am streaming real terminal trought ReadableStream, where size of chunk is "random".

When resizing over line width everything is okay.

xReav3r avatar Aug 05 '23 14:08 xReav3r

I have a similar bug with resizing. Everything is ok without text, but if i paste the text and zoom in to 175% it starts to duplicate and looks weird:

xterm5-3-0-zoom.webm

"xterm": "5.3.0",
"xterm-addon-attach": "0.9.0",
"xterm-addon-fit": "0.8.0"
  useEffect(() => {
    const terminal = new Terminal();
    const attachAddon = new AttachAddon(ws);
    const fitAddon = new FitAddon();

    terminal.loadAddon(attachAddon);
    terminal.loadAddon(fitAddon);

    const sendResize = (cols: number, rows: number) => {
      ws.readyState === WebSocket.OPEN &&
        ws.send(
          new Blob(
            [
              JSON.stringify({
                type: 'resize',
                cols,
                rows,
              }),
            ],
            { type: 'application/json' }
          )
        );
    };
    const doSendResize = () => sendResize(terminal.cols, terminal.rows);
    ws.addEventListener('open', doSendResize);

    terminal.open(notNull(terminalRef.current));
    terminal.onResize((size) => sendResize(size.cols, size.rows));

    const resizeObserver = new ResizeObserver(() => {
      requestAnimationFrame(() => {
        fitAddon.proposeDimensions();
        fitAddon.fit();
      });
    });

    resizeObserver.observe(notNull(terminalRef.current));

    return () => {
      resizeObserver.disconnect();
      ws.removeEventListener('open', doSendResize);
      terminal.dispose();
      ws.close(1000);
    };
  }, []);

ithrforu avatar Sep 12 '23 05:09 ithrforu

I also encountered the same problem. After the browser was scaled, due to the fact that the row height was not an integer when calculating rows, there was an error in the calculation. Finally, when calculating the total height of the container, there was a difference from the actual container height, resulting in some content being occluded

zhukai1991 avatar Sep 13 '23 08:09 zhukai1991

Any updates? Still relevant.

ithrforu avatar Oct 26 '23 13:10 ithrforu