odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.1k stars 550 forks source link

Refactor `core:text/table` #3791

Closed Feoramund closed 1 week ago

Feoramund commented 1 week ago

Several kilobytes of lookup tables and one grapheme segmentation algorithm later...

unicode-table-alignment

Resolves #3432

oskarnp commented 1 week ago

This is awesome. However, I am not a fan of breaking the API unless it is neccessary?

oskarnp commented 1 week ago

I'll review next week.

Feoramund commented 1 week ago

I changed colw to make calculations easier, set_cell_value_and_alignment because it was inconsistent with set_cell_value and only took a string (not an any), build to be the place where Width_Proc is specified (though this could have a default value if needed), renamed the proc from ascii to plain per the discussion in the original issue, and write_text_align to take a space argument instead of colw.

The arguments were rotated on write_text_align to purposefully break the API because the semantics of the arguments changed but the types did not.

Feoramund commented 1 week ago

All set.

oskarnp commented 1 week ago

I can't get the docs.odin to render that unicode table properly. Both GitHub using Safari and Sublime Text shows it incorrectly. Did you paste that properly? Or are they both wrong.

Edit: Running the actual code in Alacritty and iTerm2 for Mac works as expected. Pasting the output into Sublime Text messes it up. Interesting. (I'm using Fira Code font for Sublime.)

Feoramund commented 1 week ago

I have confirmed that Alacritty, kitty, WezTerm (with Thai out of alignment for some reason but otherwise fine), Konsole, QTerminal (same Thai issue), LXTerminal, and MATE terminal render it properly. I may not have good all-around Thai fonts installed, but it's otherwise fine on my end.

GitHub's display is browser-dependent, and it certainly doesn't render properly on my end, but I wouldn't expect it to.

I found a Sublime Text editor package for my distribution of Linux and installed it to have a look. With the default settings, all of the Unicode lines are out of alignment (except the actual Younger Futhark runes, amusingly enough). I'm able to get some of them to align if I set certain monospace fonts (Ubuntu Mono), but as this is the first time I've ever used Sublime Text before, I am uncertain if there may be some setting I'd have to toggle to get it to work properly.

It's very strange that it's getting CJK wrong, as they're the most easily predictable in terms of width. Even with a CJK font set, it's still not aligned. It also has issues with rendering the excessive diacritics line, as in, glyph placeholders are appearing.

I tried manually inserting spaces to see if I could align the Chinese row, and even with extra spaces, it's mis-aligned. I.e. there's no amount of space characters I can manually put in that would make the | line up. I'm inclined to say this is a rendering issue.

EDIT: I tried disabling bold, italics, antialiasing, and ligatures, and Sublime still failed to align the text. That's a shame.

oskarnp commented 1 week ago

@gingerBill @Kelimion LGTM

Great work, @Feoramund

Kelimion commented 1 week ago

Thanks as always, @Feoramund.