Skip to content

Commit 2520c29

Browse files
authored
Merge pull request #5739 from ab9rf/utf8-console
fix windows console (#5737)
2 parents 964c2ad + f766031 commit 2520c29

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Template for new versions:
6262
- `autoclothing`, `autoslab`, `tailor`: orders will no longer be created with a repetition frequency of ``NONE``
6363

6464
## Misc Improvements
65+
- 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
6566

6667
## Documentation
6768

library/MiscUtils.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,20 +653,31 @@ std::string UTF2DF(const std::string &in)
653653
out.resize(pos);
654654
return out;
655655
}
656-
657-
DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in)
656+
static bool console_is_utf8()
658657
{
659-
bool is_utf = false;
660658
#ifdef LINUX_BUILD
659+
static bool checked = false;
660+
static bool is_utf = false;
661+
if (checked)
662+
return is_utf;
663+
661664
std::string locale = "";
662665
if (getenv("LANG"))
663666
locale += getenv("LANG");
664667
if (getenv("LC_CTYPE"))
665668
locale += getenv("LC_CTYPE");
666669
locale = toUpper_cp437(locale);
667-
is_utf = (locale.find("UTF-8") != std::string::npos) ||
668-
(locale.find("UTF8") != std::string::npos);
670+
is_utf = (locale.find("UTF-8") != std::string::npos) || (locale.find("UTF8") != std::string::npos);
671+
checked = true;
672+
return is_utf;
673+
#else
674+
return true; // Since DF 53.11, Windows console is always UTF-8
669675
#endif
676+
}
677+
678+
DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in)
679+
{
680+
bool is_utf = console_is_utf8();
670681
return is_utf ? DF2UTF(in) : in;
671682
}
672683

0 commit comments

Comments
 (0)