aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-08-12 11:37:51 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-08-19 18:44:18 -0400
commit4c1c952e37c7511a52f617ceddbc10c855d45d7b (patch)
tree8f2ffa7d5b787b23cf88ea84309d7961e79d9c01
parentb50e003db13848dd74572ffd221047683313981d (diff)
perf ui browser: Add routines to compactly specify exit keys
This makes the usual idiom for specifying a series of key codes to exit ui_browser__run() for specialized processing (search, annotate, etc) or plain exiting the browser more compact. It also abstracts away some more libnewt operations. At some point we'll also replace NEWT_KEY_foo with something that can be mapped to NEWT or, say, gtk. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/ui/browser.c30
-rw-r--r--tools/perf/util/ui/browser.h2
-rw-r--r--tools/perf/util/ui/browsers/annotate.c12
-rw-r--r--tools/perf/util/ui/browsers/hists.c13
-rw-r--r--tools/perf/util/ui/browsers/map.c8
-rw-r--r--tools/perf/util/ui/util.c4
6 files changed, 34 insertions, 35 deletions
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 669a98067555..930c4acaf56a 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -11,8 +11,6 @@
11#include "../util.h" 11#include "../util.h"
12#include <stdio.h> 12#include <stdio.h>
13 13
14newtComponent newt_form__new(void);
15
16static int ui_browser__percent_color(double percent, bool current) 14static int ui_browser__percent_color(double percent, bool current)
17{ 15{
18 if (current) 16 if (current)
@@ -147,10 +145,28 @@ void ui_browser__reset_index(struct ui_browser *self)
147 self->seek(self, 0, SEEK_SET); 145 self->seek(self, 0, SEEK_SET);
148} 146}
149 147
148void ui_browser__add_exit_key(struct ui_browser *self, int key)
149{
150 newtFormAddHotKey(self->form, key);
151}
152
153void ui_browser__add_exit_keys(struct ui_browser *self, int keys[])
154{
155 int i = 0;
156
157 while (keys[i] && i < 64) {
158 ui_browser__add_exit_key(self, keys[i]);
159 ++i;
160 }
161}
162
150int ui_browser__show(struct ui_browser *self, const char *title, 163int ui_browser__show(struct ui_browser *self, const char *title,
151 const char *helpline, ...) 164 const char *helpline, ...)
152{ 165{
153 va_list ap; 166 va_list ap;
167 int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP,
168 NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ',
169 NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 };
154 170
155 if (self->form != NULL) { 171 if (self->form != NULL) {
156 newtFormDestroy(self->form); 172 newtFormDestroy(self->form);
@@ -158,7 +174,7 @@ int ui_browser__show(struct ui_browser *self, const char *title,
158 } 174 }
159 ui_browser__refresh_dimensions(self); 175 ui_browser__refresh_dimensions(self);
160 newtCenteredWindow(self->width, self->height, title); 176 newtCenteredWindow(self->width, self->height, title);
161 self->form = newt_form__new(); 177 self->form = newtForm(NULL, NULL, 0);
162 if (self->form == NULL) 178 if (self->form == NULL)
163 return -1; 179 return -1;
164 180
@@ -168,13 +184,7 @@ int ui_browser__show(struct ui_browser *self, const char *title,
168 if (self->sb == NULL) 184 if (self->sb == NULL)
169 return -1; 185 return -1;
170 186
171 newtFormAddHotKey(self->form, NEWT_KEY_UP); 187 ui_browser__add_exit_keys(self, keys);
172 newtFormAddHotKey(self->form, NEWT_KEY_DOWN);
173 newtFormAddHotKey(self->form, NEWT_KEY_PGUP);
174 newtFormAddHotKey(self->form, NEWT_KEY_PGDN);
175 newtFormAddHotKey(self->form, NEWT_KEY_HOME);
176 newtFormAddHotKey(self->form, NEWT_KEY_END);
177 newtFormAddHotKey(self->form, ' ');
178 newtFormAddComponent(self->form, self->sb); 188 newtFormAddComponent(self->form, self->sb);
179 189
180 va_start(ap, helpline); 190 va_start(ap, helpline);
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h
index 332a675e55cc..0dc7e4da36f5 100644
--- a/tools/perf/util/ui/browser.h
+++ b/tools/perf/util/ui/browser.h
@@ -33,6 +33,8 @@ void ui_browser__refresh_dimensions(struct ui_browser *self);
33void ui_browser__reset_index(struct ui_browser *self); 33void ui_browser__reset_index(struct ui_browser *self);
34 34
35void ui_browser__gotorc(struct ui_browser *self, int y, int x); 35void ui_browser__gotorc(struct ui_browser *self, int y, int x);
36void ui_browser__add_exit_key(struct ui_browser *self, int key);
37void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]);
36int ui_browser__show(struct ui_browser *self, const char *title, 38int ui_browser__show(struct ui_browser *self, const char *title,
37 const char *helpline, ...); 39 const char *helpline, ...);
38void ui_browser__hide(struct ui_browser *self); 40void ui_browser__hide(struct ui_browser *self);
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c
index a8bc2c015946..82b78f99251b 100644
--- a/tools/perf/util/ui/browsers/annotate.c
+++ b/tools/perf/util/ui/browsers/annotate.c
@@ -142,14 +142,16 @@ static int annotate_browser__run(struct annotate_browser *self)
142 if (ui_browser__show(&self->b, he->ms.sym->name, 142 if (ui_browser__show(&self->b, he->ms.sym->name,
143 "<-, -> or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0) 143 "<-, -> or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0)
144 return -1; 144 return -1;
145 145 /*
146 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 146 * To allow builtin-annotate to cycle thru multiple symbols by
147 newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT); 147 * examining the exit key for this function.
148 */
149 ui_browser__add_exit_key(&self->b, NEWT_KEY_RIGHT);
148 150
149 nd = self->curr_hot; 151 nd = self->curr_hot;
150 if (nd) { 152 if (nd) {
151 newtFormAddHotKey(self->b.form, NEWT_KEY_TAB); 153 int tabs[] = { NEWT_KEY_TAB, NEWT_KEY_UNTAB, 0 };
152 newtFormAddHotKey(self->b.form, NEWT_KEY_UNTAB); 154 ui_browser__add_exit_keys(&self->b, tabs);
153 } 155 }
154 156
155 while (1) { 157 while (1) {
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c
index 1735c48691a5..b13b9787be70 100644
--- a/tools/perf/util/ui/browsers/hists.c
+++ b/tools/perf/util/ui/browsers/hists.c
@@ -198,6 +198,8 @@ static bool hist_browser__toggle_fold(struct hist_browser *self)
198static int hist_browser__run(struct hist_browser *self, const char *title) 198static int hist_browser__run(struct hist_browser *self, const char *title)
199{ 199{
200 int key; 200 int key;
201 int exit_keys[] = { 'a', '?', 'h', 'd', 'D', 't', NEWT_KEY_ENTER,
202 NEWT_KEY_RIGHT, NEWT_KEY_LEFT, 0, };
201 char str[256], unit; 203 char str[256], unit;
202 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE]; 204 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE];
203 205
@@ -215,16 +217,7 @@ static int hist_browser__run(struct hist_browser *self, const char *title)
215 "Press '?' for help on key bindings") < 0) 217 "Press '?' for help on key bindings") < 0)
216 return -1; 218 return -1;
217 219
218 newtFormAddHotKey(self->b.form, 'a'); 220 ui_browser__add_exit_keys(&self->b, exit_keys);
219 newtFormAddHotKey(self->b.form, '?');
220 newtFormAddHotKey(self->b.form, 'h');
221 newtFormAddHotKey(self->b.form, 'd');
222 newtFormAddHotKey(self->b.form, 'D');
223 newtFormAddHotKey(self->b.form, 't');
224
225 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
226 newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT);
227 newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER);
228 221
229 while (1) { 222 while (1) {
230 key = ui_browser__run(&self->b); 223 key = ui_browser__run(&self->b);
diff --git a/tools/perf/util/ui/browsers/map.c b/tools/perf/util/ui/browsers/map.c
index 16b7d70f2c58..1bf09796cb31 100644
--- a/tools/perf/util/ui/browsers/map.c
+++ b/tools/perf/util/ui/browsers/map.c
@@ -1,6 +1,5 @@
1#include "../libslang.h" 1#include "../libslang.h"
2#include <elf.h> 2#include <elf.h>
3#include <newt.h>
4#include <sys/ttydefaults.h> 3#include <sys/ttydefaults.h>
5#include <ctype.h> 4#include <ctype.h>
6#include <string.h> 5#include <string.h>
@@ -106,13 +105,8 @@ static int map_browser__run(struct map_browser *self)
106 verbose ? "" : "restart with -v to use") < 0) 105 verbose ? "" : "restart with -v to use") < 0)
107 return -1; 106 return -1;
108 107
109 newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT);
110 newtFormAddHotKey(self->b.form, NEWT_KEY_ESCAPE);
111 newtFormAddHotKey(self->b.form, 'Q');
112 newtFormAddHotKey(self->b.form, 'q');
113 newtFormAddHotKey(self->b.form, CTRL('c'));
114 if (verbose) 108 if (verbose)
115 newtFormAddHotKey(self->b.form, '/'); 109 ui_browser__add_exit_key(&self->b, '/');
116 110
117 while (1) { 111 while (1) {
118 key = ui_browser__run(&self->b); 112 key = ui_browser__run(&self->b);
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
index 04600e26ceea..9706d9d40279 100644
--- a/tools/perf/util/ui/util.c
+++ b/tools/perf/util/ui/util.c
@@ -11,8 +11,6 @@
11#include "helpline.h" 11#include "helpline.h"
12#include "util.h" 12#include "util.h"
13 13
14newtComponent newt_form__new(void);
15
16static void newt_form__set_exit_keys(newtComponent self) 14static void newt_form__set_exit_keys(newtComponent self)
17{ 15{
18 newtFormAddHotKey(self, NEWT_KEY_LEFT); 16 newtFormAddHotKey(self, NEWT_KEY_LEFT);
@@ -22,7 +20,7 @@ static void newt_form__set_exit_keys(newtComponent self)
22 newtFormAddHotKey(self, CTRL('c')); 20 newtFormAddHotKey(self, CTRL('c'));
23} 21}
24 22
25newtComponent newt_form__new(void) 23static newtComponent newt_form__new(void)
26{ 24{
27 newtComponent self = newtForm(NULL, NULL, 0); 25 newtComponent self = newtForm(NULL, NULL, 0);
28 if (self) 26 if (self)