diff --git a/docs/changelog.txt b/docs/changelog.txt index 8dac1f1b4..a110512ce 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes -@ Console: fixed crash when entering long commands on Linux/macOS +- Fixed special characters in `command-prompt` and other non-console in-game outputs on Linux/macOS (in tools using ``df2console``) - `startdwarf`: fixed on 64-bit Linux ## Structures diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index ed37ebcea..6e17817a3 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1416,7 +1416,7 @@ static bool isMapLoaded() { return Core::getInstance().isMapLoaded(); } static std::string df2utf(std::string s) { return DF2UTF(s); } static std::string utf2df(std::string s) { return UTF2DF(s); } -static std::string df2console(std::string s) { return DF2CONSOLE(s); } +static std::string df2console(color_ostream &out, std::string s) { return DF2CONSOLE(out, s); } #define WRAP_VERSION_FUNC(name, function) WRAPN(name, DFHack::Version::function) diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp index daaea64df..84dddbbd6 100644 --- a/library/MiscUtils.cpp +++ b/library/MiscUtils.cpp @@ -25,6 +25,7 @@ distribution. #include "Internal.h" #include "Export.h" #include "MiscUtils.h" +#include "ColorText.h" #ifndef LINUX_BUILD // We don't want min and max macros @@ -394,3 +395,8 @@ DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in) #endif return is_utf ? DF2UTF(in) : in; } + +DFHACK_EXPORT std::string DF2CONSOLE(DFHack::color_ostream &out, const std::string &in) +{ + return out.is_console() ? DF2CONSOLE(in) : in; +} diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h index 51ccea656..ec2c7be58 100644 --- a/library/include/MiscUtils.h +++ b/library/include/MiscUtils.h @@ -45,6 +45,10 @@ using std::endl; #define DFHACK_FUNCTION_SIG __func__ #endif +namespace DFHack { + class color_ostream; +} + /*! \namespace dts * std.reverse() == dts, The namespace that include forward compatible helpers * which can be used from newer standards. The preprocessor check prefers @@ -384,3 +388,4 @@ DFHACK_EXPORT std::string stl_vsprintf(const char *fmt, va_list args) Wformat(pr DFHACK_EXPORT std::string UTF2DF(const std::string &in); DFHACK_EXPORT std::string DF2UTF(const std::string &in); DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in); +DFHACK_EXPORT std::string DF2CONSOLE(DFHack::color_ostream &out, const std::string &in); diff --git a/plugins/showmood.cpp b/plugins/showmood.cpp index 8f7bb2462..c7d620676 100644 --- a/plugins/showmood.cpp +++ b/plugins/showmood.cpp @@ -69,7 +69,7 @@ command_result df_showmood (color_ostream &out, vector & parameters) out.printerr("Dwarf with strange mood does not have a mood type!\n"); continue; } - out.print("%s is currently ", DF2CONSOLE(Translation::TranslateName(&unit->name, false)).c_str()); + out.print("%s is currently ", DF2CONSOLE(out, Translation::TranslateName(&unit->name, false)).c_str()); switch (unit->mood) { case mood_type::Macabre: