1 #include "util/cache.h"
2 #include "util/debug.h"
3 #include "ui/browser.h"
4 #include "ui/keysyms.h"
7 #include "ui/libslang.h"
8 #include "util/header.h"
9 #include "util/session.h"
11 #include <sys/ttydefaults.h>
13 static void ui_browser__argv_write(struct ui_browser *browser,
19 bool current_entry = ui_browser__is_current_entry(browser, row);
20 unsigned long offset = (unsigned long)browser->priv;
22 if (offset >= strlen(str))
27 ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
30 ui_browser__write_nstring(browser, str, browser->width);
33 static int list_menu__run(struct ui_browser *menu)
38 "h/?/F1 Show this window\n"
41 "LEFT/RIGHT Navigate\n"
42 "q/ESC/CTRL+C Exit browser";
44 if (ui_browser__show(menu, "Header information", "Press 'q' to exit") < 0)
48 key = ui_browser__run(menu, 0);
52 offset = (unsigned long)menu->priv;
54 menu->priv = (void *)offset;
57 offset = (unsigned long)menu->priv;
60 menu->priv = (void *)offset;
65 ui_browser__help_window(menu, help);
79 ui_browser__hide(menu);
83 static int ui__list_menu(int argc, char * const argv[])
85 struct ui_browser menu = {
86 .entries = (void *)argv,
87 .refresh = ui_browser__argv_refresh,
88 .seek = ui_browser__argv_seek,
89 .write = ui_browser__argv_write,
93 return list_menu__run(&menu);
96 int tui__header_window(struct perf_env *env)
100 struct perf_session *session;
103 FILE *fp = open_memstream(&ptr, &size);
105 session = container_of(env, struct perf_session, header.env);
106 perf_header__fprintf_info(session, fp, true);
109 for (pos = ptr, argc = 0; (pos = strchr(pos, '\n')) != NULL; pos++)
112 argv = calloc(argc + 1, sizeof(*argv));
117 for (i = 1; (pos = strchr(pos, '\n')) != NULL; i++) {
122 BUG_ON(i != argc + 1);
124 ui__list_menu(argc, argv);