aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/ui/browser.c
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 /tools/perf/util/ui/browser.c
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>
Diffstat (limited to 'tools/perf/util/ui/browser.c')
-rw-r--r--tools/perf/util/ui/browser.c30
1 files changed, 20 insertions, 10 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);