mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 22:41:49 +00:00
feat: executing commands from stdin
This commit is contained in:
parent
fcbbf4814a
commit
41ba0b8e65
3 changed files with 44 additions and 0 deletions
34
src/devtools/StdinReader.cpp
Normal file
34
src/devtools/StdinReader.cpp
Normal 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();
|
||||||
|
}
|
||||||
7
src/devtools/StdinReader.hpp
Normal file
7
src/devtools/StdinReader.hpp
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace cmd {
|
||||||
|
class CommandsInterpreter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start_stdin_reader(cmd::CommandsInterpreter& interpreter);
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "devtools/DebuggingServer.hpp"
|
#include "devtools/DebuggingServer.hpp"
|
||||||
#include "devtools/Editor.hpp"
|
#include "devtools/Editor.hpp"
|
||||||
#include "devtools/Project.hpp"
|
#include "devtools/Project.hpp"
|
||||||
|
#include "devtools/StdinReader.hpp"
|
||||||
#include "EnginePaths.hpp"
|
#include "EnginePaths.hpp"
|
||||||
#include "frontend/locale.hpp"
|
#include "frontend/locale.hpp"
|
||||||
#include "frontend/menu.hpp"
|
#include "frontend/menu.hpp"
|
||||||
|
|
@ -191,6 +192,8 @@ void Engine::initialize(CoreParameters coreParameters) {
|
||||||
if (!params.headless) {
|
if (!params.headless) {
|
||||||
project->loadProjectClientScript();
|
project->loadProjectClientScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start_stdin_reader(*cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadSettings() {
|
void Engine::loadSettings() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue