4coder/4coder_system_command.cpp

50 lines
1.8 KiB
C++
Raw Normal View History

/*
4coder_system_command.cpp - Commands for executing arbitrary system command line instructions.
*/
// TOP
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);
if (out_buffer.size > 0 && cmd.size > 0 && hot_directory.size > 0){
2019-06-19 02:31:59 +00:00
View_ID view = get_active_view(app, AccessAll);
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);
}
}
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-06-01 23:58:28 +00:00
Query_Bar bar_out = {};
bar_out.prompt = string_u8_litexpr("Output Buffer: ");
bar_out.string = SCu8(out_buffer_space, (umem)0);
bar_out.string_capacity = sizeof(out_buffer_space);
if (!query_user_string(app, &bar_out)) return;
2019-06-01 23:58:28 +00:00
Query_Bar bar_cmd = {};
bar_cmd.prompt = string_u8_litexpr("Command: ");
bar_cmd.string = SCu8(command_space, (umem)0);
bar_cmd.string_capacity = sizeof(command_space);
if (!query_user_string(app, &bar_cmd)) return;
2019-06-01 23:58:28 +00:00
String_Const_u8 hot = push_hot_directory(app, scratch);
{
umem size = clamp_top(hot.size, sizeof(hot_directory_space));
block_copy(hot_directory_space, hot.str, size);
hot_directory_space[hot.size] = 0;
}
execute_previous_cli(app);
}
// BOTTOM