2017-01-29 00:03:23 +00:00
|
|
|
/*
|
|
|
|
4coder_system_command.cpp - Commands for executing arbitrary system command line instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
CUSTOM_COMMAND_SIG(execute_previous_cli)
|
|
|
|
CUSTOM_DOC("If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.")
|
|
|
|
{
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 out_buffer = SCu8(out_buffer_space);
|
|
|
|
String_Const_u8 cmd = SCu8(command_space);
|
|
|
|
String_Const_u8 hot_directory = SCu8(hot_directory_space);
|
2017-07-17 21:13:57 +00:00
|
|
|
|
|
|
|
if (out_buffer.size > 0 && cmd.size > 0 && hot_directory.size > 0){
|
2019-10-18 02:54:02 +00:00
|
|
|
View_ID view = get_active_view(app, Access_Always);
|
2019-06-01 23:58:28 +00:00
|
|
|
Buffer_Identifier id = buffer_identifier(out_buffer);
|
|
|
|
exec_system_command(app, view, id, hot_directory, cmd, CLI_OverlapWithConflict|CLI_CursorAtEnd|CLI_SendEndSignal);
|
2019-08-16 02:54:06 +00:00
|
|
|
lock_jump_buffer(app, out_buffer);
|
2017-07-17 21:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 23:57:21 +00:00
|
|
|
CUSTOM_COMMAND_SIG(execute_any_cli)
|
|
|
|
CUSTOM_DOC("Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer."){
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
2019-10-13 20:17:22 +00:00
|
|
|
Query_Bar_Group group(app);
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Query_Bar bar_out = {};
|
|
|
|
bar_out.prompt = string_u8_litexpr("Output Buffer: ");
|
2019-12-18 03:38:08 +00:00
|
|
|
bar_out.string = SCu8(out_buffer_space, (u64)0);
|
2019-06-01 23:58:28 +00:00
|
|
|
bar_out.string_capacity = sizeof(out_buffer_space);
|
2017-01-29 00:03:23 +00:00
|
|
|
if (!query_user_string(app, &bar_out)) return;
|
2020-01-02 22:37:01 +00:00
|
|
|
bar_out.string.size = clamp_top(bar_out.string.size, sizeof(out_buffer_space) - 1);
|
|
|
|
out_buffer_space[bar_out.string.size] = 0;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Query_Bar bar_cmd = {};
|
|
|
|
bar_cmd.prompt = string_u8_litexpr("Command: ");
|
2019-12-18 03:38:08 +00:00
|
|
|
bar_cmd.string = SCu8(command_space, (u64)0);
|
2019-06-01 23:58:28 +00:00
|
|
|
bar_cmd.string_capacity = sizeof(command_space);
|
2017-01-29 00:03:23 +00:00
|
|
|
if (!query_user_string(app, &bar_cmd)) return;
|
2020-01-02 22:37:01 +00:00
|
|
|
bar_cmd.string.size = clamp_top(bar_cmd.string.size, sizeof(command_space) - 1);
|
|
|
|
command_space[bar_cmd.string.size] = 0;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 hot = push_hot_directory(app, scratch);
|
|
|
|
{
|
2019-12-18 03:38:08 +00:00
|
|
|
u64 size = clamp_top(hot.size, sizeof(hot_directory_space));
|
2019-06-01 23:58:28 +00:00
|
|
|
block_copy(hot_directory_space, hot.str, size);
|
|
|
|
hot_directory_space[hot.size] = 0;
|
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2017-07-17 21:13:57 +00:00
|
|
|
execute_previous_cli(app);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|