1 // SPDX-License-Identifier: GPL-2.0
2 #include "util/cache.h"
3 #include "util/debug.h"
4 #include "ui/browser.h"
5 #include "ui/keysyms.h"
8 #include "ui/libslang.h"
9 #include "util/header.h"
10 #include "util/session.h"
12 #include <sys/ttydefaults.h>
14 static void ui_browser__argv_write(struct ui_browser *browser,
20 bool current_entry = ui_browser__is_current_entry(browser, row);
21 unsigned long offset = (unsigned long)browser->priv;
23 if (offset >= strlen(str))
28 ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
31 ui_browser__write_nstring(browser, str, browser->width);
34 static int list_menu__run(struct ui_browser *menu)
39 "h/?/F1 Show this window\n"
42 "LEFT/RIGHT Navigate\n"
43 "q/ESC/CTRL+C Exit browser";
45 if (ui_browser__show(menu, "Header information", "Press 'q' to exit") < 0)
49 key = ui_browser__run(menu, 0);
53 offset = (unsigned long)menu->priv;
55 menu->priv = (void *)offset;
58 offset = (unsigned long)menu->priv;
61 menu->priv = (void *)offset;
66 ui_browser__help_window(menu, help);
80 ui_browser__hide(menu);
84 static int ui__list_menu(int argc, char * const argv[])
86 struct ui_browser menu = {
87 .entries = (void *)argv,
88 .refresh = ui_browser__argv_refresh,
89 .seek = ui_browser__argv_seek,
90 .write = ui_browser__argv_write,
94 return list_menu__run(&menu);
97 int tui__header_window(struct perf_env *env)
101 struct perf_session *session;
104 FILE *fp = open_memstream(&ptr, &size);
106 session = container_of(env, struct perf_session, header.env);
107 perf_header__fprintf_info(session, fp, true);
110 for (pos = ptr, argc = 0; (pos = strchr(pos, '\n')) != NULL; pos++)
113 argv = calloc(argc + 1, sizeof(*argv));
118 for (i = 1; (pos = strchr(pos, '\n')) != NULL; i++) {
123 BUG_ON(i != argc + 1);
125 ui__list_menu(argc, argv);