[PATCH v2 11/12] ui/ncurses: Update cui_run_cmd() to pass display to command

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue Jul 25 16:49:09 AEST 2017


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 <sam at mendozajonas.com>
---
 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)
 {
-- 
2.13.3



More information about the Petitboot mailing list