diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-06-21 12:36:20 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-06-21 12:36:20 -0400 |
commit | 46b0a07a45b07ed5ca8053bbb6ec522982d1a1dd (patch) | |
tree | 03f1388e7c87fde1917c3694eb3a660e9f861f2d | |
parent | 8c694d2559acf09bfd8b71fe1795e740063ad803 (diff) |
perf ui: Introduce ui_browser->seek to support multiple list structures
So that we can use the ui_browser on things like an rb_tree, etc.
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/newt.c | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c index 1e774e7f2281..0ffc8281363c 100644 --- a/tools/perf/util/newt.c +++ b/tools/perf/util/newt.c | |||
@@ -267,9 +267,42 @@ struct ui_browser { | |||
267 | void *first_visible_entry, *entries; | 267 | void *first_visible_entry, *entries; |
268 | u16 top, left, width, height; | 268 | u16 top, left, width, height; |
269 | void *priv; | 269 | void *priv; |
270 | void (*seek)(struct ui_browser *self, | ||
271 | off_t offset, int whence); | ||
270 | u32 nr_entries; | 272 | u32 nr_entries; |
271 | }; | 273 | }; |
272 | 274 | ||
275 | static void ui_browser__list_head_seek(struct ui_browser *self, | ||
276 | off_t offset, int whence) | ||
277 | { | ||
278 | struct list_head *head = self->entries; | ||
279 | struct list_head *pos; | ||
280 | |||
281 | switch (whence) { | ||
282 | case SEEK_SET: | ||
283 | pos = head->next; | ||
284 | break; | ||
285 | case SEEK_CUR: | ||
286 | pos = self->first_visible_entry; | ||
287 | break; | ||
288 | case SEEK_END: | ||
289 | pos = head->prev; | ||
290 | break; | ||
291 | default: | ||
292 | return; | ||
293 | } | ||
294 | |||
295 | if (offset > 0) { | ||
296 | while (offset-- != 0) | ||
297 | pos = pos->next; | ||
298 | } else { | ||
299 | while (offset++ != 0) | ||
300 | pos = pos->prev; | ||
301 | } | ||
302 | |||
303 | self->first_visible_entry = pos; | ||
304 | } | ||
305 | |||
273 | static bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row) | 306 | static bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row) |
274 | { | 307 | { |
275 | return (self->first_visible_entry_idx + row) == self->index; | 308 | return (self->first_visible_entry_idx + row) == self->index; |
@@ -292,7 +325,7 @@ static void ui_browser__refresh_dimensions(struct ui_browser *self) | |||
292 | static void ui_browser__reset_index(struct ui_browser *self) | 325 | static void ui_browser__reset_index(struct ui_browser *self) |
293 | { | 326 | { |
294 | self->index = self->first_visible_entry_idx = 0; | 327 | self->index = self->first_visible_entry_idx = 0; |
295 | self->first_visible_entry = NULL; | 328 | self->seek(self, 0, SEEK_SET); |
296 | } | 329 | } |
297 | 330 | ||
298 | static int objdump_line__show(struct objdump_line *self, struct list_head *head, | 331 | static int objdump_line__show(struct objdump_line *self, struct list_head *head, |
@@ -408,7 +441,7 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
408 | newtFormAddComponent(self->form, self->sb); | 441 | newtFormAddComponent(self->form, self->sb); |
409 | 442 | ||
410 | while (1) { | 443 | while (1) { |
411 | unsigned int offset; | 444 | off_t offset; |
412 | 445 | ||
413 | newtFormRun(self->form, es); | 446 | newtFormRun(self->form, es); |
414 | 447 | ||
@@ -422,9 +455,8 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
422 | break; | 455 | break; |
423 | ++self->index; | 456 | ++self->index; |
424 | if (self->index == self->first_visible_entry_idx + self->height) { | 457 | if (self->index == self->first_visible_entry_idx + self->height) { |
425 | struct list_head *pos = self->first_visible_entry; | ||
426 | ++self->first_visible_entry_idx; | 458 | ++self->first_visible_entry_idx; |
427 | self->first_visible_entry = pos->next; | 459 | self->seek(self, +1, SEEK_CUR); |
428 | } | 460 | } |
429 | break; | 461 | break; |
430 | case NEWT_KEY_UP: | 462 | case NEWT_KEY_UP: |
@@ -432,9 +464,8 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
432 | break; | 464 | break; |
433 | --self->index; | 465 | --self->index; |
434 | if (self->index < self->first_visible_entry_idx) { | 466 | if (self->index < self->first_visible_entry_idx) { |
435 | struct list_head *pos = self->first_visible_entry; | ||
436 | --self->first_visible_entry_idx; | 467 | --self->first_visible_entry_idx; |
437 | self->first_visible_entry = pos->prev; | 468 | self->seek(self, -1, SEEK_CUR); |
438 | } | 469 | } |
439 | break; | 470 | break; |
440 | case NEWT_KEY_PGDN: | 471 | case NEWT_KEY_PGDN: |
@@ -447,12 +478,7 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
447 | offset = self->nr_entries - 1 - self->index; | 478 | offset = self->nr_entries - 1 - self->index; |
448 | self->index += offset; | 479 | self->index += offset; |
449 | self->first_visible_entry_idx += offset; | 480 | self->first_visible_entry_idx += offset; |
450 | 481 | self->seek(self, +offset, SEEK_CUR); | |
451 | while (offset--) { | ||
452 | struct list_head *pos = self->first_visible_entry; | ||
453 | self->first_visible_entry = pos->next; | ||
454 | } | ||
455 | |||
456 | break; | 482 | break; |
457 | case NEWT_KEY_PGUP: | 483 | case NEWT_KEY_PGUP: |
458 | if (self->first_visible_entry_idx == 0) | 484 | if (self->first_visible_entry_idx == 0) |
@@ -465,29 +491,19 @@ static int ui_browser__run(struct ui_browser *self, const char *title, | |||
465 | 491 | ||
466 | self->index -= offset; | 492 | self->index -= offset; |
467 | self->first_visible_entry_idx -= offset; | 493 | self->first_visible_entry_idx -= offset; |
468 | 494 | self->seek(self, -offset, SEEK_CUR); | |
469 | while (offset--) { | ||
470 | struct list_head *pos = self->first_visible_entry; | ||
471 | self->first_visible_entry = pos->prev; | ||
472 | } | ||
473 | break; | 495 | break; |
474 | case NEWT_KEY_HOME: | 496 | case NEWT_KEY_HOME: |
475 | ui_browser__reset_index(self); | 497 | ui_browser__reset_index(self); |
476 | break; | 498 | break; |
477 | case NEWT_KEY_END: { | 499 | case NEWT_KEY_END: |
478 | struct list_head *head = self->entries; | ||
479 | offset = self->height - 1; | 500 | offset = self->height - 1; |
480 | 501 | ||
481 | if (offset > self->nr_entries) | 502 | if (offset > self->nr_entries) |
482 | offset = self->nr_entries; | 503 | offset = self->nr_entries; |
483 | 504 | ||
484 | self->index = self->first_visible_entry_idx = self->nr_entries - 1 - offset; | 505 | self->index = self->first_visible_entry_idx = self->nr_entries - 1 - offset; |
485 | self->first_visible_entry = head->prev; | 506 | self->seek(self, -offset, SEEK_END); |
486 | while (offset-- != 0) { | ||
487 | struct list_head *pos = self->first_visible_entry; | ||
488 | self->first_visible_entry = pos->prev; | ||
489 | } | ||
490 | } | ||
491 | break; | 507 | break; |
492 | case NEWT_KEY_RIGHT: | 508 | case NEWT_KEY_RIGHT: |
493 | case NEWT_KEY_LEFT: | 509 | case NEWT_KEY_LEFT: |
@@ -706,7 +722,8 @@ int hist_entry__tui_annotate(struct hist_entry *self) | |||
706 | ui_helpline__push("Press <- or ESC to exit"); | 722 | ui_helpline__push("Press <- or ESC to exit"); |
707 | 723 | ||
708 | memset(&browser, 0, sizeof(browser)); | 724 | memset(&browser, 0, sizeof(browser)); |
709 | browser.entries = &head; | 725 | browser.entries = &head; |
726 | browser.seek = ui_browser__list_head_seek; | ||
710 | browser.priv = self; | 727 | browser.priv = self; |
711 | list_for_each_entry(pos, &head, node) { | 728 | list_for_each_entry(pos, &head, node) { |
712 | size_t line_len = strlen(pos->line); | 729 | size_t line_len = strlen(pos->line); |