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/newt.c | |
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/newt.c')
-rw-r--r-- | tools/perf/util/newt.c | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c deleted file mode 100644 index 6bccdaa159aa..000000000000 --- a/tools/perf/util/newt.c +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
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 "ui/browser.h" | ||
11 | #include "ui/helpline.h" | ||
12 | |||
13 | newtComponent newt_form__new(void); | ||
14 | int popup_menu(int argc, char * const argv[]); | ||
15 | int ui__help_window(const char *text); | ||
16 | bool dialog_yesno(const char *msg); | ||
17 | |||
18 | char browser__last_msg[1024]; | ||
19 | |||
20 | int browser__show_help(const char *format, va_list ap) | ||
21 | { | ||
22 | int ret; | ||
23 | static int backlog; | ||
24 | |||
25 | ret = vsnprintf(browser__last_msg + backlog, | ||
26 | sizeof(browser__last_msg) - backlog, format, ap); | ||
27 | backlog += ret; | ||
28 | |||
29 | if (browser__last_msg[backlog - 1] == '\n') { | ||
30 | ui_helpline__puts(browser__last_msg); | ||
31 | newtRefresh(); | ||
32 | backlog = 0; | ||
33 | } | ||
34 | |||
35 | return ret; | ||
36 | } | ||
37 | |||
38 | static void newt_form__set_exit_keys(newtComponent self) | ||
39 | { | ||
40 | newtFormAddHotKey(self, NEWT_KEY_LEFT); | ||
41 | newtFormAddHotKey(self, NEWT_KEY_ESCAPE); | ||
42 | newtFormAddHotKey(self, 'Q'); | ||
43 | newtFormAddHotKey(self, 'q'); | ||
44 | newtFormAddHotKey(self, CTRL('c')); | ||
45 | } | ||
46 | |||
47 | newtComponent newt_form__new(void) | ||
48 | { | ||
49 | newtComponent self = newtForm(NULL, NULL, 0); | ||
50 | if (self) | ||
51 | newt_form__set_exit_keys(self); | ||
52 | return self; | ||
53 | } | ||
54 | |||
55 | int popup_menu(int argc, char * const argv[]) | ||
56 | { | ||
57 | struct newtExitStruct es; | ||
58 | int i, rc = -1, max_len = 5; | ||
59 | newtComponent listbox, form = newt_form__new(); | ||
60 | |||
61 | if (form == NULL) | ||
62 | return -1; | ||
63 | |||
64 | listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); | ||
65 | if (listbox == NULL) | ||
66 | goto out_destroy_form; | ||
67 | |||
68 | newtFormAddComponent(form, listbox); | ||
69 | |||
70 | for (i = 0; i < argc; ++i) { | ||
71 | int len = strlen(argv[i]); | ||
72 | if (len > max_len) | ||
73 | max_len = len; | ||
74 | if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) | ||
75 | goto out_destroy_form; | ||
76 | } | ||
77 | |||
78 | newtCenteredWindow(max_len, argc, NULL); | ||
79 | newtFormRun(form, &es); | ||
80 | rc = newtListboxGetCurrent(listbox) - NULL; | ||
81 | if (es.reason == NEWT_EXIT_HOTKEY) | ||
82 | rc = -1; | ||
83 | newtPopWindow(); | ||
84 | out_destroy_form: | ||
85 | newtFormDestroy(form); | ||
86 | return rc; | ||
87 | } | ||
88 | |||
89 | int ui__help_window(const char *text) | ||
90 | { | ||
91 | struct newtExitStruct es; | ||
92 | newtComponent tb, form = newt_form__new(); | ||
93 | int rc = -1; | ||
94 | int max_len = 0, nr_lines = 0; | ||
95 | const char *t; | ||
96 | |||
97 | if (form == NULL) | ||
98 | return -1; | ||
99 | |||
100 | t = text; | ||
101 | while (1) { | ||
102 | const char *sep = strchr(t, '\n'); | ||
103 | int len; | ||
104 | |||
105 | if (sep == NULL) | ||
106 | sep = strchr(t, '\0'); | ||
107 | len = sep - t; | ||
108 | if (max_len < len) | ||
109 | max_len = len; | ||
110 | ++nr_lines; | ||
111 | if (*sep == '\0') | ||
112 | break; | ||
113 | t = sep + 1; | ||
114 | } | ||
115 | |||
116 | tb = newtTextbox(0, 0, max_len, nr_lines, 0); | ||
117 | if (tb == NULL) | ||
118 | goto out_destroy_form; | ||
119 | |||
120 | newtTextboxSetText(tb, text); | ||
121 | newtFormAddComponent(form, tb); | ||
122 | newtCenteredWindow(max_len, nr_lines, NULL); | ||
123 | newtFormRun(form, &es); | ||
124 | newtPopWindow(); | ||
125 | rc = 0; | ||
126 | out_destroy_form: | ||
127 | newtFormDestroy(form); | ||
128 | return rc; | ||
129 | } | ||
130 | |||
131 | bool dialog_yesno(const char *msg) | ||
132 | { | ||
133 | /* newtWinChoice should really be accepting const char pointers... */ | ||
134 | char yes[] = "Yes", no[] = "No"; | ||
135 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | ||
136 | } | ||
137 | |||
138 | static void newt_suspend(void *d __used) | ||
139 | { | ||
140 | newtSuspend(); | ||
141 | raise(SIGTSTP); | ||
142 | newtResume(); | ||
143 | } | ||
144 | |||
145 | void setup_browser(void) | ||
146 | { | ||
147 | if (!isatty(1) || !use_browser || dump_trace) { | ||
148 | use_browser = 0; | ||
149 | setup_pager(); | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | use_browser = 1; | ||
154 | newtInit(); | ||
155 | newtCls(); | ||
156 | newtSetSuspendCallback(newt_suspend, NULL); | ||
157 | ui_helpline__puts(" "); | ||
158 | ui_browser__init(); | ||
159 | } | ||
160 | |||
161 | void exit_browser(bool wait_for_ok) | ||
162 | { | ||
163 | if (use_browser > 0) { | ||
164 | if (wait_for_ok) { | ||
165 | char title[] = "Fatal Error", ok[] = "Ok"; | ||
166 | newtWinMessage(title, ok, browser__last_msg); | ||
167 | } | ||
168 | newtFinished(); | ||
169 | } | ||
170 | } | ||