7 #include <sys/ttydefaults.h>
15 static void newt_form__set_exit_keys(newtComponent self)
17 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
18 newtFormAddHotKey(self, 'Q');
19 newtFormAddHotKey(self, 'q');
20 newtFormAddHotKey(self, CTRL('c'));
23 static newtComponent newt_form__new(void)
25 newtComponent self = newtForm(NULL, NULL, 0);
27 newt_form__set_exit_keys(self);
31 static size_t hist_entry__append_browser(struct hist_entry *self,
32 newtComponent listbox, u64 total)
38 if (symbol_conf.exclude_other && !self->parent)
41 fp = fmemopen(bf, sizeof(bf), "w");
45 len = hist_entry__fprintf(self, NULL, false, 0, fp, total);
48 newtListboxAppendEntry(listbox, bf, self);
52 static void hist_entry__annotate_browser(struct hist_entry *self)
56 newtComponent form, listbox;
57 struct newtExitStruct es;
59 size_t line_len, max_line_len = 0;
60 size_t max_usable_width;
63 if (self->sym == NULL)
66 if (asprintf(&str, "perf annotate %s 2>&1 | expand", self->sym->name) < 0)
73 newtPushHelpLine("Press ESC to exit");
74 newtGetScreenSize(&cols, &rows);
75 listbox = newtListbox(0, 0, rows - 5, NEWT_FLAG_SCROLL);
78 if (getline(&line, &line_len, fp) < 0 || !line_len)
80 while (line_len != 0 && isspace(line[line_len - 1]))
81 line[--line_len] = '\0';
83 if (line_len > max_line_len)
84 max_line_len = line_len;
85 newtListboxAppendEntry(listbox, line, NULL);
90 max_usable_width = cols - 22;
91 if (max_line_len > max_usable_width)
92 max_line_len = max_usable_width;
94 newtListboxSetWidth(listbox, max_line_len);
96 newtCenteredWindow(max_line_len + 2, rows - 5, self->sym->name);
97 form = newt_form__new();
98 newtFormAddComponents(form, listbox, NULL);
100 newtFormRun(form, &es);
101 newtFormDestroy(form);
108 void perf_session__browse_hists(struct rb_root *hists, u64 session_total,
109 const char *helpline)
111 struct sort_entry *se;
114 char *col_width = symbol_conf.col_width_list_str;
118 newtComponent form, listbox;
119 struct newtExitStruct es;
121 snprintf(str, sizeof(str), "Samples: %Ld", session_total);
122 newtDrawRootText(0, 0, str);
123 newtPushHelpLine(helpline);
125 newtGetScreenSize(NULL, &rows);
127 form = newt_form__new();
129 listbox = newtListbox(1, 1, rows - 2, (NEWT_FLAG_SCROLL |
131 NEWT_FLAG_RETURNEXIT));
133 list_for_each_entry(se, &hist_entry__sort_list, list) {
136 width = strlen(se->header);
138 if (symbol_conf.col_width_list_str) {
140 *se->width = atoi(col_width);
141 col_width = strchr(col_width, ',');
146 *se->width = max(*se->width, width);
150 for (nd = rb_first(hists); nd; nd = rb_next(nd)) {
151 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
152 size_t len = hist_entry__append_browser(h, listbox, session_total);
157 newtListboxSetWidth(listbox, max_len);
158 newtFormAddComponents(form, listbox, NULL);
161 struct hist_entry *selection;
163 newtFormRun(form, &es);
164 if (es.reason == NEWT_EXIT_HOTKEY)
166 selection = newtListboxGetCurrent(listbox);
167 hist_entry__annotate_browser(selection);
170 newtFormDestroy(form);
173 int browser__show_help(const char *format, va_list ap)
177 static char msg[1024];
179 ret = vsnprintf(msg + backlog, sizeof(msg) - backlog, format, ap);
182 if (msg[backlog - 1] == '\n') {
184 newtPushHelpLine(msg);
192 void setup_browser(void)
200 newtPushHelpLine(" ");
203 void exit_browser(void)