Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+34 -35
+20 -10
tools/perf/util/ui/browser.c
··· 11 11 #include "../util.h" 12 12 #include <stdio.h> 13 13 14 - newtComponent newt_form__new(void); 15 - 16 14 static int ui_browser__percent_color(double percent, bool current) 17 15 { 18 16 if (current) ··· 145 147 self->seek(self, 0, SEEK_SET); 146 148 } 147 149 150 + void ui_browser__add_exit_key(struct ui_browser *self, int key) 151 + { 152 + newtFormAddHotKey(self->form, key); 153 + } 154 + 155 + void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]) 156 + { 157 + int i = 0; 158 + 159 + while (keys[i] && i < 64) { 160 + ui_browser__add_exit_key(self, keys[i]); 161 + ++i; 162 + } 163 + } 164 + 148 165 int ui_browser__show(struct ui_browser *self, const char *title, 149 166 const char *helpline, ...) 150 167 { 151 168 va_list ap; 169 + int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP, 170 + NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ', 171 + NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 }; 152 172 153 173 if (self->form != NULL) { 154 174 newtFormDestroy(self->form); ··· 174 158 } 175 159 ui_browser__refresh_dimensions(self); 176 160 newtCenteredWindow(self->width, self->height, title); 177 - self->form = newt_form__new(); 161 + self->form = newtForm(NULL, NULL, 0); 178 162 if (self->form == NULL) 179 163 return -1; 180 164 ··· 184 168 if (self->sb == NULL) 185 169 return -1; 186 170 187 - newtFormAddHotKey(self->form, NEWT_KEY_UP); 188 - newtFormAddHotKey(self->form, NEWT_KEY_DOWN); 189 - newtFormAddHotKey(self->form, NEWT_KEY_PGUP); 190 - newtFormAddHotKey(self->form, NEWT_KEY_PGDN); 191 - newtFormAddHotKey(self->form, NEWT_KEY_HOME); 192 - newtFormAddHotKey(self->form, NEWT_KEY_END); 193 - newtFormAddHotKey(self->form, ' '); 171 + ui_browser__add_exit_keys(self, keys); 194 172 newtFormAddComponent(self->form, self->sb); 195 173 196 174 va_start(ap, helpline);
+2
tools/perf/util/ui/browser.h
··· 33 33 void ui_browser__reset_index(struct ui_browser *self); 34 34 35 35 void ui_browser__gotorc(struct ui_browser *self, int y, int x); 36 + void ui_browser__add_exit_key(struct ui_browser *self, int key); 37 + void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]); 36 38 int ui_browser__show(struct ui_browser *self, const char *title, 37 39 const char *helpline, ...); 38 40 void ui_browser__hide(struct ui_browser *self);
+7 -5
tools/perf/util/ui/browsers/annotate.c
··· 142 142 if (ui_browser__show(&self->b, he->ms.sym->name, 143 143 "<-, -> or ESC: exit, TAB/shift+TAB: cycle thru samples") < 0) 144 144 return -1; 145 - 146 - newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 147 - newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT); 145 + /* 146 + * To allow builtin-annotate to cycle thru multiple symbols by 147 + * examining the exit key for this function. 148 + */ 149 + ui_browser__add_exit_key(&self->b, NEWT_KEY_RIGHT); 148 150 149 151 nd = self->curr_hot; 150 152 if (nd) { 151 - newtFormAddHotKey(self->b.form, NEWT_KEY_TAB); 152 - newtFormAddHotKey(self->b.form, NEWT_KEY_UNTAB); 153 + int tabs[] = { NEWT_KEY_TAB, NEWT_KEY_UNTAB, 0 }; 154 + ui_browser__add_exit_keys(&self->b, tabs); 153 155 } 154 156 155 157 while (1) {
+3 -10
tools/perf/util/ui/browsers/hists.c
··· 198 198 static int hist_browser__run(struct hist_browser *self, const char *title) 199 199 { 200 200 int key; 201 + int exit_keys[] = { 'a', '?', 'h', 'd', 'D', 't', NEWT_KEY_ENTER, 202 + NEWT_KEY_RIGHT, NEWT_KEY_LEFT, 0, }; 201 203 char str[256], unit; 202 204 unsigned long nr_events = self->hists->stats.nr_events[PERF_RECORD_SAMPLE]; 203 205 ··· 217 215 "Press '?' for help on key bindings") < 0) 218 216 return -1; 219 217 220 - newtFormAddHotKey(self->b.form, 'a'); 221 - newtFormAddHotKey(self->b.form, '?'); 222 - newtFormAddHotKey(self->b.form, 'h'); 223 - newtFormAddHotKey(self->b.form, 'd'); 224 - newtFormAddHotKey(self->b.form, 'D'); 225 - newtFormAddHotKey(self->b.form, 't'); 226 - 227 - newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 228 - newtFormAddHotKey(self->b.form, NEWT_KEY_RIGHT); 229 - newtFormAddHotKey(self->b.form, NEWT_KEY_ENTER); 218 + ui_browser__add_exit_keys(&self->b, exit_keys); 230 219 231 220 while (1) { 232 221 key = ui_browser__run(&self->b);
+1 -7
tools/perf/util/ui/browsers/map.c
··· 1 1 #include "../libslang.h" 2 2 #include <elf.h> 3 - #include <newt.h> 4 3 #include <sys/ttydefaults.h> 5 4 #include <ctype.h> 6 5 #include <string.h> ··· 105 106 verbose ? "" : "restart with -v to use") < 0) 106 107 return -1; 107 108 108 - newtFormAddHotKey(self->b.form, NEWT_KEY_LEFT); 109 - newtFormAddHotKey(self->b.form, NEWT_KEY_ESCAPE); 110 - newtFormAddHotKey(self->b.form, 'Q'); 111 - newtFormAddHotKey(self->b.form, 'q'); 112 - newtFormAddHotKey(self->b.form, CTRL('c')); 113 109 if (verbose) 114 - newtFormAddHotKey(self->b.form, '/'); 110 + ui_browser__add_exit_key(&self->b, '/'); 115 111 116 112 while (1) { 117 113 key = ui_browser__run(&self->b);
+1 -3
tools/perf/util/ui/util.c
··· 11 11 #include "helpline.h" 12 12 #include "util.h" 13 13 14 - newtComponent newt_form__new(void); 15 - 16 14 static void newt_form__set_exit_keys(newtComponent self) 17 15 { 18 16 newtFormAddHotKey(self, NEWT_KEY_LEFT); ··· 20 22 newtFormAddHotKey(self, CTRL('c')); 21 23 } 22 24 23 - newtComponent newt_form__new(void) 25 + static newtComponent newt_form__new(void) 24 26 { 25 27 newtComponent self = newtForm(NULL, NULL, 0); 26 28 if (self)