charmbracelet / charmbracelet/bubbletea
key.go does not respect current codepage leading to utf8.RuneError
- Dominant language
- Go
- Stars
- 44.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Bubbletea does not respect the current codepage while parsing the console input from a user:
https://github.com/charmbracelet/bubbletea/blob/624343388b02eb2f5199ee8fcd29961ba3b17581/key.go#L515
It assumes the input encoding is utf8.
I'm using [Windows Terminal](https://github.com/microsoft/terminal). And `chcp`
```bash
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:
```go
var decoder = charmap.CodePage850.NewDecoder()
utf8bytes, err := decoder.Bytes(b[i:])
r, width := utf8.DecodeRune(utf8bytes)
```
instead of
```go
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?
Contributor guide
Assessment
This issue has not been assessed yet.