aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/ui/util.c')
-rw-r--r--tools/perf/util/ui/util.c83
1 files changed, 53 insertions, 30 deletions
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
index fdf1fc8f08b..37e6fe081a5 100644
--- a/tools/perf/util/ui/util.c
+++ b/tools/perf/util/ui/util.c
@@ -8,10 +8,54 @@
8#include "../cache.h" 8#include "../cache.h"
9#include "../debug.h" 9#include "../debug.h"
10#include "browser.h" 10#include "browser.h"
11#include "keysyms.h"
11#include "helpline.h" 12#include "helpline.h"
12#include "ui.h" 13#include "ui.h"
13#include "util.h" 14#include "util.h"
14 15
16static void ui_browser__argv_write(struct ui_browser *browser,
17 void *entry, int row)
18{
19 char **arg = entry;
20 bool current_entry = ui_browser__is_current_entry(browser, row);
21
22 ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
23 HE_COLORSET_NORMAL);
24 slsmg_write_nstring(*arg, browser->width);
25}
26
27static int popup_menu__run(struct ui_browser *menu)
28{
29 int key;
30
31 if (ui_browser__show(menu, " ", "ESC: exit, ENTER|->: Select option") < 0)
32 return -1;
33
34 while (1) {
35 key = ui_browser__run(menu, 0);
36
37 switch (key) {
38 case K_RIGHT:
39 case K_ENTER:
40 key = menu->index;
41 break;
42 case K_LEFT:
43 case K_ESC:
44 case 'q':
45 case CTRL('c'):
46 key = -1;
47 break;
48 default:
49 continue;
50 }
51
52 break;
53 }
54
55 ui_browser__hide(menu);
56 return key;
57}
58
15static void newt_form__set_exit_keys(newtComponent self) 59static void newt_form__set_exit_keys(newtComponent self)
16{ 60{
17 newtFormAddHotKey(self, NEWT_KEY_LEFT); 61 newtFormAddHotKey(self, NEWT_KEY_LEFT);
@@ -31,36 +75,15 @@ static newtComponent newt_form__new(void)
31 75
32int ui__popup_menu(int argc, char * const argv[]) 76int ui__popup_menu(int argc, char * const argv[])
33{ 77{
34 struct newtExitStruct es; 78 struct ui_browser menu = {
35 int i, rc = -1, max_len = 5; 79 .entries = (void *)argv,
36 newtComponent listbox, form = newt_form__new(); 80 .refresh = ui_browser__argv_refresh,
37 81 .seek = ui_browser__argv_seek,
38 if (form == NULL) 82 .write = ui_browser__argv_write,
39 return -1; 83 .nr_entries = argc,
40 84 };
41 listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); 85
42 if (listbox == NULL) 86 return popup_menu__run(&menu);
43 goto out_destroy_form;
44
45 newtFormAddComponent(form, listbox);
46
47 for (i = 0; i < argc; ++i) {
48 int len = strlen(argv[i]);
49 if (len > max_len)
50 max_len = len;
51 if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
52 goto out_destroy_form;
53 }
54
55 newtCenteredWindow(max_len, argc, NULL);
56 newtFormRun(form, &es);
57 rc = newtListboxGetCurrent(listbox) - NULL;
58 if (es.reason == NEWT_EXIT_HOTKEY)
59 rc = -1;
60 newtPopWindow();
61out_destroy_form:
62 newtFormDestroy(form);
63 return rc;
64} 87}
65 88
66int ui__help_window(const char *text) 89int ui__help_window(const char *text)