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

Misaligned output #78

Open
ners opened this issue Dec 25, 2022 · 12 comments
Open

Misaligned output #78

ners opened this issue Dec 25, 2022 · 12 comments
Labels
bug Something isn't working output

Comments

@ners
Copy link

ners commented Dec 25, 2022

I'm not quite sure why, but the overview section of the nom build output is always misaligned.

image

This was tested on an M1 MacBook Pro running macOS Ventura.

It looks this way both in the official Terminal app and in iTerm 2. Changing between various fonts, even Nerd ones, also seems to have no effect.

@maralorn maralorn added bug Something isn't working output labels Dec 25, 2022
@ners
Copy link
Author

ners commented Jan 2, 2023

Also spotted in x86-64 WSL.

grafik

@ners ners changed the title Misaligned output on aarch64-darwin Misaligned output Jan 2, 2023
@davidak
Copy link

davidak commented Feb 18, 2023

Not an issue for me on NixOS 22.11.2606.2fb7d749c08 with Pantheon Terminal.

Screenshot from 2023-02-18 01-56-46

nix-output-monitor 2.0.0.5
nix (Nix) 2.11.1

@maralorn
Copy link
Owner

maralorn commented Feb 18, 2023

To be fair, while on my system it’s not that bad as above I am also having misaligned output issues. This is super hard to get right on all platforms simultaneously, the problem is that it’s really hard to predict how many cells a certain emoji is wide in the current font.
In kitty, my current terminal of choice, this actually changes during a run of nom (i.e. during a waiting build the hourglass sometimes has width 1 and sometimes width 2 without a discernible pattern …)

@999eagle
Copy link

This sounds like it's caused in kitty by kovidgoyal/kitty#3998. Kitty has a different behavior for character widths, so the sequence U+23F3 U+FE0E (hourglass + VS15) is rendered with a width of one cell instead of the two cells NOM calculates.
This rendering difference means it's generally impossible to do alignment the "correct" way across all terminal emulators without special casing.

@maralorn
Copy link
Owner

Yes, that is also my fear. But even reliably detecting in which terminal we run seems hard.

I am considering to actually drop all emojis which tend to have an irregular width or at least offer an option to do so …

@zeorin
Copy link

zeorin commented Aug 24, 2023

There is some relevant discussion with Kovid Goyal regarding the default presentations (and thus width in cells) of certain code points: kovidgoyal/kitty#6572 (comment)

TL;DR: if you are explicitly adding the text presentation selector to the output (U+FE0E), you should expect the terminal to draw a single-width glyph, and if you are adding the emoji presentation selector (U+FE0F) you should expect the terminal to draw a double-width glyph. Any terminal that does not do this is exhibiting non-conformant behaviour and you should log an issue with that project.

The trickiness is really only when you're not adding presentation selectors. For code points that have both text and emoji presentations, they each have a default presentation. Technically, which presentation to actually render is up to the environment, but in practice a terminal emulator should stick to the default presentation exactly because there is no explicit way for the program to know which presentation is being used (and thus, how wide the rendered glyph is expected to be).

@maralorn
Copy link
Owner

Interesting. I observed the "stuff changes if there is a whitespace behind it" behavior as well.
I think I am consistently using a presentation selector.

This discussion gives me hope, that there is a principled solution to this. Will investigate when I have the time.

@takeda
Copy link

takeda commented Sep 3, 2023

Not sure if this provides any insight, but I just noticed this.

I'm on mac and use iTerm. Whenever I use NOM the output is always misaligned (it looks like the picture in initial comment). I'm currently connected to NixOS from the same iTerm on the same Mac and the output looks properly aligned.

So it likely might have to do with how the terminal is initialized, perhaps the selector (mentioned by @zeorin) is set differently on those systems.

@ghost
Copy link

ghost commented Oct 29, 2023

I observe this as well under alacritty and the PragmataPro font (with nerdfonts glyphs).

This tool is so awesome! I can't believe it took me this long to try it.

nom

@9999years
Copy link
Contributor

9999years commented Nov 7, 2023

I've noticed that the wcwidth call here frequently returns -1:

widthFold (x, False) c = (x + wcwidth c, False)

The main culprits are these characters:

However, patching widthFold to return a minimum of 1 doesn't help much.

Another problem is that the output includes variation selectors 15 and 16 to force text and emoji presentation (respectively) of the subsequent codepoint; for some reason, wcwidth thinks these characters are 1 cell wide.

Finally, the variation selectors are being used incorrectly; they're supposed to be before the codepoint they're applied to, not after it:

EDIT: Thanks @P1n3appl3 for pointing me to the Unicode docs on this, I had this wrong.

-- ["2193","FE0E"]
down = "" <> textRep

@maralorn
Copy link
Owner

maralorn commented Nov 8, 2023

@amjoseph-nixpkgs Do you mind sharing on which system you encountered this issue? I am getting the impression that wcwidth works correctly on linux but is broken when used on Mac and WSL.

@ghost
Copy link

ghost commented Nov 9, 2023

@amjoseph-nixpkgs Do you mind sharing on which system you encountered this issue?

Linux, sway, alacritty, Nixpkgs

I don't run NixOS (no systemd) but I don't think that has much to do with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working output
Projects
None yet
Development

No branches or pull requests

7 participants