1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

option for running external commands in the foreground

This commit is contained in:
sgerwk 2021-03-22 01:00:34 +01:00
parent 1570b6f0c5
commit 69d52ced31
2 changed files with 41 additions and 13 deletions

View File

@ -852,21 +852,32 @@ static union option_info config_options_info[] = {
"link and tab menu will have a submenu of items for each "
"rule.\n"
"\n"
"Note, this is mostly useful for launching graphical viewers, "
"since there is no support for releasing the terminal while "
"the command runs. The action and submenus are also available "
"by binding keys to the frame-external-command, the "
"link-external-command, and the tab-external-command "
"actions.")),
"The action and submenus are also available by binding keys "
"to the frame-external-command, the link-external-command, "
"and the tab-external-command actions.\n"
"\n"
"Commands run in the background by default: elinks is still "
"active, and they do not receive standard input. "
"The \"foreground\" suboption reverses this behaviour: "
"the command receives standard input "
"and elinks is blocked.\n")),
INIT_OPT_STRING("document.uri_passing", NULL,
"_template_", 0, "",
N_("A rule for passing URI to an external command. "
INIT_OPT_TREE("document.uri_passing", NULL,
"_template_", 0,
N_("A rule for passing URI to an external command.")),
INIT_OPT_STRING("document.uri_passing._template_", NULL,
"command", 0, "",
N_("The external command. "
"The format is:\n"
"%c in the string means the current URL\n"
"%% in the string means '%'\n"
"Do _not_ put single- or double-quotes around %c.")),
INIT_OPT_BOOL("document.uri_passing._template_", NULL,
"foreground", 0, 0,
N_("Run command in the foreground.")),
/* Keep options in alphabetical order. */

View File

@ -762,8 +762,9 @@ static void
do_pass_uri_to_command(struct terminal *term, void *command_, void *xxx)
{
char *command = command_;
int block = command[0] == 'b' ? TERM_EXEC_BG : TERM_EXEC_FG;
exec_on_terminal(term, command, "", TERM_EXEC_BG);
exec_on_terminal(term, command + 1, "", block);
mem_free(command);
}
@ -820,7 +821,7 @@ pass_uri_to_command(struct session *ses, struct document_view *doc_view,
NULL);
enum pass_uri_type type = which_type;
struct menu_item *items;
struct option *option;
struct option *option, *sub;
struct uri *uri;
int commands = 0;
@ -856,7 +857,8 @@ pass_uri_to_command(struct session *ses, struct document_view *doc_view,
}
foreach (option, *tree) {
char *text, *data;
char *text, *command, *data;
int block;
if (!strcmp(option->name, "_template_"))
continue;
@ -864,11 +866,26 @@ pass_uri_to_command(struct session *ses, struct document_view *doc_view,
text = stracpy(option->name);
if (!text) continue;
data = format_command(option->value.string, uri);
command = NULL;
block = 0;
foreach (sub, *option->value.tree) {
if (!strcmp(sub->name, "command"))
command = sub->value.string;
if (!strcmp(sub->name, "foreground"))
block = sub->value.number;
}
if (!command)
continue;
data = format_command(command, uri);
if (!data) {
mem_free(text);
continue;
}
insert_in_string(&data, 0, " ", 1);
data[0] = block ? 'f' : 'b';
add_to_menu(&items, text, NULL, ACT_MAIN_NONE,
do_pass_uri_to_command, data, 0);