hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/perf/ui/tui/util.c
....@@ -1,12 +1,10 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-#include "../../util/util.h"
32 #include <signal.h>
43 #include <stdbool.h>
54 #include <string.h>
5
+#include <stdlib.h>
66 #include <sys/ttydefaults.h>
77
8
-#include "../../util/cache.h"
9
-#include "../../util/debug.h"
108 #include "../browser.h"
119 #include "../keysyms.h"
1210 #include "../helpline.h"
....@@ -25,7 +23,7 @@
2523 ui_browser__write_nstring(browser, *arg, browser->width);
2624 }
2725
28
-static int popup_menu__run(struct ui_browser *menu)
26
+static int popup_menu__run(struct ui_browser *menu, int *keyp)
2927 {
3028 int key;
3129
....@@ -47,6 +45,11 @@
4745 key = -1;
4846 break;
4947 default:
48
+ if (keyp) {
49
+ *keyp = key;
50
+ key = menu->nr_entries;
51
+ break;
52
+ }
5053 continue;
5154 }
5255
....@@ -57,7 +60,7 @@
5760 return key;
5861 }
5962
60
-int ui__popup_menu(int argc, char * const argv[])
63
+int ui__popup_menu(int argc, char * const argv[], int *keyp)
6164 {
6265 struct ui_browser menu = {
6366 .entries = (void *)argv,
....@@ -66,8 +69,7 @@
6669 .write = ui_browser__argv_write,
6770 .nr_entries = argc,
6871 };
69
-
70
- return popup_menu__run(&menu);
72
+ return popup_menu__run(&menu, keyp);
7173 }
7274
7375 int ui_browser__input_window(const char *title, const char *text, char *input,
....@@ -162,8 +164,7 @@
162164 return key;
163165 }
164166
165
-int ui__question_window(const char *title, const char *text,
166
- const char *exit_msg, int delay_secs)
167
+void __ui__info_window(const char *title, const char *text, const char *exit_msg)
167168 {
168169 int x, y;
169170 int max_len = 0, nr_lines = 0;
....@@ -185,10 +186,10 @@
185186 t = sep + 1;
186187 }
187188
188
- pthread_mutex_lock(&ui__lock);
189
-
190189 max_len += 2;
191
- nr_lines += 4;
190
+ nr_lines += 2;
191
+ if (exit_msg)
192
+ nr_lines += 2;
192193 y = SLtt_Screen_Rows / 2 - nr_lines / 2,
193194 x = SLtt_Screen_Cols / 2 - max_len / 2;
194195
....@@ -199,18 +200,34 @@
199200 SLsmg_write_string((char *)title);
200201 }
201202 SLsmg_gotorc(++y, x);
202
- nr_lines -= 2;
203
+ if (exit_msg)
204
+ nr_lines -= 2;
203205 max_len -= 2;
204206 SLsmg_write_wrapped_string((unsigned char *)text, y, x,
205207 nr_lines, max_len, 1);
206
- SLsmg_gotorc(y + nr_lines - 2, x);
207
- SLsmg_write_nstring((char *)" ", max_len);
208
- SLsmg_gotorc(y + nr_lines - 1, x);
209
- SLsmg_write_nstring((char *)exit_msg, max_len);
208
+ if (exit_msg) {
209
+ SLsmg_gotorc(y + nr_lines - 2, x);
210
+ SLsmg_write_nstring((char *)" ", max_len);
211
+ SLsmg_gotorc(y + nr_lines - 1, x);
212
+ SLsmg_write_nstring((char *)exit_msg, max_len);
213
+ }
214
+}
215
+
216
+void ui__info_window(const char *title, const char *text)
217
+{
218
+ pthread_mutex_lock(&ui__lock);
219
+ __ui__info_window(title, text, NULL);
210220 SLsmg_refresh();
211
-
212221 pthread_mutex_unlock(&ui__lock);
222
+}
213223
224
+int ui__question_window(const char *title, const char *text,
225
+ const char *exit_msg, int delay_secs)
226
+{
227
+ pthread_mutex_lock(&ui__lock);
228
+ __ui__info_window(title, text, exit_msg);
229
+ SLsmg_refresh();
230
+ pthread_mutex_unlock(&ui__lock);
214231 return ui__getch(delay_secs);
215232 }
216233