1 // SPDX-License-Identifier: GPL-2.0
2 #include "ui/browser.h"
3 #include "ui/keysyms.h"
6 #include "ui/libslang.h"
7 #include "util/header.h"
8 #include "util/session.h"
10 #include <sys/ttydefaults.h>
12 static void ui_browser__argv_write(struct ui_browser
*browser
,
18 bool current_entry
= ui_browser__is_current_entry(browser
, row
);
19 unsigned long offset
= (unsigned long)browser
->priv
;
21 if (offset
>= strlen(str
))
26 ui_browser__set_color(browser
, current_entry
? HE_COLORSET_SELECTED
:
29 ui_browser__write_nstring(browser
, str
, browser
->width
);
32 static int list_menu__run(struct ui_browser
*menu
)
36 static const char help
[] =
37 "h/?/F1 Show this window\n"
40 "LEFT/RIGHT Navigate\n"
41 "q/ESC/CTRL+C Exit browser";
43 if (ui_browser__show(menu
, "Header information", "Press 'q' to exit") < 0)
47 key
= ui_browser__run(menu
, 0);
51 offset
= (unsigned long)menu
->priv
;
53 menu
->priv
= (void *)offset
;
56 offset
= (unsigned long)menu
->priv
;
59 menu
->priv
= (void *)offset
;
64 ui_browser__help_window(menu
, help
);
78 ui_browser__hide(menu
);
82 static int ui__list_menu(int argc
, char * const argv
[])
84 struct ui_browser menu
= {
85 .entries
= (void *)argv
,
86 .refresh
= ui_browser__argv_refresh
,
87 .seek
= ui_browser__argv_seek
,
88 .write
= ui_browser__argv_write
,
92 return list_menu__run(&menu
);
95 int tui__header_window(struct perf_env
*env
)
99 struct perf_session
*session
;
102 FILE *fp
= open_memstream(&ptr
, &size
);
104 session
= container_of(env
, struct perf_session
, header
.env
);
105 perf_header__fprintf_info(session
, fp
, true);
108 for (pos
= ptr
, argc
= 0; (pos
= strchr(pos
, '\n')) != NULL
; pos
++)
111 argv
= calloc(argc
+ 1, sizeof(*argv
));
116 for (i
= 1; (pos
= strchr(pos
, '\n')) != NULL
; i
++) {
121 BUG_ON(i
!= argc
+ 1);
123 ui__list_menu(argc
, argv
);