Implement unicode on console, move readline into driver

This commit is contained in:
2023-05-18 17:14:55 -04:00
parent 2b03ca2eb6
commit fd137e8e74
12 changed files with 371 additions and 162 deletions

View File

@@ -2,6 +2,7 @@
#include "drvutil.hpp"
#include "sslutil.hpp"
#include "readline.hpp"
#include "../core/enginewrapper.hpp"
#include <iostream>
@@ -217,12 +218,21 @@ static int socket_poll(struct pollfd *pollvec, int pollcount, int mstimeout, std
return 0;
}
static int console_write(const char *bytes, int nbytes) {
return write(1, bytes, nbytes);
// Write unicode onto the console.
static void console_write(const CodepointString &cps) {
std::string utf8 = ReadlineDevice::to_utf8(cps);
write(1, utf8.c_str(), utf8.size());
}
static int console_read(char *bytes, int nbytes) {
return read(0, bytes, nbytes);
static CodepointString console_read() {
CodepointString result;
char buffer[512];
int nread = read(0, buffer, 512);
if (nread > 0) {
std::string_view s(buffer, nread);
result = ReadlineDevice::from_utf8(s, nullptr);
}
return result;
}
static void call_init_engine_wrapper(const std::filesystem::path &luprexroot, EngineWrapper *w) {