Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Template for new versions:
## Fixes

## Misc Improvements
- General: DFHack will unconditionally use UTF-8 for the console on Windows, now that DF forces the process effective system code page to 65001 during startup

## Documentation

Expand Down
21 changes: 16 additions & 5 deletions library/MiscUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,20 +653,31 @@ std::string UTF2DF(const std::string &in)
out.resize(pos);
return out;
}

DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in)
static bool console_is_utf8()
{
bool is_utf = false;
#ifdef LINUX_BUILD
static bool checked = false;
static bool is_utf = false;
if (checked)
return is_utf;

std::string locale = "";
if (getenv("LANG"))
locale += getenv("LANG");
if (getenv("LC_CTYPE"))
locale += getenv("LC_CTYPE");
locale = toUpper_cp437(locale);
is_utf = (locale.find("UTF-8") != std::string::npos) ||
(locale.find("UTF8") != std::string::npos);
is_utf = (locale.find("UTF-8") != std::string::npos) || (locale.find("UTF8") != std::string::npos);
checked = true;
return is_utf;
#else
return true; // Since DF 53.11, Windows console is always UTF-8
#endif
}

DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in)
{
bool is_utf = console_is_utf8();
return is_utf ? DF2UTF(in) : in;
}

Expand Down