locale changes, piscreen

This commit is contained in:
2022-04-27 12:41:38 +03:00
parent 2f4e73ef13
commit c1c47b4869
6 changed files with 46 additions and 36 deletions

View File

@@ -219,14 +219,15 @@ void PIScreen::SystemConsole::print() {
} else { } else {
if (!s.isEmpty()) { if (!s.isEmpty()) {
moveTo(si, sj); moveTo(si, sj);
printf("%s", s.data()); PICout::stdoutPIString(s);
s.clear(); s.clear();
} }
} }
} }
if (!s.isEmpty()) { if (!s.isEmpty()) {
moveTo(si, sj); moveTo(si, sj);
printf("%s", s.data()); PICout::stdoutPIString(s);
//printf("%s", s.data());
s.clear(); s.clear();
} }
} }
@@ -295,32 +296,32 @@ void PIScreen::SystemConsole::newLine() {
} }
#else // WINDOWS #else // WINDOWS
PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) { PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) {
PIString ts("\e[0"); PIString ts = PIStringAscii("\e[0");
switch (c.format.color_char) { switch (c.format.color_char) {
case Black: ts += ";30"; break; case Black: ts += PIStringAscii(";30"); break;
case Red: ts += ";31"; break; case Red: ts += PIStringAscii(";31"); break;
case Green: ts += ";32"; break; case Green: ts += PIStringAscii(";32"); break;
case Blue: ts += ";34"; break; case Blue: ts += PIStringAscii(";34"); break;
case Cyan: ts += ";36"; break; case Cyan: ts += PIStringAscii(";36"); break;
case Magenta: ts += ";35"; break; case Magenta: ts += PIStringAscii(";35"); break;
case Yellow: ts += ";33"; break; case Yellow: ts += PIStringAscii(";33"); break;
case White: ts += ";37"; break; case White: ts += PIStringAscii(";37"); break;
} }
switch (c.format.color_back) { switch (c.format.color_back) {
case Black: ts += ";40"; break; case Black: ts += PIStringAscii(";40"); break;
case Red: ts += ";41"; break; case Red: ts += PIStringAscii(";41"); break;
case Green: ts += ";42"; break; case Green: ts += PIStringAscii(";42"); break;
case Blue: ts += ";44"; break; case Blue: ts += PIStringAscii(";44"); break;
case Cyan: ts += ";46"; break; case Cyan: ts += PIStringAscii(";46"); break;
case Magenta: ts += ";45"; break; case Magenta: ts += PIStringAscii(";45"); break;
case Yellow: ts += ";43"; break; case Yellow: ts += PIStringAscii(";43"); break;
case White: ts += ";47"; break; case White: ts += PIStringAscii(";47"); break;
} }
if ((c.format.flags & Bold) == Bold) ts += ";1"; if ((c.format.flags & Bold ) == Bold ) ts += PIStringAscii(";1");
if ((c.format.flags & Underline) == Underline) ts += ";4"; if ((c.format.flags & Underline) == Underline) ts += PIStringAscii(";4");
if ((c.format.flags & Blink) == Blink) ts += ";5"; if ((c.format.flags & Blink ) == Blink ) ts += PIStringAscii(";5");
if ((c.format.flags & Inverse) == Inverse) ts += ";7"; if ((c.format.flags & Inverse ) == Inverse ) ts += PIStringAscii(";7");
return ts + "m"; return ts + 'm';
} }
#endif // WINDOWS #endif // WINDOWS

View File

@@ -85,6 +85,7 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t
wchar_t wc; wchar_t wc;
ret = mbrtowc(&wc, c, size, &state); ret = mbrtowc(&wc, c, size, &state);
//printf("mbtowc = %d\n", ret); //printf("mbtowc = %d\n", ret);
//piCout << errorString();
if (ret < 1) return 0; if (ret < 1) return 0;
return ushort(wc); return ushort(wc);
# endif # endif

View File

@@ -151,9 +151,6 @@ PRIVATE_DEFINITION_START(PICout)
static WORD dattr; static WORD dattr;
static DWORD smode; static DWORD smode;
#endif #endif
#ifdef HAS_LOCALE
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
#endif
PRIVATE_DEFINITION_END(PICout) PRIVATE_DEFINITION_END(PICout)
#ifdef WINDOWS #ifdef WINDOWS
@@ -546,20 +543,24 @@ PICout & PICout::writePIString(const PIString & s) {
if (buffer_) { if (buffer_) {
buffer_->append(s); buffer_->append(s);
} else { } else {
if (PICout::isOutputDeviceActive(PICout::StdOut))
if (PICout::isOutputDeviceActive(PICout::StdOut)) { stdoutPIString(s);
#ifdef HAS_LOCALE
std::cout << PRIVATE->utf8conv.to_bytes((char16_t*)&(const_cast<PIString&>(s).front()), (char16_t*)&(const_cast<PIString&>(s).front()) + s.size());
#else
for (PIChar c: s) std::wcout.put(c.toWChar());
#endif
}
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s); if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__().append(s);
} }
return *this; return *this;
} }
void PICout::stdoutPIString(const PIString & s) {
#ifdef HAS_LOCALE
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
std::cout << utf8conv.to_bytes((char16_t*)&(const_cast<PIString&>(s).front()), (char16_t*)&(const_cast<PIString&>(s).front()) + s.size());
#else
for (PIChar c: s) std::wcout.put(c.toWChar());
#endif
}
void PICout::init() { void PICout::init() {
#ifdef WINDOWS #ifdef WINDOWS
if (__Private__::hOut == 0) { if (__Private__::hOut == 0) {

View File

@@ -291,6 +291,10 @@ public:
//! \~russian Пишет сырой \a PIString //! \~russian Пишет сырой \a PIString
PICout & writePIString(const PIString & s); 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 //! \~english Set output device to \a PICout::Buffer and if "clear" clear it
//! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его //! \~russian Устанавливает устройство вывода на \a PICout::Buffer и если "clear" то очищает его
static bool setBufferActive(bool on, bool clear = false); static bool setBufferActive(bool on, bool clear = false);

View File

@@ -157,7 +157,8 @@ PIInit::PIInit() {
freelocale(currentLocale_t); freelocale(currentLocale_t);
currentLocale_t = 0; 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::ios_base::sync_with_stdio(false);
//std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> ); //std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
//std::wcout.imbue(utf8); //std::wcout.imbue(utf8);

View File

@@ -13,6 +13,8 @@ int main(int argc, char * argv[]) {
/*for (PIChar c: rstr) /*for (PIChar c: rstr)
std::wcout << c.toWChar(); std::wcout << c.toWChar();
std::wcout << std::endl;*/ std::wcout << std::endl;*/
piCout << PIChar::fromUTF8("");
piCout << PICoutManipulators::Hex << (int)PIChar::fromUTF8("").toWChar();
piCout << rstr; piCout << rstr;
/*char rs[] = "й"; /*char rs[] = "й";