#include "terminal.h" #include #include #include "logging.h" Terminal::Config::Config() { } Terminal::Config::Config(Terminal::Config& original) { for (auto it = 0; itset_text(""); DEBUG("Terminal: Compile: running cmake command"); std::vector commands = config().compile_commands(); for (auto it = 0; it < commands.size(); ++it) { ExecuteCommand(commands.at(it), "r"); } PrintMessage("\n"); DEBUG("Terminal: Compile: compile done"); } void Terminal::Controller::Run(std::string executable) { INFO("Terminal: Run"); PrintMessage("juCi++ execute: " + executable + "\n"); DEBUG("Terminal: Compile: running run command: "); DEBUG_VAR(executable); ExecuteCommand("cd"+config().run_command() + "; ./"+executable, "r"); PrintMessage("\n"); } void Terminal::Controller::PrintMessage(std::string message){ INFO("Terminal: PrintMessage"); Terminal().get_buffer()-> insert(Terminal().get_buffer()-> end(),"> "+message); } bool Terminal::Controller::ExistInConsole(std::string string) { INFO("Terminal: ExistInConsole"); DEBUG("Terminal: PrintMessage: finding string in buffer"); double pos = Terminal().get_buffer()-> get_text().find(string); if (pos == std::string::npos) return false; return true; } void Terminal::Controller::ExecuteCommand(std::string command, std::string mode) { INFO("Terminal: ExecuteCommand"); command = folder_command_+command; DEBUG("Terminal: PrintMessage: Running command"); FILE* p = NULL; p = popen(command.c_str(), mode.c_str()); std::cout << "KJØRTE FINT!" << std::endl; if (p == NULL) { PrintMessage("juCi++ ERROR: Failed to run command" + command + "\n"); }else { std::cout << "SKRIVER UT KOMMANDO RESULAT" << std::endl; char buffer[1028]; while (fgets(buffer, 1028, p) != NULL) { PrintMessage(buffer); } pclose(p); } }