mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
rename
This commit is contained in:
parent
48f5de8adf
commit
85c085d7c3
4 changed files with 11 additions and 9 deletions
40
src/devtools/stdin_cmd_reader.cpp
Normal file
40
src/devtools/stdin_cmd_reader.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "stdin_cmd_reader.hpp"
|
||||
|
||||
#include "engine/Engine.hpp"
|
||||
#include "logic/CommandsInterpreter.hpp"
|
||||
#include "coders/json.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
static debug::Logger logger("stdin-reader");
|
||||
|
||||
static std::thread reader_thread;
|
||||
|
||||
void cmd::start_stdin_cmd_reader(Engine& engine) {
|
||||
reader_thread = std::thread([&engine]() {
|
||||
auto& interpreter = engine.getCmd();
|
||||
logger.info() << "reader thread started";
|
||||
|
||||
std::string line;
|
||||
while (std::getline(std::cin, line)) {
|
||||
if (line.empty()) {
|
||||
continue;
|
||||
}
|
||||
engine.postRunnable([line, &interpreter] () {
|
||||
try {
|
||||
auto result = interpreter.execute(line);
|
||||
if (result.isString()) {
|
||||
logger.info() << result.asString();
|
||||
} else {
|
||||
logger.info() << json::stringify(result, true);
|
||||
}
|
||||
} catch (const std::exception& err) {
|
||||
logger.error() << err.what();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
reader_thread.detach();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue