Make df2console only call df2utf if the output stream is a console

Fixes output in command-prompt, for example
develop
lethosor 2018-07-09 11:00:28 -04:00
parent 7fcc6be6f6
commit 46e53fc3b3
5 changed files with 14 additions and 2 deletions

@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes ## Fixes
-@ Console: fixed crash when entering long commands on Linux/macOS -@ 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 - `startdwarf`: fixed on 64-bit Linux
## Structures ## Structures

@ -1416,7 +1416,7 @@ static bool isMapLoaded() { return Core::getInstance().isMapLoaded(); }
static std::string df2utf(std::string s) { return DF2UTF(s); } static std::string df2utf(std::string s) { return DF2UTF(s); }
static std::string utf2df(std::string s) { return UTF2DF(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) #define WRAP_VERSION_FUNC(name, function) WRAPN(name, DFHack::Version::function)

@ -25,6 +25,7 @@ distribution.
#include "Internal.h" #include "Internal.h"
#include "Export.h" #include "Export.h"
#include "MiscUtils.h" #include "MiscUtils.h"
#include "ColorText.h"
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
// We don't want min and max macros // We don't want min and max macros
@ -394,3 +395,8 @@ DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in)
#endif #endif
return is_utf ? DF2UTF(in) : in; 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;
}

@ -45,6 +45,10 @@ using std::endl;
#define DFHACK_FUNCTION_SIG __func__ #define DFHACK_FUNCTION_SIG __func__
#endif #endif
namespace DFHack {
class color_ostream;
}
/*! \namespace dts /*! \namespace dts
* std.reverse() == dts, The namespace that include forward compatible helpers * std.reverse() == dts, The namespace that include forward compatible helpers
* which can be used from newer standards. The preprocessor check prefers * 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 UTF2DF(const std::string &in);
DFHACK_EXPORT std::string DF2UTF(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(const std::string &in);
DFHACK_EXPORT std::string DF2CONSOLE(DFHack::color_ostream &out, const std::string &in);

@ -69,7 +69,7 @@ command_result df_showmood (color_ostream &out, vector <string> & parameters)
out.printerr("Dwarf with strange mood does not have a mood type!\n"); out.printerr("Dwarf with strange mood does not have a mood type!\n");
continue; 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) switch (unit->mood)
{ {
case mood_type::Macabre: case mood_type::Macabre: