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

readLine: Unicode support for Windows console #14782

Merged
merged 3 commits into from
Jul 20, 2020
Merged

Conversation

ktamp
Copy link
Contributor

@ktamp ktamp commented Jun 23, 2020

When input is read from the Windows console, input encoding is UTF16. This is translated internally to UTF8.

When input is read from the Windows console, input encoding is UTF16. This is translated internally to UTF8.
Comment on lines 18 to 20
import os
import system/widestrs
import terminal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad, as all modules have system/io implicitly imported. This will cause recursive imports, which we don't support (but we should) atm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can work around os by calling GetLastError.
We can also work around terminal by accessing File struct contents (although this may not be pretty).
But working around widestrs is another matter...

This is what makes code work across compilers.
GCC has this functionality built-in, but what about other compilers?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC console have special HANDLE values that we can just compare to instead.

As for widestrs, you might not even have to import it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/nim-lang/Nim/blob/devel/lib/pure/terminal.nim#L669-L672

isatty() is simple enough to just duplicate into io for this.

ktamp added 2 commits June 25, 2020 00:22
**--gc:arc** defines **nimv2**. This changes the definition of **WideCStringObj**.
Also an empty string should be returned in case of EOF.
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