aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-10-26 05:11:03 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-10-26 11:06:23 -0400
commit1056d3dd9416740ec7d31348ca5f55009dc06bf3 (patch)
tree7b5b9774f01b92b9f615237eeb9d4b37fd73e473 /tools/perf
parent2ba908ecfc4697dd856a526a9d4d4bd28e64a9cd (diff)
perf ui: Reimplement ui__popup_menu using ui__browser
Right now let it work just like the other browsers: in full screen, at the top left corner. If people complain we can revisit, I found it OK and the laziest/quickest approach at reusing the ui_browser ;-) Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-4bgeqizcxh04q0sk24cw43gk@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/ui/browser.c41
-rw-r--r--tools/perf/util/ui/browser.h3
-rw-r--r--tools/perf/util/ui/util.c83
3 files changed, 97 insertions, 30 deletions
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 370c4703cec8..29c68aee00df 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -488,6 +488,47 @@ static int ui_browser__color_config(const char *var, const char *value,
488 return -1; 488 return -1;
489} 489}
490 490
491void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence)
492{
493 switch (whence) {
494 case SEEK_SET:
495 browser->top = browser->entries;
496 break;
497 case SEEK_CUR:
498 browser->top = browser->top + browser->top_idx + offset;
499 break;
500 case SEEK_END:
501 browser->top = browser->top + browser->nr_entries + offset;
502 break;
503 default:
504 return;
505 }
506}
507
508unsigned int ui_browser__argv_refresh(struct ui_browser *browser)
509{
510 unsigned int row = 0, idx = browser->top_idx;
511 char **pos;
512
513 if (browser->top == NULL)
514 browser->top = browser->entries;
515
516 pos = (char **)browser->top;
517 while (idx < browser->nr_entries) {
518 if (!browser->filter || !browser->filter(browser, *pos)) {
519 ui_browser__gotorc(browser, row, 0);
520 browser->write(browser, pos, row);
521 if (++row == browser->height)
522 break;
523 }
524
525 ++idx;
526 ++pos;
527 }
528
529 return row;
530}
531
491void ui_browser__init(void) 532void ui_browser__init(void)
492{ 533{
493 int i = 0; 534 int i = 0;
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index a2c707d33c5e..81a8d2afaa9b 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -44,6 +44,9 @@ int ui_browser__refresh(struct ui_browser *self);
44int ui_browser__run(struct ui_browser *browser, int delay_secs); 44int ui_browser__run(struct ui_browser *browser, int delay_secs);
45void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries); 45void ui_browser__update_nr_entries(struct ui_browser *browser, u32 nr_entries);
46 46
47void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
48unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
49
47void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence); 50void ui_browser__rb_tree_seek(struct ui_browser *self, off_t offset, int whence);
48unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self); 51unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self);
49 52
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
index fdf1fc8f08bc..37e6fe081a58 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)