3 #include "../../perf.h"
8 #include <linux/compiler.h>
9 #include <linux/list.h>
10 #include <linux/rbtree.h>
12 #include <sys/ttydefaults.h>
18 static int ui_browser__percent_color(
struct ui_browser *browser,
34 SLsmg_set_color(color);
39 double percent,
bool current)
41 int color = ui_browser__percent_color(browser, percent, current);
47 SLsmg_gotorc(browser->
y + y, browser->
x + x);
51 ui_browser__list_head_filter_entries(
struct ui_browser *browser,
58 }
while (pos != browser->
entries);
64 ui_browser__list_head_filter_prev_entries(
struct ui_browser *browser,
71 }
while (pos != browser->
entries);
86 pos = ui_browser__list_head_filter_entries(browser, head->
next);
92 pos = ui_browser__list_head_filter_prev_entries(browser, head->
prev);
101 while (offset-- != 0)
102 pos = ui_browser__list_head_filter_entries(browser, pos->
next);
104 while (offset++ != 0)
105 pos = ui_browser__list_head_filter_prev_entries(browser, pos->
prev);
131 while (offset-- != 0)
134 while (offset++ != 0)
153 browser->
write(browser, nd, row);
154 if (++row == browser->
height)
169 browser->
width = SLtt_Screen_Cols - 1;
170 browser->
height = SLtt_Screen_Rows - 2;
190 err = vasprintf(&text, format, args);
249 const char *helpline, ...)
259 browser->
title = title;
264 err = vasprintf(&browser->
helpline, helpline, ap);
279 static void ui_browser__scrollbar_set(
struct ui_browser *browser)
282 col = browser->
width,
283 row = browser->
y - 1;
290 SLsmg_set_char_set(1);
294 SLsmg_write_char(
h == pct ? SLSMG_DIAMOND_CHAR : SLSMG_CKBRD_CHAR);
298 SLsmg_set_char_set(0);
301 static int __ui_browser__refresh(
struct ui_browser *browser)
306 row = browser->
refresh(browser);
310 ui_browser__scrollbar_set(browser);
314 SLsmg_fill_region(browser->
y + row, browser->
x,
315 browser->
height - row, width,
' ');
323 __ui_browser__refresh(browser);
361 err = __ui_browser__refresh(browser);
399 if (browser->
index == 0)
436 offset = browser->
height - 1;
458 browser->
top = ui_browser__list_head_filter_entries(browser, head->
next);
463 if (!browser->
filter || !browser->
filter(browser, pos)) {
465 browser->
write(browser, pos, row);
466 if (++row == browser->
height)
474 static struct ui_browser__colorset {
475 const char *
name, *fg, *
bg;
477 } ui_browser__colorsets[] = {
520 static int ui_browser__color_config(
const char *var,
const char *
value,
530 for (i = 0; ui_browser__colorsets[
i].name !=
NULL; ++
i) {
531 const char *
name = var + 7;
533 if (
strcmp(ui_browser__colorsets[i].name, name) != 0)
546 ui_browser__colorsets[
i].bg =
bg;
547 ui_browser__colorsets[
i].fg = fg;
580 pos = (
char **)browser->
top;
581 while (idx < browser->nr_entries) {
582 if (!browser->
filter || !browser->
filter(browser, *pos)) {
584 browser->
write(browser, pos, row);
585 if (++row == browser->
height)
599 SLsmg_set_char_set(1);
601 SLsmg_draw_vline(end - start + 1);
602 SLsmg_set_char_set(0);
608 SLsmg_set_char_set(1);
609 SLsmg_write_char(graph);
610 SLsmg_set_char_set(0);
613 static void __ui_browser__line_arrow_up(
struct ui_browser *browser,
617 unsigned int row, end_row;
619 SLsmg_set_char_set(1);
621 if (start < browser->top_idx + browser->
height) {
622 row = start - browser->
top_idx;
624 SLsmg_write_char(SLSMG_LLCORN_CHAR);
631 row = browser->
height - 1;
634 end_row = end - browser->
top_idx;
639 SLsmg_draw_vline(row - end_row + 1);
643 SLsmg_write_char(SLSMG_ULCORN_CHAR);
645 SLsmg_write_char(SLSMG_HLINE_CHAR);
647 SLsmg_write_char(SLSMG_RARROW_CHAR);
650 SLsmg_set_char_set(0);
653 static void __ui_browser__line_arrow_down(
struct ui_browser *browser,
657 unsigned int row, end_row;
659 SLsmg_set_char_set(1);
661 if (start >= browser->
top_idx) {
662 row = start - browser->
top_idx;
664 SLsmg_write_char(SLSMG_ULCORN_CHAR);
674 end_row = browser->
height - 1;
676 end_row = end - browser->
top_idx;;
679 SLsmg_draw_vline(end_row - row + 1);
682 if (end < browser->top_idx + browser->
height) {
683 SLsmg_write_char(SLSMG_LLCORN_CHAR);
685 SLsmg_write_char(SLSMG_HLINE_CHAR);
687 SLsmg_write_char(SLSMG_RARROW_CHAR);
690 SLsmg_set_char_set(0);
697 __ui_browser__line_arrow_up(browser, column, start, end);
699 __ui_browser__line_arrow_down(browser, column, start, end);
708 while (ui_browser__colorsets[i].name) {
709 struct ui_browser__colorset *
c = &ui_browser__colorsets[i++];