On server, channel dprint through the readline-device. Also some refactors and quality improvements.
This commit is contained in:
@@ -11,6 +11,11 @@
|
||||
#define POLLVEC_SIZE (DRV_MAX_CHAN + 1)
|
||||
#define MAX_BIO_BUFFER (128 * 1024)
|
||||
|
||||
static ReadlineDevice readline_device;
|
||||
|
||||
static void dprint_callback(const char *oneline, size_t size) {
|
||||
readline_device.printline(std::string_view(oneline, size));
|
||||
}
|
||||
|
||||
static void if_error_print_and_exit(const std::string_view str) {
|
||||
if (!str.empty()) {
|
||||
@@ -19,16 +24,6 @@ static void if_error_print_and_exit(const std::string_view str) {
|
||||
}
|
||||
}
|
||||
|
||||
// DPrints are currently not going through the readline device.
|
||||
// doing so would not currently be thread-safe. Do I care about
|
||||
// that? I'm not sure.
|
||||
static void dprint_callback(const char *oneline, size_t size) {
|
||||
fwrite("**", 1, 2, stderr);
|
||||
fwrite(oneline, 1, size, stderr);
|
||||
fwrite("\n", 1, 1, stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
inline bool file_exists(const std::filesystem::path &name) {
|
||||
std::ifstream f(name);
|
||||
return f.good();
|
||||
@@ -96,7 +91,6 @@ class Driver {
|
||||
bool read_console_recently_;
|
||||
std::unique_ptr<struct pollfd[]> pollvec_;
|
||||
std::unique_ptr<char[]> chbuf_;
|
||||
ReadlineDevice readline_device_;
|
||||
std::string console_command_;
|
||||
|
||||
sslutil::UniqueCTX ssl_server_ctx_;
|
||||
@@ -209,7 +203,7 @@ class Driver {
|
||||
engw.play_access(&engw, AccessKind::CHANNEL_PRINTS, 0, 0, "", &ndata, &data);
|
||||
if (ndata > 0) {
|
||||
if (ndata > DRV_SHORTSTRING_SIZE) ndata = DRV_SHORTSTRING_SIZE;
|
||||
readline_device_.printline(std::string_view(data, ndata));
|
||||
readline_device.printline(std::string_view(data, ndata));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,7 +218,7 @@ class Driver {
|
||||
inject_lua_source();
|
||||
}
|
||||
else {
|
||||
readline_device_.printline(parser.Error());
|
||||
readline_device.printline(parser.Error());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,24 +243,24 @@ class Driver {
|
||||
engw.play_access(&engw, AccessKind::INVOKE_LUA_EXPR,
|
||||
0, cmd.size(), cmd.c_str(), nullptr, nullptr);
|
||||
} else {
|
||||
readline_device_.printline(message);
|
||||
readline_device.printline(message);
|
||||
}
|
||||
|
||||
if (console_command_.empty()) {
|
||||
readline_device_.set_prompt(">");
|
||||
readline_device.set_prompt(">");
|
||||
} else {
|
||||
readline_device_.set_prompt(">>");
|
||||
readline_device.set_prompt(">>");
|
||||
}
|
||||
}
|
||||
|
||||
void handle_console_input() {
|
||||
read_console_recently_ = false;
|
||||
while (true) {
|
||||
std::u32string cps = console_read();
|
||||
std::u32string cps = drvutil::console_read();
|
||||
if (cps.size() == 0) break;
|
||||
read_console_recently_ = true;
|
||||
for (char32_t c : cps) {
|
||||
std::string line = readline_device_.putcode(c);
|
||||
std::string line = readline_device.putcode(c);
|
||||
if (!line.empty()) {
|
||||
add_console_command(line);
|
||||
}
|
||||
@@ -631,8 +625,7 @@ class Driver {
|
||||
|
||||
int drive(int argc, char *argv[]) {
|
||||
// Set up the console readline device.
|
||||
readline_device_.set_print_callback(console_write);
|
||||
readline_device_.set_prompt(">");
|
||||
readline_device.set_prompt(">");
|
||||
console_command_.clear();
|
||||
|
||||
// Remove the program name from argv.
|
||||
|
||||
Reference in New Issue
Block a user