Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 205280
b: refs/heads/master
c: 46b0a07
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed Jun 21, 2010
1 parent 90c2a02 commit bd3d853
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8c694d2559acf09bfd8b71fe1795e740063ad803
refs/heads/master: 46b0a07a45b07ed5ca8053bbb6ec522982d1a1dd
69 changes: 43 additions & 26 deletions trunk/tools/perf/util/newt.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,42 @@ struct ui_browser {
void *first_visible_entry, *entries;
u16 top, left, width, height;
void *priv;
void (*seek)(struct ui_browser *self,
off_t offset, int whence);
u32 nr_entries;
};

static void ui_browser__list_head_seek(struct ui_browser *self,
off_t offset, int whence)
{
struct list_head *head = self->entries;
struct list_head *pos;

switch (whence) {
case SEEK_SET:
pos = head->next;
break;
case SEEK_CUR:
pos = self->first_visible_entry;
break;
case SEEK_END:
pos = head->prev;
break;
default:
return;
}

if (offset > 0) {
while (offset-- != 0)
pos = pos->next;
} else {
while (offset++ != 0)
pos = pos->prev;
}

self->first_visible_entry = pos;
}

static bool ui_browser__is_current_entry(struct ui_browser *self, unsigned row)
{
return (self->first_visible_entry_idx + row) == self->index;
Expand All @@ -292,7 +325,7 @@ static void ui_browser__refresh_dimensions(struct ui_browser *self)
static void ui_browser__reset_index(struct ui_browser *self)
{
self->index = self->first_visible_entry_idx = 0;
self->first_visible_entry = NULL;
self->seek(self, 0, SEEK_SET);
}

static int objdump_line__show(struct objdump_line *self, struct list_head *head,
Expand Down Expand Up @@ -408,7 +441,7 @@ static int ui_browser__run(struct ui_browser *self, const char *title,
newtFormAddComponent(self->form, self->sb);

while (1) {
unsigned int offset;
off_t offset;

newtFormRun(self->form, es);

Expand All @@ -422,19 +455,17 @@ static int ui_browser__run(struct ui_browser *self, const char *title,
break;
++self->index;
if (self->index == self->first_visible_entry_idx + self->height) {
struct list_head *pos = self->first_visible_entry;
++self->first_visible_entry_idx;
self->first_visible_entry = pos->next;
self->seek(self, +1, SEEK_CUR);
}
break;
case NEWT_KEY_UP:
if (self->index == 0)
break;
--self->index;
if (self->index < self->first_visible_entry_idx) {
struct list_head *pos = self->first_visible_entry;
--self->first_visible_entry_idx;
self->first_visible_entry = pos->prev;
self->seek(self, -1, SEEK_CUR);
}
break;
case NEWT_KEY_PGDN:
Expand All @@ -447,12 +478,7 @@ static int ui_browser__run(struct ui_browser *self, const char *title,
offset = self->nr_entries - 1 - self->index;
self->index += offset;
self->first_visible_entry_idx += offset;

while (offset--) {
struct list_head *pos = self->first_visible_entry;
self->first_visible_entry = pos->next;
}

self->seek(self, +offset, SEEK_CUR);
break;
case NEWT_KEY_PGUP:
if (self->first_visible_entry_idx == 0)
Expand All @@ -465,29 +491,19 @@ static int ui_browser__run(struct ui_browser *self, const char *title,

self->index -= offset;
self->first_visible_entry_idx -= offset;

while (offset--) {
struct list_head *pos = self->first_visible_entry;
self->first_visible_entry = pos->prev;
}
self->seek(self, -offset, SEEK_CUR);
break;
case NEWT_KEY_HOME:
ui_browser__reset_index(self);
break;
case NEWT_KEY_END: {
struct list_head *head = self->entries;
case NEWT_KEY_END:
offset = self->height - 1;

if (offset > self->nr_entries)
offset = self->nr_entries;

self->index = self->first_visible_entry_idx = self->nr_entries - 1 - offset;
self->first_visible_entry = head->prev;
while (offset-- != 0) {
struct list_head *pos = self->first_visible_entry;
self->first_visible_entry = pos->prev;
}
}
self->seek(self, -offset, SEEK_END);
break;
case NEWT_KEY_RIGHT:
case NEWT_KEY_LEFT:
Expand Down Expand Up @@ -706,7 +722,8 @@ int hist_entry__tui_annotate(struct hist_entry *self)
ui_helpline__push("Press <- or ESC to exit");

memset(&browser, 0, sizeof(browser));
browser.entries = &head;
browser.entries = &head;
browser.seek = ui_browser__list_head_seek;
browser.priv = self;
list_for_each_entry(pos, &head, node) {
size_t line_len = strlen(pos->line);
Expand Down

0 comments on commit bd3d853

Please sign in to comment.