diff --git a/libs/console/piscreen.cpp b/libs/console/piscreen.cpp index 448f87b2..6ee52ebe 100644 --- a/libs/console/piscreen.cpp +++ b/libs/console/piscreen.cpp @@ -219,14 +219,15 @@ void PIScreen::SystemConsole::print() { } else { if (!s.isEmpty()) { moveTo(si, sj); - printf("%s", s.data()); + PICout::stdoutPIString(s); s.clear(); } } } if (!s.isEmpty()) { moveTo(si, sj); - printf("%s", s.data()); + PICout::stdoutPIString(s); + //printf("%s", s.data()); s.clear(); } } @@ -295,32 +296,32 @@ void PIScreen::SystemConsole::newLine() { } #else // WINDOWS PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) { - PIString ts("\e[0"); + PIString ts = PIStringAscii("\e[0"); switch (c.format.color_char) { - case Black: ts += ";30"; break; - case Red: ts += ";31"; break; - case Green: ts += ";32"; break; - case Blue: ts += ";34"; break; - case Cyan: ts += ";36"; break; - case Magenta: ts += ";35"; break; - case Yellow: ts += ";33"; break; - case White: ts += ";37"; break; + case Black: ts += PIStringAscii(";30"); break; + case Red: ts += PIStringAscii(";31"); break; + case Green: ts += PIStringAscii(";32"); break; + case Blue: ts += PIStringAscii(";34"); break; + case Cyan: ts += PIStringAscii(";36"); break; + case Magenta: ts += PIStringAscii(";35"); break; + case Yellow: ts += PIStringAscii(";33"); break; + case White: ts += PIStringAscii(";37"); break; } switch (c.format.color_back) { - case Black: ts += ";40"; break; - case Red: ts += ";41"; break; - case Green: ts += ";42"; break; - case Blue: ts += ";44"; break; - case Cyan: ts += ";46"; break; - case Magenta: ts += ";45"; break; - case Yellow: ts += ";43"; break; - case White: ts += ";47"; break; + case Black: ts += PIStringAscii(";40"); break; + case Red: ts += PIStringAscii(";41"); break; + case Green: ts += PIStringAscii(";42"); break; + case Blue: ts += PIStringAscii(";44"); break; + case Cyan: ts += PIStringAscii(";46"); break; + case Magenta: ts += PIStringAscii(";45"); break; + case Yellow: ts += PIStringAscii(";43"); break; + case White: ts += PIStringAscii(";47"); break; } - if ((c.format.flags & Bold) == Bold) ts += ";1"; - if ((c.format.flags & Underline) == Underline) ts += ";4"; - if ((c.format.flags & Blink) == Blink) ts += ";5"; - if ((c.format.flags & Inverse) == Inverse) ts += ";7"; - return ts + "m"; + if ((c.format.flags & Bold ) == Bold ) ts += PIStringAscii(";1"); + if ((c.format.flags & Underline) == Underline) ts += PIStringAscii(";4"); + if ((c.format.flags & Blink ) == Blink ) ts += PIStringAscii(";5"); + if ((c.format.flags & Inverse ) == Inverse ) ts += PIStringAscii(";7"); + return ts + 'm'; } #endif // WINDOWS diff --git a/libs/main/core/pichar.cpp b/libs/main/core/pichar.cpp index 38f826f8..9b0a7128 100644 --- a/libs/main/core/pichar.cpp +++ b/libs/main/core/pichar.cpp @@ -85,6 +85,7 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t wchar_t wc; ret = mbrtowc(&wc, c, size, &state); //printf("mbtowc = %d\n", ret); + //piCout << errorString(); if (ret < 1) return 0; return ushort(wc); # endif diff --git a/libs/main/core/picout.cpp b/libs/main/core/picout.cpp index b6d99526..bc40bad9 100644 --- a/libs/main/core/picout.cpp +++ b/libs/main/core/picout.cpp @@ -151,9 +151,6 @@ PRIVATE_DEFINITION_START(PICout) static WORD dattr; static DWORD smode; #endif -#ifdef HAS_LOCALE - std::wstring_convert, char16_t> utf8conv; -#endif PRIVATE_DEFINITION_END(PICout) #ifdef WINDOWS @@ -546,20 +543,24 @@ PICout & PICout::writePIString(const PIString & s) { if (buffer_) { buffer_->append(s); } else { - - if (PICout::isOutputDeviceActive(PICout::StdOut)) { -#ifdef HAS_LOCALE - std::cout << PRIVATE->utf8conv.to_bytes((char16_t*)&(const_cast(s).front()), (char16_t*)&(const_cast(s).front()) + s.size()); -#else - for (PIChar c: s) std::wcout.put(c.toWChar()); -#endif - } + if (PICout::isOutputDeviceActive(PICout::StdOut)) + stdoutPIString(s); if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s); } return *this; } +void PICout::stdoutPIString(const PIString & s) { +#ifdef HAS_LOCALE + std::wstring_convert, char16_t> utf8conv; + std::cout << utf8conv.to_bytes((char16_t*)&(const_cast(s).front()), (char16_t*)&(const_cast(s).front()) + s.size()); +#else + for (PIChar c: s) std::wcout.put(c.toWChar()); +#endif +} + + void PICout::init() { #ifdef WINDOWS if (__Private__::hOut == 0) { diff --git a/libs/main/core/picout.h b/libs/main/core/picout.h index 68a584a4..94c8c13b 100644 --- a/libs/main/core/picout.h +++ b/libs/main/core/picout.h @@ -291,6 +291,10 @@ public: //! \~russian Пишет сырой \a PIString PICout & writePIString(const PIString & s); + //! \~english Output \a PIString to stdout + //! \~russian Вывод \a PIString в stdout + static void stdoutPIString(const PIString & s); + //! \~english Set output device to \a PICout::Buffer and if "clear" clear it //! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его static bool setBufferActive(bool on, bool clear = false); diff --git a/libs/main/core/piinit.cpp b/libs/main/core/piinit.cpp index 1e04d086..c8354cfb 100644 --- a/libs/main/core/piinit.cpp +++ b/libs/main/core/piinit.cpp @@ -157,7 +157,8 @@ PIInit::PIInit() { freelocale(currentLocale_t); currentLocale_t = 0; } - currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0); + currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, "C"), 0); + setlocale(LC_CTYPE, "en_US.UTF-8"); //std::ios_base::sync_with_stdio(false); //std::locale utf8( std::locale(), new std::codecvt_utf8 ); //std::wcout.imbue(utf8); diff --git a/main.cpp b/main.cpp index c854f400..d04be35c 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,8 @@ int main(int argc, char * argv[]) { /*for (PIChar c: rstr) std::wcout << c.toWChar(); std::wcout << std::endl;*/ + piCout << PIChar::fromUTF8("│"); + piCout << PICoutManipulators::Hex << (int)PIChar::fromUTF8("│").toWChar(); piCout << rstr; /*char rs[] = "й";