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

key.go does not respect current codepage leading to utf8.RuneError #447

Open
Vinschni opened this issue Sep 11, 2022 · 2 comments
Open

key.go does not respect current codepage leading to utf8.RuneError #447

Vinschni opened this issue Sep 11, 2022 · 2 comments

Comments

@Vinschni
Copy link

Vinschni commented Sep 11, 2022

Bubbletea does not respect the current codepage while parsing the console input from a user:

r, width := utf8.DecodeRune(b[i:])

It assumes the input encoding is utf8.
I'm using Windows Terminal. And chcp

PS C:\Windows\system32> chcp
Active Codepage: 850.

shows default encoding is Codepage 850 == DOS-Latin-1.
If I'm entering characters (in a textarea widget) on my german keyboard like ß, ö, ä, ü this leads to utf8.RuneError.

I could fix key.go just for my system by using:

var decoder = charmap.CodePage850.NewDecoder()
utf8bytes, err := decoder.Bytes(b[i:])
r, width := utf8.DecodeRune(utf8bytes)

instead of

r, width := utf8.DecodeRune(b[i:])

but this is no good nor general solution.
I assume a good solution would include using something like GetConsoleCP()

Futhermore pressing buttons on my keyboard like POS1 / END inserts a bracket to the textarea which suggests parsing of control characters does not work.

Is this a known problem?

@muesli
Copy link
Contributor

muesli commented Oct 6, 2022

Futhermore pressing buttons on my keyboard like POS1 / END inserts a bracket to the textarea which suggests parsing of control characters does not work.

Is this a known problem?

This should be fixed by 2fe4aad.

@muesli
Copy link
Contributor

muesli commented Oct 6, 2022

r, width := utf8.DecodeRune(b[i:])

Shouldn't this have been converted to utf8 by the localereader above?

Probably related: #153 and #343.

@muesli muesli added the question Further information is requested label Oct 13, 2022
@bashbunni bashbunni removed the question Further information is requested label Feb 16, 2023
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

No branches or pull requests

3 participants