Skip to content

Fix emoji render issue on MSYS2 - #1271

Closed
lifei wants to merge 2 commits into
mobile-shell:masterfrom
lifei:fix-emoji-render-issue-on-msys2
Closed

lifei wants to merge 2 commits into
mobile-shell:masterfrom
lifei:fix-emoji-render-issue-on-msys2

Conversation

@lifei

@lifei lifei commented May 19, 2023

Copy link
Copy Markdown

This pr can make mosh rendering emoji on MSYS2 work fine.

@achernya

Copy link
Copy Markdown
Collaborator

I don't understand the underlying reasoning of this PR. I am primarily concerned that it seems to sometimes return a wcwidth of 2, but I'm not convinced that those scenarios are correct. Can you provide some comments/documentation/reasoning for this change?

I believe a more correct fix is for mosh to ship its own up-to-date wcwidth tables, but I'm open to this PR if we can understand its effects more thoroughly.

I'd like to see tests added before this can be merged as well.

@lifei

lifei commented May 19, 2023

Copy link
Copy Markdown
Author

I don't understand the underlying reasoning of this PR. I am primarily concerned that it seems to sometimes return a wcwidth of 2, but I'm not convinced that those scenarios are correct. Can you provide some comments/documentation/reasoning for this change?

I believe a more correct fix is for mosh to ship its own up-to-date wcwidth tables, but I'm open to this PR if we can understand its effects more thoroughly.

I'd like to see tests added before this can be merged as well.

wcwidth is not the main problem. the root cause is mbrtowc takes 3 chars return 1 wchar_ts and the right result should be taking 4 chars return 2 wchar_ts in windows/msys2. also the wcrtomb has the same issue. so i use mbstowcs instead of mbtowc functions.

I update pr and add some comments.

@keithw

keithw commented May 19, 2023 •

Copy link
Copy Markdown
Member

I think the backstory here is that Mosh relies on the system to advertise (or at least checks and warns if the system doesn't set) __STDC_ISO_10646__, meaning, wchar_t represents a Unicode Scalar Value, end of story.

It looks like you're talking about a non-STDC_ISO_10646 system where wchar_t represents something else (a UTF-16 code unit). This is outside what Mosh has tried to support in the past (hence the check and warning at build time which I hope you are seeing here?), but of course it's totally reasonable if people want to take this on.

I would worry that it does make the parser more complicated to branch on this at runtime -- maybe there should be an entirely different parser for wchar_t=UTF-16 architectures that gets linked in at compile time? But that's just spitballing.

@lifei

lifei commented May 20, 2023 •

Copy link
Copy Markdown
Author

parser

the parser is almost unchanged, for the improvement just appear on the condition with the failure of the pwccheck. so it should be just some small corner case fix for the parser.

a bigger change in this pr i think should be adding a field raw to class Print. And i suggest that in common case the filed raw is also reasonable, for chars has been converted twice through the process. they were converted to wcahr_t when saving to the Print, and converted back to char when printing to the console.

@lifei

lifei commented May 22, 2023

Copy link
Copy Markdown
Author

@achernya @keithw i made a graphical interpretation.
Snipaste_2023-05-22_16-10-07

@achernya

Copy link
Copy Markdown
Collaborator

@lifei the screenshot you posted honestly leaves me with more concerns. Given what @keithw said above, it seems that this is "WAI" from a mosh perspective that wchat_t is a UTF-8 type, and making this work on Windows is a lot more involved than this PR accomplishes. I am not comfortable merging this PR as a result.

@lifei

lifei commented May 22, 2023

Copy link
Copy Markdown
Author

@lifei the screenshot you posted honestly leaves me with more concerns. Given what @keithw said above, it seems that this is "WAI" from a mosh perspective that is a UTF-8 type, and making this work on Windows is a lot more involved than this PR accomplishes. I am not comfortable merging this PR as a result.wchat_t

Making emoji rendering on Windows is a lot more involved than this PR accomplishes. is right. So This PR also introduces a field named raw to pass original UTF-8 chars, which is unconverted, unchanged and right for the printing to console.

In my option, we should just cut the UTF-8 chars into Cells correctly, not converting, then everything would work fine. So the logic should be how to cut the UTF-8 chars to cells and how to know the cell's width. That's all. No unicode, no wchat_t.

A✏️B❌C📁D✅E📂F😢
                ↓
A|✏️|B|❌|C|📁|D|✅|E|📂|F|😢|
                ↓
1|2|1|2|1|2|1|2|1|2
                ↓
The console

@achernya

Copy link
Copy Markdown
Collaborator

You cannot "just cut the UTF-8 chars into Cells correctly" without a lot more information. The bug here, as Keith mentioned above, is an incompatibility between the parser's state machine and the type of wchar_t. As we've seen here some characters take multiple cells, hence the calls to wcwidth. You can't do this with "No unicode, no wchar_t".

@lifei

lifei commented May 23, 2023 •

Copy link
Copy Markdown
Author

You cannot "just cut the UTF-8 chars into Cells correctly" without a lot more information. The bug here, as Keith mentioned above, is an incompatibility between the parser's state machine and the type of wchar_t. As we've seen here some characters take multiple cells, hence the calls to wcwidth. You can't do this with "No unicode, no wchar_t".

You're right. What I real mean is that unicode/wchar_t can be used in cutting chars and measuring the length, no used in printing.

@achernya

Copy link
Copy Markdown
Collaborator

That's still not a great idea because the terminal state machine needs to know the width of the characters it's displaying. Just emitting raw bytes means that the state of the outer and inner terminals can desync.

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

Successfully merging this pull request may close these issues.

3 participants