ui/ncurses: Update cui_run_cmd() to pass display to command
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 15 Feb 2017 03:47:45 +0000 (14:47 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 15 Aug 2017 03:38:17 +0000 (13:38 +1000)
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@mendozajonas.com>
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h

index fbc02b969f15b1177b7d491825366d95631c2959..84e4bf01cdff59b1021d8c79a9a19dfa5a2803a6 100644 (file)
@@ -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.
  */
index 418df711204ea3f95ea176ba4b8f71c6263bc8cd..d8a5f8b5f5a16e99ca62dc79eecccca1a2b606aa 100644 (file)
@@ -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)
 {