diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-03-16 04:50:52 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-03-16 15:32:36 -0400 |
commit | aa49f6ec990baa9d8f1b46a86fc169a8028776d4 (patch) | |
tree | a9b2e4bd576e7c9390e07885ece249cfb4125e0d /tools | |
parent | e94d53ebec2fb4795c18ad2e76ec633390b1e794 (diff) |
perf ui browser: Introduce ui_browser__input_window
The ui_browser__input_window() function is to get user's key input.
Current implementation can handle maximum 49 characters.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1331887855-874-2-git-send-email-namhyung.kim@lge.com
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/ui/browser.h | 2 | ||||
-rw-r--r-- | tools/perf/util/ui/keysyms.h | 2 | ||||
-rw-r--r-- | tools/perf/util/ui/util.c | 78 |
3 files changed, 82 insertions, 0 deletions
diff --git a/tools/perf/util/ui/browser.h b/tools/perf/util/ui/browser.h index 84d761b730c1..6ee82f60feaf 100644 --- a/tools/perf/util/ui/browser.h +++ b/tools/perf/util/ui/browser.h | |||
@@ -49,6 +49,8 @@ int ui_browser__warning(struct ui_browser *browser, int timeout, | |||
49 | const char *format, ...); | 49 | const char *format, ...); |
50 | int ui_browser__help_window(struct ui_browser *browser, const char *text); | 50 | int ui_browser__help_window(struct ui_browser *browser, const char *text); |
51 | bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text); | 51 | bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text); |
52 | int ui_browser__input_window(const char *title, const char *text, char *input, | ||
53 | const char *exit_msg, int delay_sec); | ||
52 | 54 | ||
53 | void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence); | 55 | void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence); |
54 | unsigned int ui_browser__argv_refresh(struct ui_browser *browser); | 56 | unsigned int ui_browser__argv_refresh(struct ui_browser *browser); |
diff --git a/tools/perf/util/ui/keysyms.h b/tools/perf/util/ui/keysyms.h index 3458b1985761..809eca5707fa 100644 --- a/tools/perf/util/ui/keysyms.h +++ b/tools/perf/util/ui/keysyms.h | |||
@@ -16,6 +16,8 @@ | |||
16 | #define K_TAB '\t' | 16 | #define K_TAB '\t' |
17 | #define K_UNTAB SL_KEY_UNTAB | 17 | #define K_UNTAB SL_KEY_UNTAB |
18 | #define K_UP SL_KEY_UP | 18 | #define K_UP SL_KEY_UP |
19 | #define K_BKSPC 0x7f | ||
20 | #define K_DEL SL_KEY_DELETE | ||
19 | 21 | ||
20 | /* Not really keys */ | 22 | /* Not really keys */ |
21 | #define K_TIMER -1 | 23 | #define K_TIMER -1 |
diff --git a/tools/perf/util/ui/util.c b/tools/perf/util/ui/util.c index 45daa7c41dad..360f43fd5400 100644 --- a/tools/perf/util/ui/util.c +++ b/tools/perf/util/ui/util.c | |||
@@ -69,6 +69,84 @@ int ui__popup_menu(int argc, char * const argv[]) | |||
69 | return popup_menu__run(&menu); | 69 | return popup_menu__run(&menu); |
70 | } | 70 | } |
71 | 71 | ||
72 | int ui_browser__input_window(const char *title, const char *text, char *input, | ||
73 | const char *exit_msg, int delay_secs) | ||
74 | { | ||
75 | int x, y, len, key; | ||
76 | int max_len = 60, nr_lines = 0; | ||
77 | static char buf[50]; | ||
78 | const char *t; | ||
79 | |||
80 | t = text; | ||
81 | while (1) { | ||
82 | const char *sep = strchr(t, '\n'); | ||
83 | |||
84 | if (sep == NULL) | ||
85 | sep = strchr(t, '\0'); | ||
86 | len = sep - t; | ||
87 | if (max_len < len) | ||
88 | max_len = len; | ||
89 | ++nr_lines; | ||
90 | if (*sep == '\0') | ||
91 | break; | ||
92 | t = sep + 1; | ||
93 | } | ||
94 | |||
95 | max_len += 2; | ||
96 | nr_lines += 8; | ||
97 | y = SLtt_Screen_Rows / 2 - nr_lines / 2; | ||
98 | x = SLtt_Screen_Cols / 2 - max_len / 2; | ||
99 | |||
100 | SLsmg_set_color(0); | ||
101 | SLsmg_draw_box(y, x++, nr_lines, max_len); | ||
102 | if (title) { | ||
103 | SLsmg_gotorc(y, x + 1); | ||
104 | SLsmg_write_string((char *)title); | ||
105 | } | ||
106 | SLsmg_gotorc(++y, x); | ||
107 | nr_lines -= 7; | ||
108 | max_len -= 2; | ||
109 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, | ||
110 | nr_lines, max_len, 1); | ||
111 | y += nr_lines + 1; | ||
112 | SLsmg_set_color(0); | ||
113 | SLsmg_draw_box(y - 1, x + 1, 3, max_len - 2); | ||
114 | |||
115 | SLsmg_gotorc(y + 3, x); | ||
116 | SLsmg_write_nstring((char *)exit_msg, max_len); | ||
117 | SLsmg_refresh(); | ||
118 | |||
119 | x += 2; | ||
120 | len = 0; | ||
121 | key = ui__getch(delay_secs); | ||
122 | while (key != K_TIMER && key != K_ENTER && key != K_ESC) { | ||
123 | if (key == K_BKSPC) { | ||
124 | if (len == 0) | ||
125 | goto next_key; | ||
126 | SLsmg_gotorc(y, x + --len); | ||
127 | SLsmg_write_char(' '); | ||
128 | } else { | ||
129 | buf[len] = key; | ||
130 | SLsmg_gotorc(y, x + len++); | ||
131 | SLsmg_write_char(key); | ||
132 | } | ||
133 | SLsmg_refresh(); | ||
134 | |||
135 | /* XXX more graceful overflow handling needed */ | ||
136 | if (len == sizeof(buf) - 1) { | ||
137 | ui_helpline__push("maximum size of symbol name reached!"); | ||
138 | key = K_ENTER; | ||
139 | break; | ||
140 | } | ||
141 | next_key: | ||
142 | key = ui__getch(delay_secs); | ||
143 | } | ||
144 | |||
145 | buf[len] = '\0'; | ||
146 | strncpy(input, buf, len+1); | ||
147 | return key; | ||
148 | } | ||
149 | |||
72 | int ui__question_window(const char *title, const char *text, | 150 | int ui__question_window(const char *title, const char *text, |
73 | const char *exit_msg, int delay_secs) | 151 | const char *exit_msg, int delay_secs) |
74 | { | 152 | { |