diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-08-10 14:58:50 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-08-10 15:11:38 -0400 |
commit | 1e6dd077a880ba5570beb690523b7a78a91a7615 (patch) | |
tree | 979b2006c8c1b93dfe1f4e2152af5c5c4c7c6531 /tools/perf/util/ui | |
parent | d1b4f2491c3341c61c752049f73ba12553f978d8 (diff) |
perf ui: Complete the breakdown of util/newt.c
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/ui')
-rw-r--r-- | tools/perf/util/ui/browsers/annotate.c | 2 | ||||
-rw-r--r-- | tools/perf/util/ui/browsers/hists.c | 8 | ||||
-rw-r--r-- | tools/perf/util/ui/helpline.c | 26 | ||||
-rw-r--r-- | tools/perf/util/ui/helpline.h | 1 | ||||
-rw-r--r-- | tools/perf/util/ui/setup.c | 42 | ||||
-rw-r--r-- | tools/perf/util/ui/util.c | 114 | ||||
-rw-r--r-- | tools/perf/util/ui/util.h | 10 |
7 files changed, 196 insertions, 7 deletions
diff --git a/tools/perf/util/ui/browsers/annotate.c b/tools/perf/util/ui/browsers/annotate.c index 783d277f2190..5b01df633f9a 100644 --- a/tools/perf/util/ui/browsers/annotate.c +++ b/tools/perf/util/ui/browsers/annotate.c | |||
@@ -86,7 +86,7 @@ int hist_entry__tui_annotate(struct hist_entry *self) | |||
86 | return -1; | 86 | return -1; |
87 | 87 | ||
88 | if (hist_entry__annotate(self, &head) < 0) { | 88 | if (hist_entry__annotate(self, &head) < 0) { |
89 | ui__error_window(browser__last_msg); | 89 | ui__error_window(ui_helpline__last_msg); |
90 | return -1; | 90 | return -1; |
91 | } | 91 | } |
92 | 92 | ||
diff --git a/tools/perf/util/ui/browsers/hists.c b/tools/perf/util/ui/browsers/hists.c index 9d32a4149ab3..cee7998f1c33 100644 --- a/tools/perf/util/ui/browsers/hists.c +++ b/tools/perf/util/ui/browsers/hists.c | |||
@@ -17,10 +17,6 @@ | |||
17 | #include "../util.h" | 17 | #include "../util.h" |
18 | #include "map.h" | 18 | #include "map.h" |
19 | 19 | ||
20 | int ui__help_window(const char *text); | ||
21 | bool dialog_yesno(const char *msg); | ||
22 | int popup_menu(int argc, char * const argv[]); | ||
23 | |||
24 | struct hist_browser { | 20 | struct hist_browser { |
25 | struct ui_browser b; | 21 | struct ui_browser b; |
26 | struct hists *hists; | 22 | struct hists *hists; |
@@ -798,7 +794,7 @@ do_help: | |||
798 | } | 794 | } |
799 | if (is_exit_key(key)) { | 795 | if (is_exit_key(key)) { |
800 | if (key == NEWT_KEY_ESCAPE && | 796 | if (key == NEWT_KEY_ESCAPE && |
801 | !dialog_yesno("Do you really want to exit?")) | 797 | !ui__dialog_yesno("Do you really want to exit?")) |
802 | continue; | 798 | continue; |
803 | break; | 799 | break; |
804 | } | 800 | } |
@@ -842,7 +838,7 @@ do_help: | |||
842 | 838 | ||
843 | options[nr_options++] = (char *)"Exit"; | 839 | options[nr_options++] = (char *)"Exit"; |
844 | 840 | ||
845 | choice = popup_menu(nr_options, options); | 841 | choice = ui__popup_menu(nr_options, options); |
846 | 842 | ||
847 | for (i = 0; i < nr_options - 1; ++i) | 843 | for (i = 0; i < nr_options - 1; ++i) |
848 | free(options[i]); | 844 | free(options[i]); |
diff --git a/tools/perf/util/ui/helpline.c b/tools/perf/util/ui/helpline.c index 6a11e1301559..ff584606a4dc 100644 --- a/tools/perf/util/ui/helpline.c +++ b/tools/perf/util/ui/helpline.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <newt.h> | 4 | #include <newt.h> |
5 | 5 | ||
6 | #include "../debug.h" | ||
6 | #include "helpline.h" | 7 | #include "helpline.h" |
7 | 8 | ||
8 | void ui_helpline__pop(void) | 9 | void ui_helpline__pop(void) |
@@ -41,3 +42,28 @@ void ui_helpline__puts(const char *msg) | |||
41 | ui_helpline__pop(); | 42 | ui_helpline__pop(); |
42 | ui_helpline__push(msg); | 43 | ui_helpline__push(msg); |
43 | } | 44 | } |
45 | |||
46 | void ui_helpline__init(void) | ||
47 | { | ||
48 | ui_helpline__puts(" "); | ||
49 | } | ||
50 | |||
51 | char ui_helpline__last_msg[1024]; | ||
52 | |||
53 | int ui_helpline__show_help(const char *format, va_list ap) | ||
54 | { | ||
55 | int ret; | ||
56 | static int backlog; | ||
57 | |||
58 | ret = vsnprintf(ui_helpline__last_msg + backlog, | ||
59 | sizeof(ui_helpline__last_msg) - backlog, format, ap); | ||
60 | backlog += ret; | ||
61 | |||
62 | if (ui_helpline__last_msg[backlog - 1] == '\n') { | ||
63 | ui_helpline__puts(ui_helpline__last_msg); | ||
64 | newtRefresh(); | ||
65 | backlog = 0; | ||
66 | } | ||
67 | |||
68 | return ret; | ||
69 | } | ||
diff --git a/tools/perf/util/ui/helpline.h b/tools/perf/util/ui/helpline.h index 56d8c1d8ffc8..5d1e5e72ffb5 100644 --- a/tools/perf/util/ui/helpline.h +++ b/tools/perf/util/ui/helpline.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _PERF_UI_HELPLINE_H_ | 1 | #ifndef _PERF_UI_HELPLINE_H_ |
2 | #define _PERF_UI_HELPLINE_H_ 1 | 2 | #define _PERF_UI_HELPLINE_H_ 1 |
3 | 3 | ||
4 | void ui_helpline__init(void); | ||
4 | void ui_helpline__pop(void); | 5 | void ui_helpline__pop(void); |
5 | void ui_helpline__push(const char *msg); | 6 | void ui_helpline__push(const char *msg); |
6 | void ui_helpline__fpush(const char *fmt, ...); | 7 | void ui_helpline__fpush(const char *fmt, ...); |
diff --git a/tools/perf/util/ui/setup.c b/tools/perf/util/ui/setup.c new file mode 100644 index 000000000000..662085032eb7 --- /dev/null +++ b/tools/perf/util/ui/setup.c | |||
@@ -0,0 +1,42 @@ | |||
1 | #include <newt.h> | ||
2 | #include <signal.h> | ||
3 | #include <stdbool.h> | ||
4 | |||
5 | #include "../cache.h" | ||
6 | #include "../debug.h" | ||
7 | #include "browser.h" | ||
8 | #include "helpline.h" | ||
9 | |||
10 | static void newt_suspend(void *d __used) | ||
11 | { | ||
12 | newtSuspend(); | ||
13 | raise(SIGTSTP); | ||
14 | newtResume(); | ||
15 | } | ||
16 | |||
17 | void setup_browser(void) | ||
18 | { | ||
19 | if (!isatty(1) || !use_browser || dump_trace) { | ||
20 | use_browser = 0; | ||
21 | setup_pager(); | ||
22 | return; | ||
23 | } | ||
24 | |||
25 | use_browser = 1; | ||
26 | newtInit(); | ||
27 | newtCls(); | ||
28 | newtSetSuspendCallback(newt_suspend, NULL); | ||
29 | ui_helpline__init(); | ||
30 | ui_browser__init(); | ||
31 | } | ||
32 | |||
33 | void exit_browser(bool wait_for_ok) | ||
34 | { | ||
35 | if (use_browser > 0) { | ||
36 | if (wait_for_ok) { | ||
37 | char title[] = "Fatal Error", ok[] = "Ok"; | ||
38 | newtWinMessage(title, ok, ui_helpline__last_msg); | ||
39 | } | ||
40 | newtFinished(); | ||
41 | } | ||
42 | } | ||
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c new file mode 100644 index 000000000000..04600e26ceea --- /dev/null +++ b/tools/perf/util/ui/util.c | |||
@@ -0,0 +1,114 @@ | |||
1 | #include <newt.h> | ||
2 | #include <signal.h> | ||
3 | #include <stdio.h> | ||
4 | #include <stdbool.h> | ||
5 | #include <string.h> | ||
6 | #include <sys/ttydefaults.h> | ||
7 | |||
8 | #include "../cache.h" | ||
9 | #include "../debug.h" | ||
10 | #include "browser.h" | ||
11 | #include "helpline.h" | ||
12 | #include "util.h" | ||
13 | |||
14 | newtComponent newt_form__new(void); | ||
15 | |||
16 | static void newt_form__set_exit_keys(newtComponent self) | ||
17 | { | ||
18 | newtFormAddHotKey(self, NEWT_KEY_LEFT); | ||
19 | newtFormAddHotKey(self, NEWT_KEY_ESCAPE); | ||
20 | newtFormAddHotKey(self, 'Q'); | ||
21 | newtFormAddHotKey(self, 'q'); | ||
22 | newtFormAddHotKey(self, CTRL('c')); | ||
23 | } | ||
24 | |||
25 | newtComponent newt_form__new(void) | ||
26 | { | ||
27 | newtComponent self = newtForm(NULL, NULL, 0); | ||
28 | if (self) | ||
29 | newt_form__set_exit_keys(self); | ||
30 | return self; | ||
31 | } | ||
32 | |||
33 | int ui__popup_menu(int argc, char * const argv[]) | ||
34 | { | ||
35 | struct newtExitStruct es; | ||
36 | int i, rc = -1, max_len = 5; | ||
37 | newtComponent listbox, form = newt_form__new(); | ||
38 | |||
39 | if (form == NULL) | ||
40 | return -1; | ||
41 | |||
42 | listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); | ||
43 | if (listbox == NULL) | ||
44 | goto out_destroy_form; | ||
45 | |||
46 | newtFormAddComponent(form, listbox); | ||
47 | |||
48 | for (i = 0; i < argc; ++i) { | ||
49 | int len = strlen(argv[i]); | ||
50 | if (len > max_len) | ||
51 | max_len = len; | ||
52 | if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) | ||
53 | goto out_destroy_form; | ||
54 | } | ||
55 | |||
56 | newtCenteredWindow(max_len, argc, NULL); | ||
57 | newtFormRun(form, &es); | ||
58 | rc = newtListboxGetCurrent(listbox) - NULL; | ||
59 | if (es.reason == NEWT_EXIT_HOTKEY) | ||
60 | rc = -1; | ||
61 | newtPopWindow(); | ||
62 | out_destroy_form: | ||
63 | newtFormDestroy(form); | ||
64 | return rc; | ||
65 | } | ||
66 | |||
67 | int ui__help_window(const char *text) | ||
68 | { | ||
69 | struct newtExitStruct es; | ||
70 | newtComponent tb, form = newt_form__new(); | ||
71 | int rc = -1; | ||
72 | int max_len = 0, nr_lines = 0; | ||
73 | const char *t; | ||
74 | |||
75 | if (form == NULL) | ||
76 | return -1; | ||
77 | |||
78 | t = text; | ||
79 | while (1) { | ||
80 | const char *sep = strchr(t, '\n'); | ||
81 | int len; | ||
82 | |||
83 | if (sep == NULL) | ||
84 | sep = strchr(t, '\0'); | ||
85 | len = sep - t; | ||
86 | if (max_len < len) | ||
87 | max_len = len; | ||
88 | ++nr_lines; | ||
89 | if (*sep == '\0') | ||
90 | break; | ||
91 | t = sep + 1; | ||
92 | } | ||
93 | |||
94 | tb = newtTextbox(0, 0, max_len, nr_lines, 0); | ||
95 | if (tb == NULL) | ||
96 | goto out_destroy_form; | ||
97 | |||
98 | newtTextboxSetText(tb, text); | ||
99 | newtFormAddComponent(form, tb); | ||
100 | newtCenteredWindow(max_len, nr_lines, NULL); | ||
101 | newtFormRun(form, &es); | ||
102 | newtPopWindow(); | ||
103 | rc = 0; | ||
104 | out_destroy_form: | ||
105 | newtFormDestroy(form); | ||
106 | return rc; | ||
107 | } | ||
108 | |||
109 | bool ui__dialog_yesno(const char *msg) | ||
110 | { | ||
111 | /* newtWinChoice should really be accepting const char pointers... */ | ||
112 | char yes[] = "Yes", no[] = "No"; | ||
113 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | ||
114 | } | ||
diff --git a/tools/perf/util/ui/util.h b/tools/perf/util/ui/util.h new file mode 100644 index 000000000000..afcbc1d99531 --- /dev/null +++ b/tools/perf/util/ui/util.h | |||
@@ -0,0 +1,10 @@ | |||
1 | #ifndef _PERF_UI_UTIL_H_ | ||
2 | #define _PERF_UI_UTIL_H_ 1 | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | |||
6 | int ui__popup_menu(int argc, char * const argv[]); | ||
7 | int ui__help_window(const char *text); | ||
8 | bool ui__dialog_yesno(const char *msg); | ||
9 | |||
10 | #endif /* _PERF_UI_UTIL_H_ */ | ||