mycoboco / wcwidth.js

a javascript porting of C's wcwidth()
http://code.woong.org/wcwidth.js
Other
12 stars 2 forks source link

What about ambiguous-width characters #11

Open qiu8310 opened 9 years ago

qiu8310 commented 9 years ago

wcwidth will always return 1, but it should be 2 when enabled Treat ambiguous-width characters as double width in iTerm2 qq20151022-1

qiu8310 commented 9 years ago

For example: sindresorhus/time-grunt#52

mycoboco commented 9 years ago

Thanks for the information.

I had never heard that a terminal client could change the printing width of ambiguous-width characters before you told me.

Is there any good way to generally detect users' configuration other than providing an option to specify how to handle those characters?

qiu8310 commented 9 years ago

We can use ansi escape to get Device Status Report.

By using ansi escape technology I write a package called tty-detect which can async detect any character's length on terminal, but it only work on my MAC, not work on Windows. If you have any better way, please let me know.

On the other hand, I don't think we should detect the ternimal's Double-Width Characters setting, ternimal should export this setting to the environment.

mycoboco commented 8 years ago

My apologies for the late reply. It took more time than I expected to make progress on other projects and to figure out a way to employ the method you used in tty-detect.

Considering wcwidth.js's table-based approach, it seems difficult to adopt an empirical method to detect the width of ambiguous characters; wcwidth.js should work when there are no attached terminals. The best way I can think of is to provide an option for the predefined width, hoping that, as you said, terminals will export their setting in the future.