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

Grapheme clusters #838

Merged
merged 4 commits into from
Jan 23, 2025
Merged

Grapheme clusters #838

merged 4 commits into from
Jan 23, 2025

Conversation

gwenn
Copy link
Collaborator

@gwenn gwenn commented Jan 15, 2025

See #826

  • At least, make the mode configurable
  • Ideally, try to auto-detect / auto-select the mode based on some heuristics (but it seems difficult)

@gwenn gwenn marked this pull request as ready for review January 19, 2025 11:17
In case a cross-platform terminal like WezTerm is used
Ok("iTerm.app") => GraphemeClusterMode::Unicode,
Ok("WezTerm") => GraphemeClusterMode::Unicode,
Err(std::env::VarError::NotPresent) => match std::env::var("TERM").as_deref() {
Ok("xterm-kitty") => GraphemeClusterMode::NoZwj,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is almost perfect. The one issue I had was with Kitty (on Debian):

Image

This seems to work better with:

Suggested change
Ok("xterm-kitty") => GraphemeClusterMode::NoZwj,
Ok("xterm-kitty") => GraphemeClusterMode::Unicode,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the rendering varies depending on the platform / font used by Kitty ?
Because, I am almost sure that I tested kitty on MacOS. I will double check.
And, on Windows, all seems wrong:

Alacritty ~ (TERM=xterm-256color)
contour ~ (TERMINAL_NAME=contour)
WezTerm ~
Windows Terminal ~

But anyway, thanks for your feedback.

Copy link
Collaborator Author

@gwenn gwenn Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On MacOS, kitty seems fine:
image
(at least rustyline behaves like zsh)
Should we add #[cfg(target_os = "macos")] on Ok("xterm-kitty") => GraphemeClusterMode::NoZwj, ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried changing the font for Kitty, but my understanding is that it just automatically use a fallback font for emojis if it is not present in the provided font.

I suspect that the issue I have observed does depend on the installed font, and I do not see how this could be handled 100% of the time. When testing in xfce4-terminal, My guess is that the underlying terminal emulator (GNOME’s vte) does something that prevent the combination of the separate emojis, regardless of the font. It is unclear whether that is intentional, but it does mean that the behavior stays consistent accross installations.

Anyway, having a bunch of empty space next to the character is not a terrible failure case. It is probably better than the original behavior where it was hard to know what you were even typing. So, probably a worthwile trade-off.

@gwenn
Copy link
Collaborator Author

gwenn commented Jan 22, 2025

Wezterm is almost good on Windows (except 👩🏼‍👨🏼‍👦🏼‍👦🏼):
image
Alacritty (issue with ❤️) :
image
Contour is all wrong:
image
Windows Terminal iseems wrong:
image

@gwenn gwenn merged commit c689e32 into master Jan 23, 2025
3 checks passed
@gwenn gwenn deleted the grapheme-clusters branch January 23, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants