malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.23k stars 30 forks source link

autocomplete for chinese path is weird #96

Open z0ow opened 3 years ago

z0ow commented 3 years ago

image For example, there exists a directory "MCNP格式转换工具" in the Desktop directory, and the PWD is Desktop. If I typed "cd MC" and press TAB to autocomplete the residual characters, the display result looks weird.

I guess the behavior of yori is to display characters based on the same width (1 ASCII character width) but the Chinese characters occupied 2 widths.

Wish this bug could be fixed in the next update 😄

malxau commented 3 years ago

Yes, double width characters won't work well in any of these tools. I've looked into this before and they seem very difficult to handle correctly.

As far as I know, each character in the Unicode can be:

This creates two things that are uncertain:

Both of these can only be known by firstly knowing what the display font is. It is very unnatural for a command line program to know what font is being used to display it. Strictly speaking, a Windows command line program running locally can know this by calling GetCurrentConsoleFontEx, and start calling into the UI libraries to determine what the font can do. As far as I know, it's not really possible to do this across SSH or another pipe that cannot communicate the font used to display the characters.

If there are better ways to handle this, I'd really like to hear about them. This can't be the first project to face these problems, but I don't see how layout can be correct unless the console and command line program agree - exactly - on how wide each character needs to be.