diff options
author | Tad Marshall <tad@10gen.com> | 2012-06-29 15:43:22 -0400 |
---|---|---|
committer | Tad Marshall <tad@10gen.com> | 2012-06-29 15:43:22 -0400 |
commit | 181ff5d768e45bb4b84622444da9fa3e0181aaa8 (patch) | |
tree | 4545d911552c96815dc98b19181e630bd3431dec /src/mongo/util/text.cpp | |
parent | 5a55e91e68daa59ca29c1bb1a899fafb6a039b50 (diff) | |
download | mongo-181ff5d768e45bb4b84622444da9fa3e0181aaa8.tar.gz |
SERVER-6244 behave better when non-Unicode font used with shell
If the Windows WriteConsoleW() API fails because the console is set
to a non-Unicode font, display a (hopefully helpful) error message
once and then display the text anyway. ASCII parts will display
fine, non-ASCII parts will display with UTF-8 bytes interpreted as
if they were OEM characters.
Diffstat (limited to 'src/mongo/util/text.cpp')
-rw-r--r-- | src/mongo/util/text.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/util/text.cpp b/src/mongo/util/text.cpp index 152e76b20bc..9308c0a333a 100644 --- a/src/mongo/util/text.cpp +++ b/src/mongo/util/text.cpp @@ -21,6 +21,10 @@ #include "mongo/util/mongoutils/str.h" #include <boost/smart_ptr/scoped_array.hpp> +#ifdef _WIN32 +#include <io.h> +#endif + using namespace std; namespace mongo { @@ -248,6 +252,19 @@ namespace mongo { &numberOfCharactersWritten, NULL ); if ( 0 == success ) { + DWORD dosError = GetLastError(); + static bool errorMessageShown = false; + if ( ERROR_GEN_FAILURE == dosError ) { + if ( ! errorMessageShown ) { + std::cout << "\n---\nUnicode text could not be correctly displayed.\n" + "Please change your console font to a Unicode font " + "(e.g. Lucida Console).\n---\n" << std::endl; + errorMessageShown = true; + } + // we can't display the text properly using a raster font, + // but we can display the bits that will display ... + _write( 1, utf8String, utf8StringSize ); + } return false; } numberOfCharactersToWrite -= numberOfCharactersWritten; |