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

The width of Box-drawing characters #14

Closed
NonerKao opened this issue Mar 4, 2018 · 14 comments
Closed

The width of Box-drawing characters #14

NonerKao opened this issue Mar 4, 2018 · 14 comments

Comments

@NonerKao
Copy link

NonerKao commented Mar 4, 2018

Check this for the definition of box-drawing (BD below) characters.

I found that these characters are defined to be of ambiguous width, so passing these to RuneWidth returns 2 in my environment. This is somehow inconvenient since AFAIK, terminal fonts tend to interpret BD characters in half-width.

Is it possible to remove these characters from the ambiguous table? I can make the PR if you think this sounds sane.

Thanks.

@mattn
Copy link
Owner

mattn commented Mar 4, 2018

It is depend on $LANG. And you can modify it to set EastAsianWidth.

@mattn
Copy link
Owner

mattn commented Mar 4, 2018

Now I added environment variable github.com/mattn/go-runewidth#IsEastAsian. You can modify it if you want to change behaivor.

@mattn mattn closed this as completed Mar 4, 2018
@NonerKao
Copy link
Author

NonerKao commented Mar 4, 2018

Thanks for the quick reply.

Just a feedback for this patch: for some shell, such as sh or bash, github.com/mattn/go-runewidth#IsEastAsian is not a valid name for environment variable.

@mattn
Copy link
Owner

mattn commented Mar 4, 2018

renamed to RUNEWIDTH_EASTASIAN.

@nzlov
Copy link

nzlov commented Apr 5, 2018

Hi @mattn, When LC_CTYPE=zh_CN.UTF-8, RUNEWIDTH_EASTASIAN is invalid. Box-drawing (BD below) characters, RuneWidth returns 2

@mattn
Copy link
Owner

mattn commented Apr 5, 2018

What character do you mean?

=│=
=AA=

Please try to paste above text on your terminal. This is my environment. UNIX.

38ea1497442d9a19

And Windows cmd.exe

d6860f291190eed6

@nzlov
Copy link

nzlov commented Apr 5, 2018

LC_CTYPE=zh_CN.UTF-8 RUNEWIDTH_EASTASIAN=0:
511aac51-1158-4e34-85e7-7e74a15b527d
LC_CTYPE=en_US.UTF-8:
10897581-0eeb-475c-ab7c-d42e11ce4c55

Macos 10.12.6 zh_CN iterm2 zsh

=│=
=AA=

image

@mattn mattn reopened this Apr 6, 2018
@mattn
Copy link
Owner

mattn commented Apr 6, 2018

Do you want to forcibly disable RUNEWIDTH_EASTASIAN ?

@mattn
Copy link
Owner

mattn commented Apr 6, 2018

How about this patch ?

diff --git a/runewidth.go b/runewidth.go
index 70de0dc..82568a1 100644
--- a/runewidth.go
+++ b/runewidth.go
@@ -4,12 +4,21 @@ import "os"
 
 var (
 	// EastAsianWidth will be set true if the current locale is CJK
-	EastAsianWidth = os.Getenv("RUNEWIDTH_EASTASIAN") == "1" || IsEastAsian()
+	EastAsianWidth bool
 
 	// DefaultCondition is a condition in current locale
 	DefaultCondition = &Condition{EastAsianWidth}
 )
 
+func init() {
+	env := os.Getenv("RUNEWIDTH_EASTASIAN")
+	if env == "" {
+		EastAsianWidth = IsEastAsian()
+	} else {
+		EastAsianWidth = env == "1"
+	}
+}
+
 type interval struct {
 	first rune
 	last  rune

@nzlov
Copy link

nzlov commented Apr 6, 2018

Good idea, but why not force return 1?

@mattn
Copy link
Owner

mattn commented Apr 6, 2018

What do you mean "return"?

@nzlov
Copy link

nzlov commented Apr 7, 2018

I want to remove these characters box-drawing from the ambiguous table

@mattn
Copy link
Owner

mattn commented Apr 8, 2018

Unfortunately, box-drawing characters are listed in ambiguous width characters.

http://www.unicode.org/reports/tr11-2/

@nzlov
Copy link

nzlov commented Apr 8, 2018

@mattn Ok,thanks.

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