console encoding patch
This commit is contained in:
@@ -323,12 +323,18 @@ void PIKbdListener::readKeyboard() {
|
|||||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||||
PICout(0) << PICoutManipulators::Hex << int(((uchar * )&rc)[i]) << ' ';
|
PICout(0) << PICoutManipulators::Hex << int(((uchar * )&rc)[i]) << ' ';
|
||||||
PICout(0) << "\n";
|
PICout(0) << "\n";
|
||||||
|
std::cout << PRIVATE->ret << " chars ";
|
||||||
for (int i = 0; i < PRIVATE->ret; ++i)
|
for (int i = 0; i < PRIVATE->ret; ++i)
|
||||||
cout << "'" << (char)(rc[i]) << "' ";
|
std::cout << "'" << (char)(rc[i]) << "' " << (int)(uchar)(rc[i]);
|
||||||
cout << endl;*/
|
std::cout << std::endl;*/
|
||||||
if (rc[0] == 0) {piMSleep(10); return;}
|
if (rc[0] == 0) {piMSleep(10); return;}
|
||||||
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {piMSleep(10); return;}
|
if (PRIVATE->ret < 0 || PRIVATE->ret > 7) {piMSleep(10); return;}
|
||||||
if (PRIVATE->ret == 1) ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
if (PRIVATE->ret == 1) {
|
||||||
|
if (rc[0] == 8)
|
||||||
|
ke.key = Backspace;
|
||||||
|
else
|
||||||
|
ke.key = PIChar::fromConsole(rc[0]).unicode16Code();
|
||||||
|
}
|
||||||
int mod(0);
|
int mod(0);
|
||||||
// 2 - shift 1
|
// 2 - shift 1
|
||||||
// 3 - alt 2
|
// 3 - alt 2
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
#include "pistack.h"
|
#include "pistack.h"
|
||||||
#include "piobject.h"
|
#include "piobject.h"
|
||||||
#include "pistring_std.h"
|
#include "pistring_std.h"
|
||||||
|
#ifdef HAS_LOCALE
|
||||||
|
# include <locale>
|
||||||
|
# include <codecvt>
|
||||||
|
#endif
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <wingdi.h>
|
# include <wingdi.h>
|
||||||
@@ -147,6 +151,9 @@ 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
|
||||||
@@ -539,8 +546,13 @@ 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)) {
|
||||||
|
#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());
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,12 +152,15 @@ PIInit::PIInit() {
|
|||||||
}
|
}
|
||||||
# endif //WINDOWS
|
# endif //WINDOWS
|
||||||
# ifdef HAS_LOCALE
|
# ifdef HAS_LOCALE
|
||||||
//cout << "has locale" << endl;
|
//std::cout << "has locale" << std::endl;
|
||||||
if (currentLocale_t != 0) {
|
if (currentLocale_t != 0) {
|
||||||
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, ""), 0);
|
||||||
|
//std::ios_base::sync_with_stdio(false);
|
||||||
|
//std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
||||||
|
//std::wcout.imbue(utf8);
|
||||||
# else //HAS_LOCALE
|
# else //HAS_LOCALE
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
@@ -212,9 +215,6 @@ PIInit::PIInit() {
|
|||||||
if (gethostname(cbuff, 1023) == 0) {
|
if (gethostname(cbuff, 1023) == 0) {
|
||||||
sinfo->hostname = cbuff;
|
sinfo->hostname = cbuff;
|
||||||
}
|
}
|
||||||
// std::ios_base::sync_with_stdio(false);
|
|
||||||
// std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
|
|
||||||
// std::wcout.imbue(utf8);
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
|
|||||||
22
main.cpp
22
main.cpp
@@ -4,8 +4,30 @@ static const char * smallstr = "abcdef";
|
|||||||
|
|
||||||
static const char * bigstr = "zsxdcgfhvbncjdbasljcvavcjadnwnxudvbabdhjlavudvdaljsvclavjlasdhvcjhldsavhjldasvfjlhsavdjhavdjhvfjhldasvfjlasvfhjldasvfhjasvfdjdasfhvjldasvhfjlasvfhjlahsvdfhjfvfvdjalsvfjlhasdvfdjsalvfhhjldasvfdjhaldsvfhjdvsfjhlavfjhlavfladlsvfjlasdvfdhjlavfhjldasvfhjlavfhjldvfhjlalsdvfjlhvasfhjlvchjlavchjladvchjldladvschjlladscvjlhdcahjchjllcahjllvcdjladsvhldbcljadsbcjdhlsachjlvdsa hjlcldajc hljdascbhaldb cldhashd l cajlhs chdsbfhlbfdasdffadsfjkbfkjldsabflhbcldhsbhclabchljadsbchldahsbcladsbhclhabhasbclasbdhl";
|
static const char * bigstr = "zsxdcgfhvbncjdbasljcvavcjadnwnxudvbabdhjlavudvdaljsvclavjlasdhvcjhldsavhjldasvfjlhsavdjhavdjhvfjhldasvfjlasvfhjldasvfhjasvfdjdasfhvjldasvhfjlasvfhjlahsvdfhjfvfvdjalsvfjlhasdvfdjsalvfhhjldasvfdjhaldsvfhjdvsfjhlavfjhlavfladlsvfjlasdvfdhjlavfhjldasvfhjlavfhjldvfhjlalsdvfjlhvasfhjlvchjlavchjladvchjldladvschjlladscvjlhdcahjchjllcahjllvcdjladsvhldbcljadsbcjdhlsachjlvdsa hjlcldajc hljdascbhaldb cldhashd l cajlhs chdsbfhlbfdasdffadsfjkbfkjldsabflhbcldhsbhclabchljadsbchldahsbcladsbhclhabhasbclasbdhl";
|
||||||
|
|
||||||
|
PIKbdListener kbd;
|
||||||
|
#include <iostream>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
|
auto rstr = PIString::fromUTF8("ascii русский!");
|
||||||
|
/*for (PIChar c: rstr)
|
||||||
|
std::wcout << c.toWChar();
|
||||||
|
std::wcout << std::endl;*/
|
||||||
|
piCout << rstr;
|
||||||
|
|
||||||
|
/*char rs[] = "й";
|
||||||
|
piCout << PIString(PIChar::fromUTF8(rs));
|
||||||
|
std::cout << sizeof(rs) << " chars ";
|
||||||
|
for (int i = 0; i < sizeof(rs); ++i)
|
||||||
|
std::cout << "'" << (char)(rs[i]) << "' " << (int)(uchar)(rs[i]);
|
||||||
|
std::cout << std::endl;
|
||||||
|
CONNECTL(&kbd, keyPressed, ([](PIKbdListener::KeyEvent k, void*){
|
||||||
|
;
|
||||||
|
piCout << k.key << PIChar((ushort)k.key);
|
||||||
|
}));
|
||||||
|
kbd.start();
|
||||||
|
WAIT_FOR_EXIT;*/
|
||||||
|
return 0;
|
||||||
static const int cc = 1000000;
|
static const int cc = 1000000;
|
||||||
PITimeMeasurer tm;
|
PITimeMeasurer tm;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user