This commit is contained in:
MihailRis 2026-02-11 15:57:38 +03:00
parent 41ba0b8e65
commit 7c0772b5b6
3 changed files with 2 additions and 2 deletions

View file

@ -0,0 +1,34 @@
#include "stdin_reader.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 start_stdin_reader(cmd::CommandsInterpreter& interpreter) {
reader_thread = std::thread([&interpreter]() {
std::string line;
while (std::getline(std::cin, line)) {
if (line.empty()) {
continue;
}
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();
}