xtermjs / xterm.js

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

xterm deletes content instead of wrapping #5062

Closed cpendery closed 1 month ago

cpendery commented 1 month ago

Details

Steps to reproduce

  1. Resize the below html where Public should wrap to the next line
  2. See that it vanishes instead of wrapping even though there is enough space to wrap
<!doctype html>
  <html>
    <head>
      <link rel="stylesheet" href="node_modules/@xterm/xterm/css/xterm.css" />
      <script src="node_modules/@xterm/xterm/lib/xterm.js"></script>
      <script src="node_modules/@xterm/addon-fit/lib/addon-fit.js"></script>
    </head>
    <body>
      <div id="terminal"></div>
      <script>
        var term = new Terminal({rows: 5, cols: 70});
        var fitAddon = new FitAddon.FitAddon();
        term.loadAddon(fitAddon);
        term.open(document.getElementById('terminal'));
        term.writeln('\x1b[9CDesktop\x1b[9CDownloads\x1b[7CMovies\x1b[10CPictures\x1b[8Cgo');
        term.write('\x1b[9CDocuments\x1b[7CLibrary\x1b[9CMusic\x1b[11CPublic');

        const observer = new ResizeObserver(() => fitAddon.fit());
        observer.observe(document.getElementById('terminal'));
      </script>
    </body>
  </html>
jerch commented 1 month ago

Yes thats one of the quirk modes implemented in xterm.js - the last line of the normal (scrollback) buffer does not reflow automatically. The reason for this comes from how many shell versions treat their prompt line - on a resize event (SIGWINCH signal) they typically wipe their prompt and rewrite it with the new col size. Effectively this means, that the shell process does the reflow for the prompt line itself.

@Tyriar We already had several discussions/requests regarding this (cant find them atm). To me it looks wrong to share reflow responsibility as it is currently done for many reasons (up to causing race conditions), but we cannot simply tell shells not to do it anymore. Thus I wonder if we should make this configurable via an option, and maybe also reserve a boolean under DECSET for reflow. This way shells can query TEs for reflow capability and dont have to do it on their own anymore. And hopefully they would adopt to that over time.

Tyriar commented 1 month ago

I don't think xterm.js will ever know how to wrap likes properly as there can be line continuations, right prompts, etc. Are there any cases where someone would want this disabled? Right now we reflow all lines that are very unlikely to be touched unless old versions of conpty are being used.

jerch commented 1 month ago

Ah right - right prompts. :see_no_evil:

Tyriar commented 1 month ago

Unless I'm missing something I think we should close this by design