question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Terminal font letter spacing is huge on Arch Linux (not on Windows or Ubuntu)

See original GitHub issue

Details

I’ve only tested this on Windows 10, Ubuntu, and Arch Linux, but I’ve only had the problem on Arch, in Chrome, Konqueror, Vivaldi, and GNOME Web. Essentially, the each character in the terminal is its normal width, but the space around it is doubled, so each character takes up the space of two. Here’s some images from Cockpit on Chrome, and some more from xtermjs.org, also on Chrome. And as I said, on Windows it’s not an issue.

  • Browser and browser version: Chrome 81.0.4044.138 (Official Build) (64-bit), Konqueror 4.0.97, Vivaldi 3.0.1874.38 (Stable channel) (64-bit), and GNOME Web 3.36.2
  • OS version: Arch Linux (last pacman -Syu was a day ago)
  • xterm.js version: 4.6.0 within the Cockpit terminal on Fedora Server 32, and even on the xtermjs.org website (!).

Steps to reproduce

  1. Open any of the browsers listed (and I don’t think it’s limited to just those, but curiously it’s not an issue in VS Code…) on Arch Linux.
  2. Look at an xterm.js terminal and observe the extremely wide letter spacing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
Tyriarcommented, Aug 5, 2020

Here’s an addon that waits for fonts to load and then opens: https://github.com/CoderPad/xterm-webfont

1reaction
Kevin-Parkincommented, Aug 5, 2020

Daniel, I finally understand the wisdom in your comment.

xterm.js creates a <span> element (xterm-char-measure-element) containing the letter “W” and measures its width using getBoundingClientRect() to determine the character width. However, if the webfont is not loaded before this, getBoundingClientRect returns an overly conservative width instead. Even if there is an @font-face in the style sheet, the browser does not load the font until it is used.

xterm-webfont uses fontfaceobserver to solve the font loading problem and generate an event when the font is loaded. Unfortunately, I never could get xterm-webfont to work because my project cannot use javascript modules. The workaround was simply to use fontfaceobserver directly.

So now I have the following in my html webpage, which gives me a single-spaced webfont:

<style>
        @font-face {
            font-family: EIEFont;
            src: url(EIE.ttf);
        }
</style>
<script src="node_modules/xterm/lib/xterm.js"></script>
<script src="node_modules/fontfaceobserver/fontfaceobserver.js"></script>    
<script src="node_modules/xterm-addon-fit/lib/xterm-addon-fit.js"></script>
<script src="node_modules/xterm-addon-attach/lib/xterm-addon-attach.js"></script>
...
<script>
        var regular = new FontFaceObserver('EIEFont').load();
        var bold = new FontFaceObserver('EIEFont', {
            weight: "bold"
        }).load();
        Promise.all([regular, bold]).then(() => {
            const term = new Terminal({
                fontFamily: 'EIEFont',
                fontSize: 16, 
                theme: {
                    blue: '#0000ff'
                },
                cursorBlink: true,
                convertEol: true
            });
            const fitAddon = new FitAddon.FitAddon();
            term.loadAddon(fitAddon);
            term.open(document.getElementById('terminal'));
            fitAddon.fit();
            term.focus();

            and so on...
</script>

Hopefully this helps someone in future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Solved]spacing between characters not correct on any termial ...
I'm using Xfce on my laptop. The fonts don't look right in any of the terminal emulators. I've tried Xfce terminal, guake and...
Read more >
(Ubuntu) bad font rendering / weird letter spacing : r/linux4noobs
I'm asking because everything looks great on Windows which I've used before :/.
Read more >
Why text in the gnome-terminal has characters slightly ...
The font you use in your terminal is not a monospaced font or the configuration file of the terminal has a font size...
Read more >
Terminal Appearance in Visual Studio Code
fontSize : Changes the font size of text in the terminal. terminal.integrated.letterSpacing : Configures additional horizontal spacing between characters in ...
Read more >
How to change the default font size of XTerm? - Ask Ubuntu
Using Monospace will not just change the size but use a quite different font (at least that's the case on Ubuntu 18.04). And...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found