aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/ui/browser.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/ui/browser.c')
-rw-r--r--tools/perf/util/ui/browser.c137
1 files changed, 82 insertions, 55 deletions
diff --git a/tools/perf/util/ui/browser.c b/tools/perf/util/ui/browser.c
index 66f2d583d8c4..611219f80680 100644
--- a/tools/perf/util/ui/browser.c
+++ b/tools/perf/util/ui/browser.c
@@ -1,16 +1,6 @@
1#define _GNU_SOURCE 1#include "libslang.h"
2#include <stdio.h> 2#include "ui.h"
3#undef _GNU_SOURCE 3#include <linux/compiler.h>
4/*
5 * slang versions <= 2.0.6 have a "#if HAVE_LONG_LONG" that breaks
6 * the build if it isn't defined. Use the equivalent one that glibc
7 * has on features.h.
8 */
9#include <features.h>
10#ifndef HAVE_LONG_LONG
11#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
12#endif
13#include <slang.h>
14#include <linux/list.h> 4#include <linux/list.h>
15#include <linux/rbtree.h> 5#include <linux/rbtree.h>
16#include <stdlib.h> 6#include <stdlib.h>
@@ -19,17 +9,9 @@
19#include "helpline.h" 9#include "helpline.h"
20#include "../color.h" 10#include "../color.h"
21#include "../util.h" 11#include "../util.h"
12#include <stdio.h>
22 13
23#if SLANG_VERSION < 20104 14static int ui_browser__percent_color(double percent, bool current)
24#define sltt_set_color(obj, name, fg, bg) \
25 SLtt_set_color(obj,(char *)name, (char *)fg, (char *)bg)
26#else
27#define sltt_set_color SLtt_set_color
28#endif
29
30newtComponent newt_form__new(void);
31
32int ui_browser__percent_color(double percent, bool current)
33{ 15{
34 if (current) 16 if (current)
35 return HE_COLORSET_SELECTED; 17 return HE_COLORSET_SELECTED;
@@ -40,6 +22,23 @@ int ui_browser__percent_color(double percent, bool current)
40 return HE_COLORSET_NORMAL; 22 return HE_COLORSET_NORMAL;
41} 23}
42 24
25void ui_browser__set_color(struct ui_browser *self __used, int color)
26{
27 SLsmg_set_color(color);
28}
29
30void ui_browser__set_percent_color(struct ui_browser *self,
31 double percent, bool current)
32{
33 int color = ui_browser__percent_color(percent, current);
34 ui_browser__set_color(self, color);
35}
36
37void ui_browser__gotorc(struct ui_browser *self, int y, int x)
38{
39 SLsmg_gotorc(self->y + y, self->x + x);
40}
41
43void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence) 42void ui_browser__list_head_seek(struct ui_browser *self, off_t offset, int whence)
44{ 43{
45 struct list_head *head = self->entries; 44 struct list_head *head = self->entries;
@@ -111,7 +110,7 @@ unsigned int ui_browser__rb_tree_refresh(struct ui_browser *self)
111 nd = self->top; 110 nd = self->top;
112 111
113 while (nd != NULL) { 112 while (nd != NULL) {
114 SLsmg_gotorc(self->y + row, self->x); 113 ui_browser__gotorc(self, row, 0);
115 self->write(self, nd, row); 114 self->write(self, nd, row);
116 if (++row == self->height) 115 if (++row == self->height)
117 break; 116 break;
@@ -131,13 +130,10 @@ void ui_browser__refresh_dimensions(struct ui_browser *self)
131 int cols, rows; 130 int cols, rows;
132 newtGetScreenSize(&cols, &rows); 131 newtGetScreenSize(&cols, &rows);
133 132
134 if (self->width > cols - 4) 133 self->width = cols - 1;
135 self->width = cols - 4; 134 self->height = rows - 2;
136 self->height = rows - 5; 135 self->y = 1;
137 if (self->height > self->nr_entries) 136 self->x = 0;
138 self->height = self->nr_entries;
139 self->y = (rows - self->height) / 2;
140 self->x = (cols - self->width) / 2;
141} 137}
142 138
143void ui_browser__reset_index(struct ui_browser *self) 139void ui_browser__reset_index(struct ui_browser *self)
@@ -146,78 +142,109 @@ void ui_browser__reset_index(struct ui_browser *self)
146 self->seek(self, 0, SEEK_SET); 142 self->seek(self, 0, SEEK_SET);
147} 143}
148 144
145void ui_browser__add_exit_key(struct ui_browser *self, int key)
146{
147 newtFormAddHotKey(self->form, key);
148}
149
150void ui_browser__add_exit_keys(struct ui_browser *self, int keys[])
151{
152 int i = 0;
153
154 while (keys[i] && i < 64) {
155 ui_browser__add_exit_key(self, keys[i]);
156 ++i;
157 }
158}
159
160void __ui_browser__show_title(struct ui_browser *browser, const char *title)
161{
162 SLsmg_gotorc(0, 0);
163 ui_browser__set_color(browser, NEWT_COLORSET_ROOT);
164 slsmg_write_nstring(title, browser->width);
165}
166
167void ui_browser__show_title(struct ui_browser *browser, const char *title)
168{
169 pthread_mutex_lock(&ui__lock);
170 __ui_browser__show_title(browser, title);
171 pthread_mutex_unlock(&ui__lock);
172}
173
149int ui_browser__show(struct ui_browser *self, const char *title, 174int ui_browser__show(struct ui_browser *self, const char *title,
150 const char *helpline, ...) 175 const char *helpline, ...)
151{ 176{
152 va_list ap; 177 va_list ap;
178 int keys[] = { NEWT_KEY_UP, NEWT_KEY_DOWN, NEWT_KEY_PGUP,
179 NEWT_KEY_PGDN, NEWT_KEY_HOME, NEWT_KEY_END, ' ',
180 NEWT_KEY_LEFT, NEWT_KEY_ESCAPE, 'q', CTRL('c'), 0 };
153 181
154 if (self->form != NULL) { 182 if (self->form != NULL)
155 newtFormDestroy(self->form); 183 newtFormDestroy(self->form);
156 newtPopWindow(); 184
157 }
158 ui_browser__refresh_dimensions(self); 185 ui_browser__refresh_dimensions(self);
159 newtCenteredWindow(self->width, self->height, title); 186 self->form = newtForm(NULL, NULL, 0);
160 self->form = newt_form__new();
161 if (self->form == NULL) 187 if (self->form == NULL)
162 return -1; 188 return -1;
163 189
164 self->sb = newtVerticalScrollbar(self->width, 0, self->height, 190 self->sb = newtVerticalScrollbar(self->width, 1, self->height,
165 HE_COLORSET_NORMAL, 191 HE_COLORSET_NORMAL,
166 HE_COLORSET_SELECTED); 192 HE_COLORSET_SELECTED);
167 if (self->sb == NULL) 193 if (self->sb == NULL)
168 return -1; 194 return -1;
169 195
170 newtFormAddHotKey(self->form, NEWT_KEY_UP); 196 pthread_mutex_lock(&ui__lock);
171 newtFormAddHotKey(self->form, NEWT_KEY_DOWN); 197 __ui_browser__show_title(self, title);
172 newtFormAddHotKey(self->form, NEWT_KEY_PGUP); 198
173 newtFormAddHotKey(self->form, NEWT_KEY_PGDN); 199 ui_browser__add_exit_keys(self, keys);
174 newtFormAddHotKey(self->form, NEWT_KEY_HOME);
175 newtFormAddHotKey(self->form, NEWT_KEY_END);
176 newtFormAddHotKey(self->form, ' ');
177 newtFormAddComponent(self->form, self->sb); 200 newtFormAddComponent(self->form, self->sb);
178 201
179 va_start(ap, helpline); 202 va_start(ap, helpline);
180 ui_helpline__vpush(helpline, ap); 203 ui_helpline__vpush(helpline, ap);
181 va_end(ap); 204 va_end(ap);
205 pthread_mutex_unlock(&ui__lock);
182 return 0; 206 return 0;
183} 207}
184 208
185void ui_browser__hide(struct ui_browser *self) 209void ui_browser__hide(struct ui_browser *self)
186{ 210{
211 pthread_mutex_lock(&ui__lock);
187 newtFormDestroy(self->form); 212 newtFormDestroy(self->form);
188 newtPopWindow();
189 self->form = NULL; 213 self->form = NULL;
190 ui_helpline__pop(); 214 ui_helpline__pop();
215 pthread_mutex_unlock(&ui__lock);
191} 216}
192 217
193int ui_browser__refresh(struct ui_browser *self) 218int ui_browser__refresh(struct ui_browser *self)
194{ 219{
195 int row; 220 int row;
196 221
222 pthread_mutex_lock(&ui__lock);
197 newtScrollbarSet(self->sb, self->index, self->nr_entries - 1); 223 newtScrollbarSet(self->sb, self->index, self->nr_entries - 1);
198 row = self->refresh(self); 224 row = self->refresh(self);
199 SLsmg_set_color(HE_COLORSET_NORMAL); 225 ui_browser__set_color(self, HE_COLORSET_NORMAL);
200 SLsmg_fill_region(self->y + row, self->x, 226 SLsmg_fill_region(self->y + row, self->x,
201 self->height - row, self->width, ' '); 227 self->height - row, self->width, ' ');
228 pthread_mutex_unlock(&ui__lock);
202 229
203 return 0; 230 return 0;
204} 231}
205 232
206int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es) 233int ui_browser__run(struct ui_browser *self)
207{ 234{
235 struct newtExitStruct es;
236
208 if (ui_browser__refresh(self) < 0) 237 if (ui_browser__refresh(self) < 0)
209 return -1; 238 return -1;
210 239
211 while (1) { 240 while (1) {
212 off_t offset; 241 off_t offset;
213 242
214 newtFormRun(self->form, es); 243 newtFormRun(self->form, &es);
215 244
216 if (es->reason != NEWT_EXIT_HOTKEY) 245 if (es.reason != NEWT_EXIT_HOTKEY)
217 break; 246 break;
218 if (is_exit_key(es->u.key)) 247 switch (es.u.key) {
219 return es->u.key;
220 switch (es->u.key) {
221 case NEWT_KEY_DOWN: 248 case NEWT_KEY_DOWN:
222 if (self->index == self->nr_entries - 1) 249 if (self->index == self->nr_entries - 1)
223 break; 250 break;
@@ -274,12 +301,12 @@ int ui_browser__run(struct ui_browser *self, struct newtExitStruct *es)
274 self->seek(self, -offset, SEEK_END); 301 self->seek(self, -offset, SEEK_END);
275 break; 302 break;
276 default: 303 default:
277 return es->u.key; 304 return es.u.key;
278 } 305 }
279 if (ui_browser__refresh(self) < 0) 306 if (ui_browser__refresh(self) < 0)
280 return -1; 307 return -1;
281 } 308 }
282 return 0; 309 return -1;
283} 310}
284 311
285unsigned int ui_browser__list_head_refresh(struct ui_browser *self) 312unsigned int ui_browser__list_head_refresh(struct ui_browser *self)
@@ -294,7 +321,7 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *self)
294 pos = self->top; 321 pos = self->top;
295 322
296 list_for_each_from(pos, head) { 323 list_for_each_from(pos, head) {
297 SLsmg_gotorc(self->y + row, self->x); 324 ui_browser__gotorc(self, row, 0);
298 self->write(self, pos, row); 325 self->write(self, pos, row);
299 if (++row == self->height) 326 if (++row == self->height)
300 break; 327 break;