aboutsummaryrefslogtreecommitdiff
path: root/tools/perf/util/ui/util.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-10-26 08:00:55 -0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-10-26 13:06:36 -0200
commitae55795ef2d9ba71d46e4111b87a4d0cde93abea (patch)
treedcd1afdaa5942cb661774f4c4b96353327ae1f28 /tools/perf/util/ui/util.c
parent1056d3dd9416740ec7d31348ca5f55009dc06bf3 (diff)
perf ui: Reimplement the popup windows using libslang
Just another step in stopping the use of libnewt in perf. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-vtxnmz1t1807ykprapnk9njl@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
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 37e6fe081a5..ef9b79332fe 100644
--- a/tools/perf/util/ui/util.c
+++ b/tools/perf/util/ui/util.c
@@ -1,6 +1,5 @@
-#include <newt.h>
+#include "../util.h"
#include <signal.h>
-#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/ttydefaults.h>
@@ -12,6 +11,7 @@
#include "helpline.h"
#include "ui.h"
#include "util.h"
+#include "libslang.h"
static void ui_browser__argv_write(struct ui_browser *browser,
void *entry, int row)
@@ -56,23 +56,6 @@ static int popup_menu__run(struct ui_browser *menu)
return key;
}
-static void newt_form__set_exit_keys(newtComponent self)
-{
- newtFormAddHotKey(self, NEWT_KEY_LEFT);
- newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
- newtFormAddHotKey(self, 'Q');
- newtFormAddHotKey(self, 'q');
- newtFormAddHotKey(self, CTRL('c'));
-}
-
-static newtComponent newt_form__new(void)
-{
- newtComponent self = newtForm(NULL, NULL, 0);
- if (self)
- newt_form__set_exit_keys(self);
- return self;
-}
-
int ui__popup_menu(int argc, char * const argv[])
{
struct ui_browser menu = {
@@ -86,17 +69,13 @@ int ui__popup_menu(int argc, char * const argv[])
return popup_menu__run(&menu);
}
-int ui__help_window(const char *text)
+int ui__question_window(const char *title, const char *text,
+ const char *exit_msg, int delay_secs)
{
- struct newtExitStruct es;
- newtComponent tb, form = newt_form__new();
- int rc = -1;
+ int x, y;
int max_len = 0, nr_lines = 0;
const char *t;
- if (form == NULL)
- return -1;
-
t = text;
while (1) {
const char *sep = strchr(t, '\n');
@@ -113,28 +92,56 @@ int ui__help_window(const char *text)
t = sep + 1;
}
- tb = newtTextbox(0, 0, max_len, nr_lines, 0);
- if (tb == NULL)
- goto out_destroy_form;
-
- newtTextboxSetText(tb, text);
- newtFormAddComponent(form, tb);
- newtCenteredWindow(max_len, nr_lines, NULL);
- newtFormRun(form, &es);
- newtPopWindow();
- rc = 0;
-out_destroy_form:
- newtFormDestroy(form);
- return rc;
+ max_len += 2;
+ nr_lines += 4;
+ y = SLtt_Screen_Rows / 2 - nr_lines / 2,
+ x = SLtt_Screen_Cols / 2 - max_len / 2;
+
+ SLsmg_set_color(0);
+ SLsmg_draw_box(y, x++, nr_lines, max_len);
+ if (title) {
+ SLsmg_gotorc(y, x + 1);
+ SLsmg_write_string((char *)title);
+ }
+ SLsmg_gotorc(++y, x);
+ nr_lines -= 2;
+ max_len -= 2;
+ SLsmg_write_wrapped_string((unsigned char *)text, y, x,
+ nr_lines, max_len, 1);
+ SLsmg_gotorc(y + nr_lines - 2, x);
+ SLsmg_write_nstring((char *)" ", max_len);
+ SLsmg_gotorc(y + nr_lines - 1, x);
+ SLsmg_write_nstring((char *)exit_msg, max_len);
+ SLsmg_refresh();
+ return ui__getch(delay_secs);
}
-static const char yes[] = "Yes", no[] = "No",
- warning_str[] = "Warning!", ok[] = "Ok";
+int ui__help_window(const char *text)
+{
+ return ui__question_window("Help", text, "Press any key...", 0);
+}
bool ui__dialog_yesno(const char *msg)
{
- /* newtWinChoice should really be accepting const char pointers... */
- return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1;
+ int answer = ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0);
+
+ return answer == K_ENTER;
+}
+
+static void __ui__warning(const char *title, const char *format, va_list args)
+{
+ char *s;
+
+ if (use_browser > 0 && vasprintf(&s, format, args) > 0) {
+ pthread_mutex_lock(&ui__lock);
+ ui__question_window(title, s, "Press any key...", 0);
+ pthread_mutex_unlock(&ui__lock);
+ free(s);
+ return;
+ }
+
+ fprintf(stderr, "%s:\n", title);
+ vfprintf(stderr, format, args);
}
void ui__warning(const char *format, ...)
@@ -142,12 +149,15 @@ void ui__warning(const char *format, ...)
va_list args;
va_start(args, format);
- if (use_browser > 0) {
- pthread_mutex_lock(&ui__lock);
- newtWinMessagev((char *)warning_str, (char *)ok,
- (char *)format, args);
- pthread_mutex_unlock(&ui__lock);
- } else
- vfprintf(stderr, format, args);
+ __ui__warning("Warning", format, args);
+ va_end(args);
+}
+
+void ui__error(const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ __ui__warning("Error", format, args);
va_end(args);
}