diff options
Diffstat (limited to 'tools/perf/util/ui/browser.c')
| -rw-r--r-- | tools/perf/util/ui/browser.c | 117 | 
1 files changed, 63 insertions, 54 deletions
| diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c index 66f2d583d8c4..6d0df809a2ed 100644 --- a/tools/perf/util/ui/browser.c +++ b/tools/perf/util/ui/browser.c | |||
| @@ -1,16 +1,6 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | #undef _GNU_SOURCE | ||
| 4 | /* | ||
| 5 | * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks | ||
| 6 | * the build if it isn't defined. Use the equivalent one that glibc | ||
| 7 | * has on features.h. | ||
| 8 | */ | ||
| 9 | #include <features.h> | ||
| 10 | #ifndef HAVE_LONG_LONG | ||
| 11 | #define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG | ||
| 12 | #endif | ||
| 13 | #include <slang.h> | 1 | #include <slang.h> | 
| 2 | #include "libslang.h" | ||
| 3 | #include <linux/compiler.h> | ||
| 14 | #include <linux/list.h> | 4 | #include <linux/list.h> | 
| 15 | #include <linux/rbtree.h> | 5 | #include <linux/rbtree.h> | 
| 16 | #include <stdlib.h> | 6 | #include <stdlib.h> | 
| @@ -19,17 +9,9 @@ | |||
| 19 | #include "helpline.h" | 9 | #include "helpline.h" | 
| 20 | #include "../color.h" | 10 | #include "../color.h" | 
| 21 | #include "../util.h" | 11 | #include "../util.h" | 
| 12 | #include <stdio.h> | ||
| 22 | 13 | ||
| 23 | #if SLANG_VERSION < 20104 | 14 | static int ui_browser__percent_color(double percent, bool current) | 
| 24 | #define sltt_set_color(obj, name, fg, bg) \ | ||
| 25 | SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg) | ||
| 26 | #else | ||
| 27 | #define sltt_set_color SLtt_set_color | ||
| 28 | #endif | ||
| 29 | |||
| 30 | newtComponent newt_form__new(void); | ||
| 31 | |||
| 32 | int ui_browser__percent_color(double percent, bool current) | ||
| 33 | { | 15 | { | 
| 34 | if (current) | 16 | if (current) | 
| 35 | return HE_COLORSET_SELECTED; | 17 | return HE_COLORSET_SELECTED; | 
| @@ -40,6 +22,23 @@ int ui_browser__percent_color(double percent, bool current) | |||
| 40 | return HE_COLORSET_NORMAL; | 22 | return HE_COLORSET_NORMAL; | 
| 41 | } | 23 | } | 
| 42 | 24 | ||
| 25 | void ui_browser__set_color(struct ui_browser *self __used, int color) | ||
| 26 | { | ||
| 27 | SLsmg_set_color(color); | ||
| 28 | } | ||
| 29 | |||
| 30 | void ui_browser__set_percent_color(struct ui_browser *self, | ||
| 31 | double percent, bool current) | ||
| 32 | { | ||
| 33 | int color = ui_browser__percent_color(percent, current); | ||
| 34 | ui_browser__set_color(self, color); | ||
| 35 | } | ||
| 36 | |||
| 37 | void ui_browser__gotorc(struct ui_browser *self, int y, int x) | ||
| 38 | { | ||
| 39 | SLsmg_gotorc(self->y + y, self->x + x); | ||
| 40 | } | ||
| 41 | |||
| 43 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) | 42 | void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) | 
| 44 | { | 43 | { | 
| 45 | struct list_head *head = self->entries; | 44 | struct list_head *head = self->entries; | 
| @@ -111,7 +110,7 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self) | |||
| 111 | nd = self->top; | 110 | nd = self->top; | 
| 112 | 111 | ||
| 113 | while (nd != NULL) { | 112 | while (nd != NULL) { | 
| 114 | SLsmg_gotorc(self->y + row, self->x); | 113 | ui_browser__gotorc(self, row, 0); | 
| 115 | self->write(self, nd, row); | 114 | self->write(self, nd, row); | 
| 116 | if (++row == self->height) | 115 | if (++row == self->height) | 
| 117 | break; | 116 | break; | 
| @@ -131,13 +130,10 @@ void ui_browser__refresh_dimensions(struct ui_browser *self) | |||
| 131 | int cols, rows; | 130 | int cols, rows; | 
| 132 | newtGetScreenSize(&cols, &rows); | 131 | newtGetScreenSize(&cols, &rows); | 
| 133 | 132 | ||
| 134 | if (self->width > cols - 4) | 133 | self->width = cols - 1; | 
| 135 | self->width = cols - 4; | 134 | self->height = rows - 2; | 
| 136 | self->height = rows - 5; | 135 | self->y = 1; | 
| 137 | if (self->height > self->nr_entries) | 136 | self->x = 0; | 
| 138 | self->height = self->nr_entries; | ||
| 139 | self->y = (rows - self->height) / 2; | ||
| 140 | self->x = (cols - self->width) / 2; | ||
| 141 | } | 137 | } | 
| 142 | 138 | ||
| 143 | void ui_browser__reset_index(struct ui_browser *self) | 139 | void ui_browser__reset_index(struct ui_browser *self) | 
| @@ -146,34 +142,48 @@ void ui_browser__reset_index(struct ui_browser *self) | |||
| 146 | self->seek(self, 0, SEEK_SET); | 142 | self->seek(self, 0, SEEK_SET); | 
| 147 | } | 143 | } | 
| 148 | 144 | ||
| 145 | void ui_browser__add_exit_key(struct ui_browser *self, int key) | ||
| 146 | { | ||
| 147 | newtFormAddHotKey(self->form, key); | ||
| 148 | } | ||
| 149 | |||
| 150 | void ui_browser__add_exit_keys(struct ui_browser *self, int keys[]) | ||
| 151 | { | ||
| 152 | int i = 0; | ||
| 153 | |||
| 154 | while (keys[i] && i < 64) { | ||
| 155 | ui_browser__add_exit_key(self, keys[i]); | ||
| 156 | ++i; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 149 | int ui_browser__show(struct ui_browser *self, const char *title, | 160 | int ui_browser__show(struct ui_browser *self, const char *title, | 
| 150 | const char *helpline, ...) | 161 | const char *helpline, ...) | 
| 151 | { | 162 | { | 
| 152 | va_list ap; | 163 | va_list ap; | 
| 164 | int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP, | ||
| 165 | NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ', | ||
| 166 | NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 }; | ||
| 153 | 167 | ||
| 154 | if (self->form != NULL) { | 168 | if (self->form != NULL) | 
| 155 | newtFormDestroy(self->form); | 169 | newtFormDestroy(self->form); | 
| 156 | newtPopWindow(); | 170 | |
| 157 | } | ||
| 158 | ui_browser__refresh_dimensions(self); | 171 | ui_browser__refresh_dimensions(self); | 
| 159 | newtCenteredWindow(self->width, self->height, title); | 172 | self->form = newtForm(NULL, NULL, 0); | 
| 160 | self->form = newt_form__new(); | ||
| 161 | if (self->form == NULL) | 173 | if (self->form == NULL) | 
| 162 | return -1; | 174 | return -1; | 
| 163 | 175 | ||
| 164 | self->sb = newtVerticalScrollbar(self->width, 0, self->height, | 176 | self->sb = newtVerticalScrollbar(self->width, 1, self->height, | 
| 165 | HE_COLORSET_NORMAL, | 177 | HE_COLORSET_NORMAL, | 
| 166 | HE_COLORSET_SELECTED); | 178 | HE_COLORSET_SELECTED); | 
| 167 | if (self->sb == NULL) | 179 | if (self->sb == NULL) | 
| 168 | return -1; | 180 | return -1; | 
| 169 | 181 | ||
| 170 | newtFormAddHotKey(self->form, NEWT_KEY_UP); | 182 | SLsmg_gotorc(0, 0); | 
| 171 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); | 183 | ui_browser__set_color(self, NEWT_COLORSET_ROOT); | 
| 172 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); | 184 | slsmg_write_nstring(title, self->width); | 
| 173 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); | 185 | |
| 174 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); | 186 | ui_browser__add_exit_keys(self, keys); | 
| 175 | newtFormAddHotKey(self->form, NEWT_KEY_END); | ||
| 176 | newtFormAddHotKey(self->form, ' '); | ||
| 177 | newtFormAddComponent(self->form, self->sb); | 187 | newtFormAddComponent(self->form, self->sb); | 
| 178 | 188 | ||
| 179 | va_start(ap, helpline); | 189 | va_start(ap, helpline); | 
| @@ -185,7 +195,6 @@ int ui_browser__show(struct ui_browser *self, const char *title, | |||
| 185 | void ui_browser__hide(struct ui_browser *self) | 195 | void ui_browser__hide(struct ui_browser *self) | 
| 186 | { | 196 | { | 
| 187 | newtFormDestroy(self->form); | 197 | newtFormDestroy(self->form); | 
| 188 | newtPopWindow(); | ||
| 189 | self->form = NULL; | 198 | self->form = NULL; | 
| 190 | ui_helpline__pop(); | 199 | ui_helpline__pop(); | 
| 191 | } | 200 | } | 
| @@ -196,28 +205,28 @@ int ui_browser__refresh(struct ui_browser *self) | |||
| 196 | 205 | ||
| 197 | newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); | 206 | newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); | 
| 198 | row = self->refresh(self); | 207 | row = self->refresh(self); | 
| 199 | SLsmg_set_color(HE_COLORSET_NORMAL); | 208 | ui_browser__set_color(self, HE_COLORSET_NORMAL); | 
| 200 | SLsmg_fill_region(self->y + row, self->x, | 209 | SLsmg_fill_region(self->y + row, self->x, | 
| 201 | self->height - row, self->width, ' '); | 210 | self->height - row, self->width, ' '); | 
| 202 | 211 | ||
| 203 | return 0; | 212 | return 0; | 
| 204 | } | 213 | } | 
| 205 | 214 | ||
| 206 | int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) | 215 | int ui_browser__run(struct ui_browser *self) | 
| 207 | { | 216 | { | 
| 217 | struct newtExitStruct es; | ||
| 218 | |||
| 208 | if (ui_browser__refresh(self) < 0) | 219 | if (ui_browser__refresh(self) < 0) | 
| 209 | return -1; | 220 | return -1; | 
| 210 | 221 | ||
| 211 | while (1) { | 222 | while (1) { | 
| 212 | off_t offset; | 223 | off_t offset; | 
| 213 | 224 | ||
| 214 | newtFormRun(self->form, es); | 225 | newtFormRun(self->form, &es); | 
| 215 | 226 | ||
| 216 | if (es->reason != NEWT_EXIT_HOTKEY) | 227 | if (es.reason != NEWT_EXIT_HOTKEY) | 
| 217 | break; | 228 | break; | 
| 218 | if (is_exit_key(es->u.key)) | 229 | switch (es.u.key) { | 
| 219 | return es->u.key; | ||
| 220 | switch (es->u.key) { | ||
| 221 | case NEWT_KEY_DOWN: | 230 | case NEWT_KEY_DOWN: | 
| 222 | if (self->index == self->nr_entries - 1) | 231 | if (self->index == self->nr_entries - 1) | 
| 223 | break; | 232 | break; | 
| @@ -274,12 +283,12 @@ int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) | |||
| 274 | self->seek(self, -offset, SEEK_END); | 283 | self->seek(self, -offset, SEEK_END); | 
| 275 | break; | 284 | break; | 
| 276 | default: | 285 | default: | 
| 277 | return es->u.key; | 286 | return es.u.key; | 
| 278 | } | 287 | } | 
| 279 | if (ui_browser__refresh(self) < 0) | 288 | if (ui_browser__refresh(self) < 0) | 
| 280 | return -1; | 289 | return -1; | 
| 281 | } | 290 | } | 
| 282 | return 0; | 291 | return -1; | 
| 283 | } | 292 | } | 
| 284 | 293 | ||
| 285 | unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | 294 | unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | 
| @@ -294,7 +303,7 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *self) | |||
| 294 | pos = self->top; | 303 | pos = self->top; | 
| 295 | 304 | ||
| 296 | list_for_each_from(pos, head) { | 305 | list_for_each_from(pos, head) { | 
| 297 | SLsmg_gotorc(self->y + row, self->x); | 306 | ui_browser__gotorc(self, row, 0); | 
| 298 | self->write(self, pos, row); | 307 | self->write(self, pos, row); | 
| 299 | if (++row == self->height) | 308 | if (++row == self->height) | 
| 300 | break; | 309 | break; | 
