rensbreur / SwiftTUI

SwiftUI for terminal applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't support Chinese characters in the textfield

underthestars-zhy opened this issue · comments

The Chinese characters will become strange symbols

Thank you for reporting 👍

Not just Chinese characters, any multibyte character seem to fall apart.
For example, here's "Árvíztűrő tükörfúrógép" as it appears in the ToDoList sample: Ã�rvíztűrÅ� tükörfúrógé

This has some serious MS-DOS vibes 😄 But instead of codepage mismatches, this one is caused by reading one byte at a time from the standard input. Perhaps there's a more robust solution in Darwin?

Changing Control to pass around a Character, and changing the C read call to String(data:encoding:) seems to do the trick. I commented out arrow handling for the moment, so no PR yet. Actually, that wasn't a complicated fix either.

image

Thanks @vzsg for coming up with a fix for the character encoding 👏

With Chinese characters and emojis however, there is a second issue, which is that they are considered double-width by many Terminal apps. That means they occupy twice the width of other characters, and the cursor is moved two positions as well, which the rendering code in SwiftTUI doesn't handle properly. We might have to consider support for double-width characters as a new feature, unrelated to this encoding bug.