feat: executing commands from stdin

This commit is contained in:
MihailRis 2026-02-11 15:26:53 +03:00
parent fcbbf4814a
commit 41ba0b8e65
3 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,34 @@
#include "StdinReader.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();
}

View file

@ -0,0 +1,7 @@
#pragma once
namespace cmd {
class CommandsInterpreter;
}
void start_stdin_reader(cmd::CommandsInterpreter& interpreter);

View file

@ -15,6 +15,7 @@
#include "devtools/DebuggingServer.hpp"
#include "devtools/Editor.hpp"
#include "devtools/Project.hpp"
#include "devtools/StdinReader.hpp"
#include "EnginePaths.hpp"
#include "frontend/locale.hpp"
#include "frontend/menu.hpp"
@ -191,6 +192,8 @@ void Engine::initialize(CoreParameters coreParameters) {
if (!params.headless) {
project->loadProjectClientScript();
}
start_stdin_reader(*cmd);
}
void Engine::loadSettings() {