aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/ui/util.c')
-rw-r--r--tools/perf/util/ui/util.c110
1 files changed, 60 insertions, 50 deletions
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c
index 37e6fe081a58..ef9b79332fe8 100644
--- a/tools/perf/util/ui/util.c
+++ b/tools/perf/util/ui/util.c
@@ -1,6 +1,5 @@
1#include <newt.h> 1#include "../util.h"
2#include <signal.h> 2#include <signal.h>
3#include <stdio.h>
4#include <stdbool.h> 3#include <stdbool.h>
5#include <string.h> 4#include <string.h>
6#include <sys/ttydefaults.h> 5#include <sys/ttydefaults.h>
@@ -12,6 +11,7 @@
12#include "helpline.h" 11#include "helpline.h"
13#include "ui.h" 12#include "ui.h"
14#include "util.h" 13#include "util.h"
14#include "libslang.h"
15 15
16static void ui_browser__argv_write(struct ui_browser *browser, 16static void ui_browser__argv_write(struct ui_browser *browser,
17 void *entry, int row) 17 void *entry, int row)
@@ -56,23 +56,6 @@ static int popup_menu__run(struct ui_browser *menu)
56 return key; 56 return key;
57} 57}
58 58
59static void newt_form__set_exit_keys(newtComponent self)
60{
61 newtFormAddHotKey(self, NEWT_KEY_LEFT);
62 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
63 newtFormAddHotKey(self, 'Q');
64 newtFormAddHotKey(self, 'q');
65 newtFormAddHotKey(self, CTRL('c'));
66}
67
68static newtComponent newt_form__new(void)
69{
70 newtComponent self = newtForm(NULL, NULL, 0);
71 if (self)
72 newt_form__set_exit_keys(self);
73 return self;
74}
75
76int ui__popup_menu(int argc, char * const argv[]) 59int ui__popup_menu(int argc, char * const argv[])
77{ 60{
78 struct ui_browser menu = { 61 struct ui_browser menu = {
@@ -86,17 +69,13 @@ int ui__popup_menu(int argc, char * const argv[])
86 return popup_menu__run(&menu); 69 return popup_menu__run(&menu);
87} 70}
88 71
89int ui__help_window(const char *text) 72int ui__question_window(const char *title, const char *text,
73 const char *exit_msg, int delay_secs)
90{ 74{
91 struct newtExitStruct es; 75 int x, y;
92 newtComponent tb, form = newt_form__new();
93 int rc = -1;
94 int max_len = 0, nr_lines = 0; 76 int max_len = 0, nr_lines = 0;
95 const char *t; 77 const char *t;
96 78
97 if (form == NULL)
98 return -1;
99
100 t = text; 79 t = text;
101 while (1) { 80 while (1) {
102 const char *sep = strchr(t, '\n'); 81 const char *sep = strchr(t, '\n');
@@ -113,28 +92,56 @@ int ui__help_window(const char *text)
113 t = sep + 1; 92 t = sep + 1;
114 } 93 }
115 94
116 tb = newtTextbox(0, 0, max_len, nr_lines, 0); 95 max_len += 2;
117 if (tb == NULL) 96 nr_lines += 4;
118 goto out_destroy_form; 97 y = SLtt_Screen_Rows / 2 - nr_lines / 2,
119 98 x = SLtt_Screen_Cols / 2 - max_len / 2;
120 newtTextboxSetText(tb, text); 99
121 newtFormAddComponent(form, tb); 100 SLsmg_set_color(0);
122 newtCenteredWindow(max_len, nr_lines, NULL); 101 SLsmg_draw_box(y, x++, nr_lines, max_len);
123 newtFormRun(form, &es); 102 if (title) {
124 newtPopWindow(); 103 SLsmg_gotorc(y, x + 1);
125 rc = 0; 104 SLsmg_write_string((char *)title);
126out_destroy_form: 105 }
127 newtFormDestroy(form); 106 SLsmg_gotorc(++y, x);
128 return rc; 107 nr_lines -= 2;
108 max_len -= 2;
109 SLsmg_write_wrapped_string((unsigned char *)text, y, x,
110 nr_lines, max_len, 1);
111 SLsmg_gotorc(y + nr_lines - 2, x);
112 SLsmg_write_nstring((char *)" ", max_len);
113 SLsmg_gotorc(y + nr_lines - 1, x);
114 SLsmg_write_nstring((char *)exit_msg, max_len);
115 SLsmg_refresh();
116 return ui__getch(delay_secs);
129} 117}
130 118
131static const char yes[] = "Yes", no[] = "No", 119int ui__help_window(const char *text)
132 warning_str[] = "Warning!", ok[] = "Ok"; 120{
121 return ui__question_window("Help", text, "Press any key...", 0);
122}
133 123
134bool ui__dialog_yesno(const char *msg) 124bool ui__dialog_yesno(const char *msg)
135{ 125{
136 /* newtWinChoice should really be accepting const char pointers... */ 126 int answer = ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0);
137 return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1; 127
128 return answer == K_ENTER;
129}
130
131static void __ui__warning(const char *title, const char *format, va_list args)
132{
133 char *s;
134
135 if (use_browser > 0 && vasprintf(&s, format, args) > 0) {
136 pthread_mutex_lock(&ui__lock);
137 ui__question_window(title, s, "Press any key...", 0);
138 pthread_mutex_unlock(&ui__lock);
139 free(s);
140 return;
141 }
142
143 fprintf(stderr, "%s:\n", title);
144 vfprintf(stderr, format, args);
138} 145}
139 146
140void ui__warning(const char *format, ...) 147void ui__warning(const char *format, ...)
@@ -142,12 +149,15 @@ void ui__warning(const char *format, ...)
142 va_list args; 149 va_list args;
143 150
144 va_start(args, format); 151 va_start(args, format);
145 if (use_browser > 0) { 152 __ui__warning("Warning", format, args);
146 pthread_mutex_lock(&ui__lock); 153 va_end(args);
147 newtWinMessagev((char *)warning_str, (char *)ok, 154}
148 (char *)format, args); 155
149 pthread_mutex_unlock(&ui__lock); 156void ui__error(const char *format, ...)
150 } else 157{
151 vfprintf(stderr, format, args); 158 va_list args;
159
160 va_start(args, format);
161 __ui__warning("Error", format, args);
152 va_end(args); 162 va_end(args);
153} 163}