xtermjs / xterm.js

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

Resizing when writing causes text to disappear and spaces to appear #4639

Open xReav3r opened 1 year ago

xReav3r commented 1 year ago

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

Steps to reproduce

  1. Call write periodically.
  2. Call resize.
Tyriar commented 1 year ago

@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.

xReav3r commented 1 year ago

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

Tyriar commented 1 year ago

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

image

xReav3r commented 1 year ago

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.

ithrforu commented 1 year ago

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);
    };
  }, []);
zhukai1991 commented 1 year ago

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

ithrforu commented 11 months ago

Any updates? Still relevant.