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 pannel lines rendered wrongly when locale set to zh_CN #259

Closed
BlurryLight opened this issue Sep 29, 2020 · 17 comments
Closed

tmux pannel lines rendered wrongly when locale set to zh_CN #259

BlurryLight opened this issue Sep 29, 2020 · 17 comments

Comments

@BlurryLight
Copy link

# To use common configuration in %APPDATA%\mintty, simply remove this file
ThemeFile=
Locale=C
Language=en_US
Term=xterm-256color
Font=Fixedsys
FontHeight=14
CursorType=line
ForegroundColour=0,255,255
Columns=120
CursorColour=128,0,64
BellType=0
BoldAsColour=yes

when Locale is set to C, the panel lines look fine.
图片

After I set the locale to zh_CN, which is

# To use common configuration in %APPDATA%\mintty, simply remove this file
ThemeFile=
Locale=zh_CN
Language=en_US
Term=xterm-256color
Font=Fixedsys
FontHeight=14
CursorType=line
ForegroundColour=0,255,255
Columns=120
CursorColour=128,0,64
BellType=0
BoldAsColour=yes

the tmux panel lines is rendered like
图片

The lines looks weired and some chars have been overlapped by the lines.

My wsl is Ubuntu 2004 and the wsltty is 3.3.0

@Biswa96
Copy link
Contributor

Biswa96 commented Sep 29, 2020

  • Does this happen if you run wsl.exe in Command Prompt or Powershell?
  • Does chaging font type and size make any change to this issue?

@BlurryLight
Copy link
Author

  1. I guess the locale entry in the mintty menu only affects mintty, is that right? I have tried to run tmux in cmd, powershll and mintty, only wsltty behaved weirdly on lines.

  2. I tried serveral font types and sizes, including consolas, fixedsys and some other fonts, but it was useless.

@Biswa96
Copy link
Contributor

Biswa96 commented Sep 29, 2020

Would you like to test this? If you have root access in your WSL distribution,

  1. backup the /etc/default/locale file
  2. create a new /etc/default/locale file and add this LANG=zh_CN@cjknarrow
  3. re-execute wsltty.

@BlurryLight
Copy link
Author

The lines now render correctly but another problem appears: The tty cannot neither display cjk characters nor emojis.

图片

my current mintty config is

# To use common configuration in %APPDATA%\mintty, simply remove this file
ThemeFile=flat-ui
Locale=zh_CN
Language=en_US
Term=xterm-256color
Font=Sarasa Term SC
FontHeight=14
CursorType=block
ForegroundColour=0,255,255
Columns=120
CursorColour=128,0,64
BellType=0
BoldAsColour=yes
Charset=UTF-8

@Biswa96
Copy link
Contributor

Biswa96 commented Sep 29, 2020

Another way is to pass -e LANG with wslbridge2 command inside mintty. /cc @mintty

@mintty
Copy link
Owner

mintty commented Sep 29, 2020

Manipulating locale is a tricky issue which requires some background know-how.
CJK locales trigger ambiguous-wide character width, which affects the width of the horizontal line.
And in fact, if your WSL shell does not have the same idea about the locale as the terminal, things will go very wrong.

@mintty
Copy link
Owner

mintty commented Sep 30, 2020

Did you actually check the locale set in the WSL shell? I suppose it's the default C.UTF-8. Try to set LC_ALL=zh_CN.UTF-8 bash. You may have to install the locale first.
If you still think there's something to analyse, please remind me of how to create a tmux panel.

@BlurryLight
Copy link
Author

It's somewhat confusing, at least for me, about the locale word in the context. From my understanding, there are two locales in wsltty and wsl. One is the locale setting in the wsl ubuntu, which is the LC_xx =XXX, and another one is the locale in the mintty menu Options->Text->locale. I have no idea if the two are correlated or not but I guess they are not.

So in my environment, my Ubuntu locales are set to zh_CN.UTF-8, which is set by sudo update-locale LANG=zh_CN.UTF-8.
And the problem appears when I change the mintty locale .

When the mintty locale is set to zh_CN, the lines display wrongly.
QQ截图20200930220314

And it works well when the mintty locale is C.
20200930221436

The font is Fixedsys, 12pt, and the Ubuntu Locale keeps zh_CN.UTF-8. Everytime I change the mintty locale, I open a new mintty and create a new tmux instance to make sure the change makes effect.

@mintty
Copy link
Owner

mintty commented Sep 30, 2020

There are two problems:

  1. The locale isn't propagated to WSL. Actually you handled this properly by setting both locales consistently.
  2. Locales are not identical in cygwin and WSL. Particularly, CJK locales have the "ambiguous wide" property in cygwin (the mintty environment) but they are "ambiguous narrow" in WSL. Meaning that a range of characters, traditionally included in CJK character sets for compatibility, are double-cell wide or not. This includes the horizontal line. As a workaround, cygwin introduced the locale suffix @cjknarrow, so setting LC_ALL=zh_CN.utf8@cjknarrow before starting mintty would make locales consistent and fix the problem. Unfortunately, there is no mechanism right now to set such a locale in the mintty configuration, you could only do it externally, from a command line. This is because I considered the explicit options Locale and Charset a legacy feature, but maybe they should be tweaked.

@mintty
Copy link
Owner

mintty commented Oct 1, 2020

When the mintty locale is set to zh_CN, the lines display wrongly.

Actually, as the mintty locale is not propagated towards WSL (where you have to set it explicitly), there is no benefit in setting this option for wsltty. I will add some documentation about this.
On the other hand, I am also considering to disable CJK ambiguous-wide character width in WSL mode.

@mintty
Copy link
Owner

mintty commented Oct 3, 2020

Actually, while checking whether interworking of mintty with WSL could be enhanced on this issue, I cannot reproduce it.
While setting LANG=zh_CN.utf8 before starting mintty (with no related setting in the config file) triggers the wide line,
mintty -o Locale=zh_CN -o Charset=UTF-8 does not, which should be sufficient to faciliate seamless running of WSL.

@mintty
Copy link
Owner

mintty commented Oct 4, 2020

@Biswa96, I guess I should add -e LANG -e LC_CTYPE -e LC_ALL to the invocation of wslbridge2 from mintty.

@mintty
Copy link
Owner

mintty commented Oct 4, 2020

I cannot reproduce it.

Comment withdrawn. I'll tweak locale setup for a workaround.

@Biswa96
Copy link
Contributor

Biswa96 commented Oct 4, 2020

I had said that workaround first. Though it works I am not fully satisfied with it.

mintty added a commit to mintty/mintty that referenced this issue Oct 5, 2020
@mintty
Copy link
Owner

mintty commented Oct 7, 2020

Actually, I think this should be tweaked in cygwin rather than mintty.
I.e., assuming that Linux systems / libraries (glibc, musl?) do not apply ambiguous-wide behaviour even for jp, ko, zh locales if they are combined with UTF-8 character encoding. At least that's what the locale zh_CN.utf8 on WSL Ubuntu suggests. Does anyone know whether this is consistent with other Linux distributions?

mintty added a commit to mintty/mintty that referenced this issue Oct 23, 2020
  * Revised locale handling and setting, especially with option Locale.
  * Revised character width determination and setting, especially with option Locale.
  * Revised setup of GB18030 encoding support.
  * New option to enforce narrow ambiguous-width.
  * Do not clear/overwrite all locale categories anymore by option Locale.
  * Do not enforce UTF-8 encoding with WSL anymore.
  * Propagate locale settings with option --WSL (mintty/wsltty#259).
  * Do not enforce UTF-8 for WSL anymore.
  * New option value Charwidth=ambig-narrow.
  * New option OldLocale.
@mintty
Copy link
Owner

mintty commented Oct 24, 2020

Released 3.4.1.

@mintty mintty closed this as completed Oct 24, 2020
@mintty
Copy link
Owner

mintty commented Nov 11, 2020

Released 3.4.3 with further tweaks.

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

No branches or pull requests

3 participants