The Wayback Machine - https://web.archive.org/web/20220411171009/https://github.com/xtermjs/xterm.js/issues/3564
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xterm-addon-fit Shrinking the screen doesn't work #3564

Open
xiaolannuoyi opened this issue Nov 24, 2021 · 16 comments · May be fixed by #3678
Open

xterm-addon-fit Shrinking the screen doesn't work #3564

xiaolannuoyi opened this issue Nov 24, 2021 · 16 comments · May be fixed by #3678
Labels

Comments

@xiaolannuoyi
Copy link

@xiaolannuoyi xiaolannuoyi commented Nov 24, 2021

Details

  • Browser and browser version: chrome/版本 96.0.4664.55(正式版本) (arm64)
  • OS version: macos 12.0.1 (21A559)
  • xterm.js version: 4.0.5
  • xterm-addon-fit: 0.5.0

Steps to reproduce

  1. xterm-addon-fit 扩大屏幕时好使,缩小屏幕时不好使
initTerm() {
      const term = new Terminal(this.option)
      this.fitAddon = new FitAddon()
      term.loadAddon(this.fitAddon)
      term.open(this.$refs.terminal)
      term.write(this.initText)
      this.fitAddon.fit()

      return term
    },
 onResize: debounce(function () {
      console.warn('resize')
      this.fitAddon.fit()
    }, 0),
    onTerminalResize() {
      window.addEventListener('resize', this.onResize)
      this.term.onResize(this.resizeRemoteTerminal)
    },
    removeResizeListener() {
      window.removeEventListener('resize', this.onResize)
    },

aaa

@xiaolannuoyi
Copy link
Author

@xiaolannuoyi xiaolannuoyi commented Nov 26, 2021

我发现当缩小不好使 是因为xterm-viewport这个样式
image

@xiaolannuoyi
Copy link
Author

@xiaolannuoyi xiaolannuoyi commented Nov 26, 2021

目前的解决办法就是 初始化的时候 不使用fit ,并将col设置小点

@Tyriar
Copy link
Member

@Tyriar Tyriar commented Nov 29, 2021

This looks like an issue on your end, the element's container probably isn't going below a certain width so fit keeps it set to some minimum.

@Tyriar Tyriar closed this Nov 29, 2021
@Tyriar Tyriar added the type/question label Nov 29, 2021
@xiaolannuoyi
Copy link
Author

@xiaolannuoyi xiaolannuoyi commented Nov 30, 2021

@Tyriar 这不是我的问题,我在测试中发现,<div class="xterm-viewport" style="background-color: rgb(24, 29, 40); width: 74px;">...</div> 这里的style width始终是页面初始化的width,而且一直不变的。因为这个不变导致屏幕的宽度小于这个宽度就会出现异常
Nov-30-2021 11-01-07

@xiaolannuoyi
Copy link
Author

@xiaolannuoyi xiaolannuoyi commented Nov 30, 2021

@Tyriar xterm-viewport. style width
image

@deximy
Copy link

@deximy deximy commented Nov 30, 2021

I encountered this problem too. I'll try to give a demo which can reproduce this problem.

@deximy
Copy link

@deximy deximy commented Nov 30, 2021

Here is a demo: https://codepen.io/deximy/pen/ZEXExdp
When I open the page with maximum width, everything is ok:
image

But when I try to decrease the width, xterm-viewport doesn't change with xterm-screen. It looks like this:
the left of the page
↑left of the page
the right of the page
↑right of the page

The scroll bar is back, and a lot of black space appears on the right of the page.
Here are the attributes of element:
image

I don't know whether if there is a wrong in my use. Please help me for check. Thank you. @Tyriar

@Tyriar
Copy link
Member

@Tyriar Tyriar commented Nov 30, 2021

Guess it is an issue on our end. This doesn't happen in vscode because viewport is absolutely positioned such that the scroll bar is right aligned to the container.

@Tyriar Tyriar reopened this Nov 30, 2021
@Tyriar Tyriar added type/bug good first issue help wanted and removed type/question labels Nov 30, 2021
@deximy
Copy link

@deximy deximy commented Dec 1, 2021

Guess it is an issue on our end. This doesn't happen in vscode because viewport is absolutely positioned such that the scroll bar is right aligned to the container.

So you mean I need to check some part of the code about the viewport so that I could solve this problem, right?

@Bryce-huang
Copy link

@Bryce-huang Bryce-huang commented Dec 15, 2021

It is irrelevant to this question, is there any usage of native js for fit plugin?

@Tyriar
Copy link
Member

@Tyriar Tyriar commented Dec 16, 2021

@liyuewen
Copy link

@liyuewen liyuewen commented Dec 22, 2021

Use "xterm": "~ 4.10.0", which solves my problem

@deximy
Copy link

@deximy deximy commented Dec 24, 2021

Use "xterm": "~ 4.10.0", which solves my problem

Now I am using "xterm": "^4.15.0". I'll try to downgrade.

@BitStream1
Copy link

@BitStream1 BitStream1 commented Jan 3, 2022

I've been running into this issue also. I'm using xterm 4.16.0.

It might be related to the width calculation in Viewport._innerRefresh(), rather than the fit add-on. The width is explicitly calculated based on the number of columns, so the viewport's scrollbar will be aligned to an integer column count rather than the edge of the parent window. e.g.:

this._viewportElement.style.width = (this._renderService.dimensions.actualCellWidth * (this._bufferService.cols) + this.scrollBarWidth + (this._lastHadScrollBar ? elementPadding : 0)).toString() + 'px';

If the number of columns doesn't match the outer xterm's width then the viewport's scrollbar would appear in the middle of the screen. In my case, the main symptom would be the scrollbar appearing before the right edge of the screen, rather than exactly at the end. The scrollbar would also jump when the viewport was resized.

I see that with VS Code, the xterm.js CSS is overridden quite a bit, but I couldn't identify what prevented the manifestation of the issue in VS Code.
https://github.com/microsoft/vscode/blob/17b2d1c97906d4538990ed3ab0200e3fafb98a35/src/vs/workbench/contrib/terminal/browser/media/terminal.css

As a temporary work-around, I only found the following, which effectively disables the above width and has to use an !important:

    .xterm .xterm-viewport {
        width: initial !important; 
    }

Which leads to the question - does this width really needs to be set and instead use CSS to position viewport, or could there be side effects as a result of removing this?

I hope the extra information may help in resolving the issue.

@nebbles
Copy link

@nebbles nebbles commented Feb 9, 2022

I have also been looking into this. Generally, we were seeing weird resizing behaviour where the term viewport wouldn't match the width of its container (we are also using the addon-fit module).

I was previously on 4.13.0 where there was no issue with the width or resizing. Using a pinned upgrade, I noticed the issue was introduced in 4.14.0. I have tested all the way up to and including 4.17.0 and the issue remains.

The workaround described by @BitStream1 works to patch this issue (I tested it on 4.14.0 and 4.17.0)

.xterm-viewport {
    width: initial !important;
}
@enncy
Copy link

@enncy enncy commented Mar 4, 2022

I got the same problem.
But i found this way, it's work for me :

<div class="terminal-container">
    <div id="terminal"></div>
</div>
import { Terminal } from "xterm";
import { FitAddon } from "xterm-addon-fit";
const term = new Terminal(...);

const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
term.open(document.querySelector("#terminal"));
fitAddon.fit();

window.onresize = function () {
    fitAddon.fit();
};
.terminal-container{
    /* this is important */
    overflow: hidden;
}
.xterm .xterm-viewport {
    /* see : https://github.com/xtermjs/xterm.js/issues/3564#issuecomment-1004417440 */
    width: initial !important;
}
@silamon silamon linked a pull request Mar 12, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8 participants