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

Pybricks Code hub stdout to terminal is not UTF-8 aware #1743

Closed
dlech opened this issue Aug 6, 2024 Discussed in #1742 · 6 comments · Fixed by pybricks/pybricks-code#2310
Closed

Pybricks Code hub stdout to terminal is not UTF-8 aware #1743

dlech opened this issue Aug 6, 2024 Discussed in #1742 · 6 comments · Fixed by pybricks/pybricks-code#2310
Assignees
Labels
bug Something isn't working software: pybricks-code Issues with https://code.pybricks.com application

Comments

@dlech
Copy link
Member

dlech commented Aug 6, 2024

Discussed in https://github.com/orgs/pybricks/discussions/1742

Originally posted by angzicn August 6, 2024
Thank you, I'm a Chinese pybricks fan and I want to teach my son use pybricks to make python code.
Can i print the Chinese str in the online terminal?
There is something wrong with the Chinese str printing in the terminal.
incomplete display, like this↓
微信截图_20240806152205
thank you!

@dlech dlech added bug Something isn't working software: pybricks-code Issues with https://code.pybricks.com application labels Aug 6, 2024
@dlech
Copy link
Member Author

dlech commented Aug 6, 2024

The problem is that data sent from the hub gets split up into 20 byte packets. If a multi-byte character gets split, Pybricks code currently isn't catching that and print two or more invalid characters instead of recombining the data into whole characters.

@dlech dlech self-assigned this Aug 6, 2024
dlech added a commit to pybricks/pybricks-code that referenced this issue Sep 8, 2024
Enable the stream option on the text decode for the stdout and uart
stream handlers that pipe data to the terminal. This fixes improperly
printing multibyte unicode characters that get split across multiple
data packets.

A new decode is added for each different stream in case both are used
at the same time.

Fixes: pybricks/support#1743
dlech added a commit to pybricks/pybricks-code that referenced this issue Sep 8, 2024
Enable the stream option on the text decode for the stdout and uart
stream handlers that pipe data to the terminal. This fixes improperly
printing multibyte unicode characters that get split across multiple
data packets.

A new decode is added for each different stream in case both are used
at the same time.

Fixes: pybricks/support#1743
@BertLindeman
Copy link

beta.pybricks.com has just been updated and now printing utf-8 characters look nice!

Small example:
image

So fixed!

Bert

@laurensvalk
Copy link
Member

laurensvalk commented Oct 15, 2024

I was going to add an example for @angzicn to say 很高兴认识你 (我学习中文) but bonus points for extra effort go to @BertLindeman 😄 Love it - thanks for sharing! I suppose you can make an animated story now. I think we support \r. Is there a sequence to go back a line?

Thanks @dlech for fixing this!

@BertLindeman
Copy link

Animated, I do not know, but I can share the program (need to cleanup all debugging)
Will do a discussions "look what I made item"

There are domino-stone images that could be animated. The \r worked before this update and I did not yet try it on this beta.

@dlech
Copy link
Member Author

dlech commented Oct 15, 2024

Is there a sequence to go back a line?

And much, much more: https://xtermjs.org/docs/api/vtfeatures/

@BertLindeman
Copy link

Misunderstood you Laurens, you were just stating the fact, not asking me to...., 😄

suppose you can make an animated story now

I use ANSI codes as an example to show xbox controls sent by an disconnected Technichub on some other hub.
The controls stay at their location for better understanding.
(Horrible code though)

Added the UTF-8 print program in discussion #1882 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working software: pybricks-code Issues with https://code.pybricks.com application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants