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

tmux: enable utf8proc #5665

Closed
wants to merge 1 commit into from
Closed

Conversation

joshuarubin
Copy link
Contributor

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same formula update/change?
  • Have you built your formula locally prior to submission with brew install <formula> (where <formula> is the name of the formula you're submitting)?
  • Does your submission pass brew audit --new-formula <formula> (after doing brew install <formula>)?

This enables the use of utf8proc for calculating character widths. This fixes most issues with tmux on mac.

Here is the PR this originated from: tmux/tmux#524

@mistydemeo
Copy link
Member

If this is recommended for all users, do you think it's worth revisioning the formula so that everyone is upgraded to this?

@MikeMcQuaid
Copy link
Member

@BrewTestBot test this please

@MikeMcQuaid
Copy link
Member

Can you provide more details as to when this is needed? Is it needed when using Terminal.app?

@dunn dunn added the needs response Needs a response from the issue/PR author label Oct 8, 2016
@BrewTestBot BrewTestBot removed the needs response Needs a response from the issue/PR author label Oct 10, 2016
@joshuarubin
Copy link
Contributor Author

@mistydemeo:

If this is recommended for all users, do you think it's worth revisioning the formula so that everyone is upgraded to this?

Probably. I updated the PR.

@MikeMcQuaid:

Can you provide more details as to when this is needed? Is it needed when using Terminal.app?

Changes introduced in tmux 2.2 removed much of tmux's built in handling for unicode in favor of relying on system libraries. This cleaned up the codebase and, on many operating systems, improved tmux's support of unicode. However, the Mac's wcwidth function (man 3 wcwidth, "number of column positions of a wide-character code") has been broken for a very long time, often returning -1 (which the homebrew patch to tmux 2.2 "fixed" to mean 1 column) and sometimes returning the wrong column width entirely for a character.

This is what caused people to have lots of problems with tmux on mac for 2.2, especially if they had unusual characters for terminal prompts or tmux status lines.

I worked with the tmux author to integrate optional support for utf8proc which was developed for the julia language and is widely seen as an excellently designed and maintained, cross-platform unicode support library.

When utf8proc is enabled, all unicode character widths are calculated using it, instead of the built in wcwidth.

I should note that there are a few edge cases that I believe should be updated within utf8proc (detailed here: JuliaStrings/utf8proc#83). However, by and large, it is a massive improvement over the mac's built in libraries.

To answer your question, yes, it greatly improves support for wide characters in Terminal.app, iTerm2.app, any terminal in which tmux is run.

@MikeMcQuaid
Copy link
Member

Ok, thanks for the comprehensive response @joshuarubin!

@MikeMcQuaid
Copy link
Member

Thanks again for your contribution to Homebrew! Without people like you submitting PRs we couldn't run this project. You rock!

@joshuarubin
Copy link
Contributor Author

Thanks a bunch!

@theckman
Copy link
Contributor

@joshuarubin I think this change has caused tmux to have some redraw issues on my MBP. Specifically, emacs is rendering things all garbled. Here's a short video showing the issue, the 2.3_1 usage starts at about 0:40:

@joshuarubin
Copy link
Contributor Author

I was able to reproduce this, only after installing spacemacs though (I'm not much of an emacs guy). It seems that some of the characters used in the mode line are getting their width calculated differently (from before, and from how the terminal calculates character width) by utf8proc which is causing a line overflow. Disabling the mode line should fix the rendering (or at least prove that it is causing the issue).

This is a dicey issue. The problem is that wide characters (like emoji) should usually be rendered with 2 columns, but that Terminal.app, iTerm2.app and likely others actually render it as 1 column (try running echo "😀z" in a terminal, you'll see that the z gets covered up). This is also font dependent as some fonts may incorrectly implement normal and wide characters widths.

Figuring out the width a character should be is one thing (which utf8proc does very well). Figuring out the width that the terminal actually displays it as is another issue. It probably isn't realistic to try to reconcile all of these differences (where the terminal will almost always be the offender if utf8proc is used).

iTerm2.app (nightly) has an option to enable Unicode 9 character widths to address this issue, but that breaks a whole lot of other things and really isn't safe to enable yet.

I already override some of utf8proc's calculations here to get better compatibility with how terminals actually render the characters.

If we can identify the characters causing the issue, we may be able to patch it in homebrew, though I am not sure if it will be accepted upstream in tmux, particularly if we have many individual cases to check and can't just use a unicode category.

@MikeMcQuaid
Copy link
Member

If we can identify the characters causing the issue, we may be able to patch it in homebrew, though I am not sure if it will be accepted upstream in tmux, particularly if we have many individual cases to check and can't just use a unicode category.

Just a note to avoid people wasting time: if it's not accepted upstream we won't accept it in Homebrew either.

@wincent
Copy link
Contributor

wincent commented Nov 9, 2016

This causes some horrible rendering glitches for me (reported in tmux/tmux#632), so I've been forced to uninstall the Homebrew-supplied tmux and build my own without --enable-utf8proc from master.

Is there a way to make this optional or overridable? Feels like there may be a long tail of issues in utf8proc that may take a while to address upstream.

@theckman
Copy link
Contributor

theckman commented Nov 9, 2016

I am starting to think the same. I worked around it by reverting my local Homebrew repo to the commit before this change was added, installed tmux and used brew switch to stay pinned to the working version.

This was absolutely a breaking change for me. I've yet to discover the exact cause of my rendering glitch, but I'd like to be able to continue using the latest tmux without these undesirable behaviors.

It may be worth mentioning that while yet I was aware of the issues this was trying to solve, the bugs it introduces for me are worse than the original problem.

@MikeMcQuaid
Copy link
Member

I'd like to get @joshuarubin's thoughts on this.

@wincent @theckman Are you using iTerm or Terminal.app?

@wincent
Copy link
Contributor

wincent commented Nov 10, 2016

@MikeMcQuaid: iTerm.

@theckman
Copy link
Contributor

theckman commented Nov 10, 2016

@MikeMcQuaid I've replicated my issues in both iTerm and Terminal.app, but I primarily use iTerm.

@joshuarubin
Copy link
Contributor Author

Can we get some examples of the problems? Are you using uncommon fonts or symbols? The best thing I can think would be to make the utf8proc change configurable in the brew file itself so people can opt out of it if it's not working for them.

@MikeMcQuaid
Copy link
Member

@joshuarubin An option is the easy way out. We need to decide what the default should be. I'm thinking we should defer to tmux's defaults. Do you know why they weren't changed?

@theckman
Copy link
Contributor

@joshuarubin The only place I've hit it was using Spacemacs (Emacs). It's probably worth mentioning that I reverted back when I commented above / provided the YouTube link, which was probably within a few hours of finding it. So I didn't have much time to find other issues.

@wincent
Copy link
Contributor

wincent commented Nov 11, 2016

Can we get some examples of the problems? Are you using uncommon fonts or symbols?

I doubt that the font is relevant. See these issues in the tmux repo for examples:

Seems like lots of people are running into this.

I'm thinking we should defer to tmux's defaults.

I don't know why the default was changed, but utf8proc was added in tmux/tmux@6c94774 and disabled by default a couple weeks after in tmux/tmux@6e8f400

@joshuarubin
Copy link
Contributor Author

There is a change in tmux not yet in the latest release (I think) that removes some character overrides that were put in place when utf8proc was used. Because of this, it's unclear in each of these cases, 1) is utf8proc used and 2) were the overrides in place if it was?

@wincent
Copy link
Contributor

wincent commented Nov 11, 2016

All of my testing has been against the current HEAD of master in the tmux repo.

@MikeMcQuaid
Copy link
Member

I think it's worth reverting back to the tmux default and letting them decide what to set this value to.

@joshuarubin
Copy link
Contributor Author

So that means the overrides are no longer in place. The overrides were for all things in the unicode "symbol" category. They protected people using things like powerline on a unicode8 terminal. If you use iterm2, switch to the nightly and enable unicode9 widths, see if that helps.

@joshuarubin
Copy link
Contributor Author

Can we keep utf8proc as a brew level option in any case?

@MikeMcQuaid
Copy link
Member

Sure.

@theckman
Copy link
Contributor

theckman commented Nov 11, 2016

@joshuarubin @MikeMcQuaid thank you for your continued discussion around this. I had some spare time today so I whipped-up a quick Homebrew PR to remove utf8proc as being included by default, but allowed it as an option if you want to build against it.

This is #6838.

theckman pushed a commit to theckman/homebrew-core that referenced this pull request Nov 12, 2016
This change enhances the `tmux` Formula so that `utf8proc` support is an
opt-in change when building `tmux`.

There have been reports of rendering issues in versions of `tmux` when
`utf8proc` support is enabled. Specifically these issues appear to
happen when special symbols are printed, such as those commonly used in
the powerline-themed status lines and shell prompts.

The change to include `utf8proc` in `tmux` was in Homebrew PR Homebrew#5665. In
that some PR some `tmux` users have reported issues with text being
rendered in builds of `tmux`. There are also some other issues on the
`tmux` tracker around similar rendering problems:

* tmux/tmux#631
* tmux/tmux#632
* tmux/tmux#637
* tmux/tmux#639
MikeMcQuaid pushed a commit that referenced this pull request Nov 12, 2016
This change enhances the `tmux` Formula so that `utf8proc` support is an
opt-in change when building `tmux`.

There have been reports of rendering issues in versions of `tmux` when
`utf8proc` support is enabled. Specifically these issues appear to
happen when special symbols are printed, such as those commonly used in
the powerline-themed status lines and shell prompts.

The change to include `utf8proc` in `tmux` was in Homebrew PR #5665. In
that some PR some `tmux` users have reported issues with text being
rendered in builds of `tmux`. There are also some other issues on the
`tmux` tracker around similar rendering problems:

* tmux/tmux#631
* tmux/tmux#632
* tmux/tmux#637
* tmux/tmux#639

Closes #6838.

Signed-off-by: Mike McQuaid <[email protected]>
@theckman
Copy link
Contributor

Just to add a final update to this issue. A change was made in #6838 to disable utf8proc by default. This has been merged in to master approximately 23 hours ago. The rendering issues in this ticket should be resolved (for now).

@joshuarubin I'll give your suggestion a go in the coming days and do some playing around with iTerm2 nightlies. Hopefully that will make things work 💯.

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants