From d90efe9e2bbfb18ee05ec2032b5723dbfa902d82 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Wed, 15 Feb 2017 14:47:45 +1100 Subject: ui/ncurses: Update cui_run_cmd() to pass display to command Update cui_run_cmd() to setup a process that uses 'raw_stdout' so that output is displayed on the screen instead of being caught in the log. Also update cui_run_cmd() to take a more generic list of arguments, and add a cui_run_cmd_from_item() wrapper for the existing user. Signed-off-by: Samuel Mendoza-Jonas --- ui/ncurses/nc-cui.c | 28 ++++++++++++++++++++++++---- ui/ncurses/nc-cui.h | 3 ++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index fbc02b9..84e4bf0 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -155,19 +155,29 @@ void cui_on_exit(struct pmenu *menu) * cui_run_cmd - A generic cb to run the supplied command. */ -int cui_run_cmd(struct pmenu_item *item) +int cui_run_cmd(struct cui *cui, const char **cmd_argv) { + struct process *process; int result; - struct cui *cui = cui_from_item(item); - const char **cmd_argv = item->data; + + process = process_create(cui); + if (!process) + return -1; + + process->path = cmd_argv[0]; + process->argv = cmd_argv; + process->raw_stdout = true; nc_scr_status_printf(cui->current, _("Running %s..."), cmd_argv[0]); def_prog_mode(); + endwin(); - result = process_run_simple_argv(item, cmd_argv); + result = process_run_sync(process); reset_prog_mode(); + refresh(); + redrawwin(cui->current->main_ncw); if (result) { @@ -176,9 +186,19 @@ int cui_run_cmd(struct pmenu_item *item) cmd_argv[0]); } + process_release(process); + return result; } +int cui_run_cmd_from_item(struct pmenu_item *item) +{ + struct cui *cui = cui_from_item(item); + const char **cmd_argv = item->data; + + return cui_run_cmd(cui, cmd_argv); +} + /** * cui_boot - A generic cb to run kexec. */ diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index 418df71..d8a5f8b 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -98,7 +98,8 @@ void cui_abort(struct cui *cui); void cui_resize(struct cui *cui); void cui_on_exit(struct pmenu *menu); void cui_on_open(struct pmenu *menu); -int cui_run_cmd(struct pmenu_item *item); +int cui_run_cmd(struct cui *cui, const char **cmd_argv); +int cui_run_cmd_from_item(struct pmenu_item *item); static inline struct cui *cui_from_arg(void *arg) { -- cgit v1.2.1