perf ui browser: Optional horizontal scrolling key binding

If the classes derived from ui_browser want to do some sort of
horizontal scrolling, they have just to set ui_browser->columns to
the number of columns available.

Those columns can be the number of characters on the screen, if what is
desired is to scroll character by character, or the number of columns in
a spreadsheet like table.

This is what the hist_browser will do, skipping ui_browser->horiz_scroll
columns when rendering each of its lines.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-q6a22bpmpgcr1awgzrmd4jrs@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent def02db0
...@@ -393,6 +393,7 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs) ...@@ -393,6 +393,7 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs)
if (browser->use_navkeypressed && !browser->navkeypressed) { if (browser->use_navkeypressed && !browser->navkeypressed) {
if (key == K_DOWN || key == K_UP || if (key == K_DOWN || key == K_UP ||
(browser->columns && (key == K_LEFT || key == K_RIGHT)) ||
key == K_PGDN || key == K_PGUP || key == K_PGDN || key == K_PGUP ||
key == K_HOME || key == K_END || key == K_HOME || key == K_END ||
key == ' ') { key == ' ') {
...@@ -421,6 +422,18 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs) ...@@ -421,6 +422,18 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs)
browser->seek(browser, -1, SEEK_CUR); browser->seek(browser, -1, SEEK_CUR);
} }
break; break;
case K_RIGHT:
if (!browser->columns)
goto out;
if (browser->horiz_scroll < browser->columns - 1)
++browser->horiz_scroll;
break;
case K_LEFT:
if (!browser->columns)
goto out;
if (browser->horiz_scroll != 0)
--browser->horiz_scroll;
break;
case K_PGDN: case K_PGDN:
case ' ': case ' ':
if (browser->top_idx + browser->rows > browser->nr_entries - 1) if (browser->top_idx + browser->rows > browser->nr_entries - 1)
...@@ -459,6 +472,7 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs) ...@@ -459,6 +472,7 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs)
browser->seek(browser, -offset, SEEK_END); browser->seek(browser, -offset, SEEK_END);
break; break;
default: default:
out:
return key; return key;
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
struct ui_browser { struct ui_browser {
u64 index, top_idx; u64 index, top_idx;
void *top, *entries; void *top, *entries;
u16 y, x, width, height, rows; u16 y, x, width, height, rows, columns, horiz_scroll;
int current_color; int current_color;
void *priv; void *priv;
const char *title; const char *title;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment