Browse Source

Added possibility to label run commands in the commands.json

pipelines/1486128344
eidheim 2 years ago
parent
commit
2bff28a844
  1. 7
      src/commands.cpp
  2. 1
      src/commands.hpp
  3. 26
      src/window.cpp

7
src/commands.cpp

@ -20,7 +20,9 @@ void Commands::load() {
"run": "echo <path_match> && echo <working_directory>", "run": "echo <path_match> && echo <working_directory>",
"debug_comment": "Whether or not this command should run through debugger", "debug_comment": "Whether or not this command should run through debugger",
"debug": false, "debug": false,
"debug_remote_host": "" "debug_remote_host": "",
"label_comment": "Output to the terminal instead of the run command",
"label": ""
} }
] ]
)"); )");
@ -43,7 +45,8 @@ void Commands::load() {
regex = std::regex(path, std::regex::optimize); regex = std::regex(path, std::regex::optimize);
commands.emplace_back(Command{key, modifier, std::move(regex), commands.emplace_back(Command{key, modifier, std::move(regex),
command.string_or("compile", ""), command.string("run"), command.string_or("compile", ""), command.string("run"),
command.boolean_or("debug", false), command.string_or("debug_remote_host", "")}); command.boolean_or("debug", false), command.string_or("debug_remote_host", ""),
command.string_or("label", "")});
} }
} }
catch(const std::exception &e) { catch(const std::exception &e) {

1
src/commands.hpp

@ -17,6 +17,7 @@ public:
std::string run; std::string run;
bool debug; bool debug;
std::string debug_remote_host; std::string debug_remote_host;
std::string label;
}; };
static Commands &get() { static Commands &get() {

26
src/window.cpp

@ -1942,6 +1942,14 @@ bool Window::on_key_press_event(GdkEventKey *event) {
auto run = command.run; auto run = command.run;
boost::replace_all(run, "<path_match>", filesystem::escape_argument(path.string())); boost::replace_all(run, "<path_match>", filesystem::escape_argument(path.string()));
boost::replace_all(run, "<working_directory>", filesystem::escape_argument(run_path.string())); boost::replace_all(run, "<working_directory>", filesystem::escape_argument(run_path.string()));
std::string label;
if(!command.label.empty()) {
label = command.label;
boost::replace_all(label, "<path_match>", filesystem::escape_argument(path.string()));
boost::replace_all(label, "<working_directory>", filesystem::escape_argument(run_path.string()));
}
else
label = run;
if(!compile.empty() || command.debug) { if(!compile.empty() || command.debug) {
if(Project::debugging && command.debug) // Possibly continue current debugging if(Project::debugging && command.debug) // Possibly continue current debugging
@ -1967,19 +1975,19 @@ bool Window::on_key_press_event(GdkEventKey *event) {
if(!command.debug) { if(!command.debug) {
Project::compiling = true; Project::compiling = true;
Terminal::get().print("\e[2mCompiling and running: " + run + "\e[m\n"); Terminal::get().print("\e[2mCompiling and running: " + label + "\e[m\n");
Terminal::get().async_process(compile, run_path, [run, run_path](int exit_status) { Terminal::get().async_process(compile, run_path, [run, run_path, label](int exit_status) {
Project::compiling = false; Project::compiling = false;
if(exit_status == 0) { if(exit_status == 0) {
Terminal::get().async_process(run, run_path, [run](int exit_status) { Terminal::get().async_process(run, run_path, [label](int exit_status) {
Terminal::get().print("\e[2m" + run + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); Terminal::get().print("\e[2m" + label + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n");
}); });
} }
}); });
} }
else { // Debug else { // Debug
Project::debugging = true; Project::debugging = true;
Terminal::get().print("\e[2mCompiling and debugging: " + run + "\e[m\n"); Terminal::get().print("\e[2mCompiling and debugging: " + label + "\e[m\n");
Terminal::get().async_process(compile, run_path, [project = project->shared_from_this(), run, run_path, debug_remote_host = command.debug_remote_host](int exit_status) { Terminal::get().async_process(compile, run_path, [project = project->shared_from_this(), run, run_path, debug_remote_host = command.debug_remote_host](int exit_status) {
if(exit_status != EXIT_SUCCESS) if(exit_status != EXIT_SUCCESS)
Project::debugging = false; Project::debugging = false;
@ -1989,14 +1997,14 @@ bool Window::on_key_press_event(GdkEventKey *event) {
} }
} }
else if(!command.debug) { else if(!command.debug) {
Terminal::get().async_print("\e[2mRunning: " + run + "\e[m\n"); Terminal::get().async_print("\e[2mRunning: " + label + "\e[m\n");
Terminal::get().async_process(run, run_path, [run](int exit_status) { Terminal::get().async_process(run, run_path, [label](int exit_status) {
Terminal::get().print("\e[2m" + run + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); Terminal::get().print("\e[2m" + label + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n");
}); });
} }
else { // Debug else { // Debug
Project::debugging = true; Project::debugging = true;
Terminal::get().async_print("\e[2mDebugging: " + run + "\e[m\n"); Terminal::get().async_print("\e[2mDebugging: " + label + "\e[m\n");
project->debug_start(run, run_path, command.debug_remote_host); project->debug_start(run, run_path, command.debug_remote_host);
} }
return true; return true;

Loading…
Cancel
Save