On server, channel dprint through the readline-device. Also some refactors and quality improvements.

This commit is contained in:
2026-01-09 14:28:58 -05:00
parent 1087d18a2e
commit 7fa3f39d72
15 changed files with 258 additions and 253 deletions

View File

@@ -2,7 +2,6 @@
#define _WIN32_WINNT 0x0600
#include "drvutil.hpp"
#include "osdrvutil.hpp"
#include "sslutil.hpp"
#include "readline.hpp"
#include "../core/enginewrapper.hpp"
@@ -232,52 +231,6 @@ static void init_winsock() {
}
static void console_write(const std::u32string &cps) {
if (cps.size() == 0) return;
// Convert to wstring. Any character not representable as a single wchar_t
// is replaced with a box. It's not ideal, but it's pretty good.
std::wstring ws(cps.size(), 0);
for (int i = 0; i < int(cps.size()); i++) {
char32_t c = cps[i];
if (drvutil::is_single_wchar_t(c)) ws[i] = (wchar_t)c;
else ws[i] = 0x2610;
}
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
assert(hstdout != INVALID_HANDLE_VALUE);
DWORD nwrote;
std::wstring_view v(ws);
while (v.size() > 0) {
int nwrite = v.size();
if (nwrite > 10000) nwrite = 10000;
assert(WriteConsoleW(hstdout, v.data(), nwrite, &nwrote, nullptr));
assert(nwrote > 0);
v.remove_prefix(nwrote);
}
}
static std::u32string console_read() {
HANDLE hstdin = GetStdHandle(STD_INPUT_HANDLE);
assert(hstdin != INVALID_HANDLE_VALUE);
INPUT_RECORD inrecords[512];
DWORD nread, nevents;
if (GetNumberOfConsoleInputEvents(hstdin, &nevents)) {
if (int(nevents) > 0) {
if (int(nevents) > 512) nevents = 512;
ReadConsoleInputW(hstdin, inrecords, nevents, &nread);
std::u32string result(nread, 0);
int len = 0;
for (int i = 0; i < int(nread); i++) {
const INPUT_RECORD &inr = inrecords[i];
if (inr.EventType != KEY_EVENT) continue;
const KEY_EVENT_RECORD &key = inr.Event.KeyEvent;
if (!key.bKeyDown) continue;
result[len++] = key.uChar.UnicodeChar;
}
return result.substr(0, len);
}
}
return std::u32string();
}
static void ssl_load_certificate_authorities(SSL_CTX *ctx) {
HCERTSTORE hStore = CertOpenSystemStoreW(0, L"ROOT");