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

Fonts being displayed incorrectly #1298

Open
creeper451 opened this issue Feb 16, 2024 · 3 comments
Open

Fonts being displayed incorrectly #1298

creeper451 opened this issue Feb 16, 2024 · 3 comments
Labels

Comments

@creeper451
Copy link

creeper451 commented Feb 16, 2024

When I launch ttyd from the browser in a new tab the fonts gets displayed incorrectly the first time, in order to fix it, you would have to refresh the page every time you launch it in a new tab.

I complied ttyd from source and I added the Caskaydia Cove Nerd Font using the instructions described in the Wiki, and then started the ttyd binary using the following parameters:
'-p 6175 -W -t fontSize=15 -t enableSixel=true -t enableZmodem=true -t "fontFamily=My Font" login'

Screenshots:

1
2

Environment:

  • OS: [e.g. Windows 10 Version 1809]
  • Browser: [e.g. Brave 1.62.165 Chromium: 121.0.6167.184]

log of ttyd:
log.txt

@creeper451 creeper451 added the bug label Feb 16, 2024
@creeper451 creeper451 changed the title Fonts being displayed incorrectly. Fonts being displayed incorrectly Feb 16, 2024
@tsl0922
Copy link
Owner

tsl0922 commented Mar 29, 2024

Maybe because the font was not loaded at the first time. It's required to call fitAddon.fit() after font change:

if (key.indexOf('font') === 0) fitAddon.fit();

@creeper451
Copy link
Author

Sorry for my late reply, I checked this line on my machine and its there so... I don't understand what you are trying to say, I named the custom font that I added to the source code "MyFont" should I add it to the end of this line or what?

@IZSkiSurfer
Copy link

IZSkiSurfer commented Oct 1, 2024

Hi folks, I stumbled across the same bug.

I use an inlined nerd font (as described in the wiki) and pass the following arguments to ttyd --client-option fontFamily="MesloLGS_NG" --client-option fontSize=13.3.
So I don't "change" the font (later).

It looks like the fit() / resize() functions compare the rows and cols and behave different when values are the same as before or different. Also somehow the CharSizeService of xterm.js is taken into account. I can't dig deeper into it but for the moment I fixed it this way:

ttyd/html/src/components/terminal/xterm/index.ts

                default:
                    console.log(`[ttyd] option: ${key}=${JSON.stringify(value)}`);
                    if (terminal.options[key] instanceof Object) {
                        terminal.options[key] = Object.assign({}, terminal.options[key], value);
                    } else {
                        terminal.options[key] = value;
                    }
                    if (key.indexOf('font') === 0) {
+                       setTimeout(() => {
+                           terminal.resize(Math.max(0, terminal.cols - 1), terminal.rows);
+                       }, 100);
                        fitAddon.fit();
                    }
                    break;

Then the usual yarn build and make.

A very dirty hack but at least it works...
I guess the font not yet loaded at that stage and in turn the cols/rows and/or CharSize is calculated wrong.
Maybe it's not even a ttyd bug but a xterm.js bug - dunno.
If someone has a cleaner solution - I can test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants