tools ui popup: Allow returning hotkeys
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 16 Dec 2019 15:23:34 +0000 (12:23 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Jan 2020 14:46:10 +0000 (11:46 -0300)
With this patch if an optional pointer is passed to ui__popup_menu()
then when any key that is not being handled (ENTER, ESC, etc) is typed,
it'll record that key in the pointer and return, allowing for hotkey
processing on the caller.

If NULL is passed, no change in logic, unhandled keys continue to be
ignored.

Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-6ojn19mqzgmrdm8kdoigic0m@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browsers/hists.c
tools/perf/ui/browsers/res_sample.c
tools/perf/ui/browsers/scripts.c
tools/perf/ui/tui/util.c
tools/perf/ui/util.h

index ac118aef5ed1126dfe8c5b466762ef7608a8cc10..c44b508f9e064f7d688670bba2b96bc7b31daf95 100644 (file)
@@ -2393,7 +2393,7 @@ close_file_and_continue:
        closedir(pwd_dir);
 
        if (nr_options) {
-               choice = ui__popup_menu(nr_options, options);
+               choice = ui__popup_menu(nr_options, options, NULL);
                if (choice < nr_options && choice >= 0) {
                        tmp = strdup(abs_path[choice]);
                        if (tmp) {
@@ -3279,7 +3279,7 @@ skip_scripting:
                do {
                        struct popup_action *act;
 
-                       choice = ui__popup_menu(nr_options, options);
+                       choice = ui__popup_menu(nr_options, options, NULL);
                        if (choice == -1 || choice >= nr_options)
                                break;
 
index 76d356a1879063956c50dae3010a94364920f314..7cb2d6678039749813c405ac1f515c7796ce8b53 100644 (file)
@@ -56,7 +56,7 @@ int res_sample_browse(struct res_sample *res_samples, int num_res,
                        return -1;
                }
        }
-       choice = ui__popup_menu(num_res, names);
+       choice = ui__popup_menu(num_res, names, NULL);
        for (i = 0; i < num_res; i++)
                zfree(&names[i]);
        free(names);
index fc733a6354d4dc4fc6f21e138dd7cbbe4378c20a..47d2c7a8cbe13cba1a3f9d46fd3c720cf0d2149c 100644 (file)
@@ -126,7 +126,7 @@ static int list_scripts(char *script_name, bool *custom,
                        SCRIPT_FULLPATH_LEN);
        if (num < 0)
                num = 0;
-       choice = ui__popup_menu(num + max_std, (char * const *)names);
+       choice = ui__popup_menu(num + max_std, (char * const *)names, NULL);
        if (choice < 0) {
                ret = -1;
                goto out;
index b98dd0e31dc1aee049c3fabcf6dcee7649547a5f..0f562e2cb1e881181976ad1e1bbad77aa939c580 100644 (file)
@@ -23,7 +23,7 @@ static void ui_browser__argv_write(struct ui_browser *browser,
        ui_browser__write_nstring(browser, *arg, browser->width);
 }
 
-static int popup_menu__run(struct ui_browser *menu)
+static int popup_menu__run(struct ui_browser *menu, int *keyp)
 {
        int key;
 
@@ -45,6 +45,11 @@ static int popup_menu__run(struct ui_browser *menu)
                        key = -1;
                        break;
                default:
+                       if (keyp) {
+                               *keyp = key;
+                               key = menu->nr_entries;
+                               break;
+                       }
                        continue;
                }
 
@@ -55,7 +60,7 @@ static int popup_menu__run(struct ui_browser *menu)
        return key;
 }
 
-int ui__popup_menu(int argc, char * const argv[])
+int ui__popup_menu(int argc, char * const argv[], int *keyp)
 {
        struct ui_browser menu = {
                .entries    = (void *)argv,
@@ -64,8 +69,7 @@ int ui__popup_menu(int argc, char * const argv[])
                .write      = ui_browser__argv_write,
                .nr_entries = argc,
        };
-
-       return popup_menu__run(&menu);
+       return popup_menu__run(&menu, keyp);
 }
 
 int ui_browser__input_window(const char *title, const char *text, char *input,
index 40891942f465dc4737b89fbd77d6646bcf81b49d..e30cea807564f92ff26c316fad580323f70ad240 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdarg.h>
 
 int ui__getch(int delay_secs);
-int ui__popup_menu(int argc, char * const argv[]);
+int ui__popup_menu(int argc, char * const argv[], int *keyp);
 int ui__help_window(const char *text);
 int ui__dialog_yesno(const char *msg);
 void __ui__info_window(const char *title, const char *text, const char *exit_msg);