Textualize / rich-cli

Rich-cli is a command line toolbox for fancy output in the terminal
https://www.textualize.io
MIT License
2.99k stars 77 forks source link

Hard-code UTF-8 encoding for the input file #56

Closed olivierphi closed 2 years ago

olivierphi commented 2 years ago

This is a first draft to fix the encoding errors described in #55 - i.e. we're on Windows and the input file is encoded in UTF-8.

The role of PYTHONIOENCODING, as described in the issue

The bug report mentions that even when the PYTHONIOENCODING env var is set, the preferred encoding determined by Python on Windows is still a Windows-specific encoding. However, it seems that this is actually pretty much the expected behaviour, as the behaviour of this env var seems to only affect stdin/stdout/stderr? PYTHONIOENCODING-not-changing-preferred-encoding

Potential breaking changes brought by this PR

Of course, assuming that the input file is always encoded in UTF-8, like we do with this PR, could break some existing usages of Rich-CLI. Especially on Windows, where UTF-8 is still not the default encoding if I'm not wrong? Not sure what would be the safest way to handle that issue? 🤔

Potential ways to handler that better

Before / After

Before this fix:

before-utf8-fix

After this fix:

after-utf8-fix cmd

fixes #55