magiblot / tvision

A modern port of Turbo Vision 2.0, the classical framework for text-based user interfaces. Now cross-platform and with Unicode support.
Other
1.99k stars 150 forks source link

detect TVISION_CODEPAGE from system locale #96

Closed unxed closed 1 year ago

unxed commented 1 year ago

far2l is already doing this, you can look at the function DeduceCodepages() in file https://github.com/elfmz/far2l/blob/master/WinPort/src/APIStringCodepages.cpp

Locale to code page translation table is taken from Wine sources.

magiblot commented 1 year ago

Hi @unxed!

The only purpose of TVISION_CODEPAGE is to translate single-byte-encoded text used in the UI.

Generally, new applications will just use UTF-8 for its text labels, since it's the most convenient way. Therefore, neither developers nor users will have to worry about this variable during normal usage of Turbo Vision applications.

Note that Turbo Vision makes it so that standard library functions, even on Windows, use the UTF-8 encoding.

However, the default Turbo Vision UI elements (button shadows, frame borders...) are still encoded in CP437 (see https://github.com/magiblot/tvision/blob/master/source/tvision/tvtext1.cpp). Instead of changing all of those, I chose to preserve the code as-is and instead translate these characters on-the-go. Initially, this was necessary since UTF-8 support wouldn't be added until much later. When UTF-8 support was in place, this solution was still useful since it meant that Turbo Vision could still be built for DOS and that it was still possible to port old applications without changing much of their source code.

So, there is only one use case I can think of where it would be useful to change the TVISION_CODEPAGE: imagine you find the source code of an old DOS Turbo Vision application written using the cyrillic script. Without having to convert the source code to UTF-8, you could build this application using the modern library and set TVISION_CODEPAGE=866 so that cyrillic characters are displayed correctly. (Actually, this wouldn't work right now since codepage 866 is not currently defined in https://github.com/magiblot/tvision/blob/master/source/platform/codepage.cpp, but as the Readme says, this is a matter of adding codepages as they are needed).

Obviously, this is something only the application developer would be concerned about, and therefore TVISION_CODEPAGE has a very different purpose than the OEM and ANSI codepages in far2l, and it makes no sense to auto-detect it.

Originally, I made TVISION_CODEPAGE an environment variable so that it was possible to change the conversion table without changing the source code, but as it turns out, there is barely any usefulness in this, since I doubt there is a sound use case where it makes sense to let the user pick an arbitrary conversion table. Note that several non-CP437 code pages drop some of the box-drawing characters, so using a different code page will likely make some UI elements look worse, as is the case of CP850 (see picture below). Therefore, it makes sense to always use CP437 unless the developer explicitly requires a different one.

Screenshot_20230217_211102
unxed commented 1 year ago

Sounds reasonable. Closing.