diff options
Diffstat (limited to 'WinPort/src/APIConsole.cpp')
-rw-r--r-- | WinPort/src/APIConsole.cpp | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/WinPort/src/APIConsole.cpp b/WinPort/src/APIConsole.cpp index cb46698c..6bc7c1bd 100644 --- a/WinPort/src/APIConsole.cpp +++ b/WinPort/src/APIConsole.cpp @@ -1,4 +1,6 @@ #include <mutex> +#include <map> +#include <vector> #include "WinPort.h" #include "Backend.h" @@ -137,9 +139,9 @@ extern "C" { } - WINPORT_DECL(SetConsoleTextAttribute,BOOL,(HANDLE hConsoleOutput, WORD wAttributes)) + WINPORT_DECL(SetConsoleTextAttribute,BOOL,(HANDLE hConsoleOutput, DWORD64 qAttributes)) { - g_winport_con_out->SetAttributes(wAttributes); + g_winport_con_out->SetAttributes(qAttributes); return TRUE; } @@ -167,9 +169,9 @@ extern "C" { return TRUE; } - WINPORT_DECL(FillConsoleOutputAttribute, BOOL, (HANDLE hConsoleOutput, WORD wAttribute, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten)) + WINPORT_DECL(FillConsoleOutputAttribute, BOOL, (HANDLE hConsoleOutput, DWORD64 qAttributes, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten)) { - *lpNumberOfAttrsWritten = g_winport_con_out->FillAttributeAt(wAttribute, nLength, dwWriteCoord); + *lpNumberOfAttrsWritten = g_winport_con_out->FillAttributeAt(qAttributes, nLength, dwWriteCoord); return TRUE; } @@ -345,4 +347,69 @@ extern "C" { { return g_winport_con_out->SetFKeyTitles(titles) ? TRUE : FALSE; } + + WINPORT_DECL(GetConsoleColorPalette,BYTE,()) + { + return g_winport_con_out->GetColorPalette(); + } + + static struct { + struct Cmp + { + bool operator()(const WCHAR *a, const WCHAR *b) const { return wcscmp(a, b) < 0; } + }; + std::mutex mtx; + std::vector<WCHAR *> id2str; + std::map<const WCHAR *, COMP_CHAR, Cmp> str2id; + } s_composite_chars; + + WINPORT_DECL(CompositeCharRegister,COMP_CHAR,(const WCHAR *lpSequence)) + { + if (!lpSequence[0]) { + return 0; + } + if (!lpSequence[1]) { + return lpSequence[0]; + } + + std::lock_guard<std::mutex> lock(s_composite_chars.mtx); + auto it = s_composite_chars.str2id.find(lpSequence); + if (it != s_composite_chars.str2id.end()) { + return it->second | COMPOSITE_CHAR_MARK; + } + wchar_t *wd = wcsdup(lpSequence); + try { + if (!wd) + throw std::logic_error("wcsdup failed"); + + const COMP_CHAR id = COMP_CHAR(s_composite_chars.id2str.size()); + s_composite_chars.id2str.emplace_back(wd); + s_composite_chars.str2id.emplace(wd, id); + return id | COMPOSITE_CHAR_MARK; + + } catch (std::exception &e) { + fprintf(stderr, "%s: %s for '%ls'\n", __FUNCTION__, e.what(), lpSequence); + free(wd); + } + return 0; + } + + WINPORT_DECL(CompositeCharLookup,const WCHAR *,(COMP_CHAR CompositeChar)) + { + if ((CompositeChar & COMPOSITE_CHAR_MARK) == 0) { + fprintf(stderr, "%s: invoked for not composite-char 0x%llx\n", + __FUNCTION__, (unsigned long long)CompositeChar); + return L"\u2022"; + } + + const COMP_CHAR id = CompositeChar & (~COMPOSITE_CHAR_MARK); + + std::lock_guard<std::mutex> lock(s_composite_chars.mtx); + if (id >= (COMP_CHAR)s_composite_chars.id2str.size()) { + fprintf(stderr, "%s: out of range composite-char 0x%llx\n", + __FUNCTION__, (unsigned long long)CompositeChar); + return L"\u2022"; + } + return s_composite_chars.id2str[id]; + } } |