Virtual machine Management Terminal User Interface
Revision | bbc568effb50bfc8595c2ce09568596cbad37cdc (tree) |
---|---|
Time | 2023-06-27 22:28:41 |
Author | Koine Yuusuke(koinec) <koinec@user...> |
Commiter | Koine Yuusuke(koinec) |
Support input cursor with InputString/InputPassword Mode.
@@ -38,6 +38,9 @@ int | ||
38 | 38 | { |
39 | 39 | int i_mode; |
40 | 40 | int i_len; |
41 | + int i_cursor; | |
42 | + int i_start; | |
43 | + int i_row; | |
41 | 44 | char *pstr_input; |
42 | 45 | char *pstr_prompt; |
43 | 46 | char str_pass[ HVISOR_SSH_MAXLEN_PASSWORD ]; |
@@ -46,18 +49,22 @@ int | ||
46 | 49 | |
47 | 50 | pstr_prompt = TuiKey_GetPromptString(); |
48 | 51 | |
49 | - mvwprintw( gp_cmd_win, 0, 0, "%s", pstr_prompt ); | |
52 | + mvwprintw( gp_cmd_win, 0, 0, "%s => ", pstr_prompt ); | |
50 | 53 | |
51 | 54 | i_mode = TuiKey_GetMode(); |
52 | 55 | if( TUIKEY_MODE_INPUTSTR == i_mode ) { |
53 | - pstr_input = TuiKey_GetInputStringAndPasswd( NULL ); | |
54 | - wprintw( gp_cmd_win, " => %s", pstr_input ); | |
56 | + getyx( gp_cmd_win, i_row, i_start ); | |
57 | + | |
58 | + pstr_input = TuiKey_GetInputStringAndPasswd( NULL, &i_cursor ); | |
59 | + wprintw( gp_cmd_win, "%s", pstr_input ); | |
60 | + | |
61 | + wmove( gp_cmd_win, i_row, i_start + i_cursor ); | |
55 | 62 | } |
56 | 63 | else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) { |
57 | - pstr_input = TuiKey_GetInputStringAndPasswd( &i_len ); | |
64 | + pstr_input = TuiKey_GetInputStringAndPasswd( &i_len, NULL ); | |
58 | 65 | str_pass[ i_len-- ] = '\0'; |
59 | 66 | for( ; 0 <= i_len; i_len-- ) { str_pass[ i_len ] = '*'; } |
60 | - wprintw( gp_cmd_win, " => %s", str_pass ); | |
67 | + wprintw( gp_cmd_win, "%s", str_pass ); | |
61 | 68 | } |
62 | 69 | |
63 | 70 | touchwin( gp_cmd_win ); |
@@ -137,7 +137,7 @@ int | ||
137 | 137 | VMTUI_TUIKEY_EXTERN |
138 | 138 | char * |
139 | 139 | TuiKey_GetInputStringAndPasswd( |
140 | - int *pi_len ) | |
140 | + int *pi_len, int *pi_cursor ) | |
141 | 141 | { |
142 | 142 | if(( TUIKEY_MODE_INPUTSTR != gi_keymode ) && ( TUIKEY_MODE_INPUTPASSWD != gi_keymode )) { |
143 | 143 | return NULL; |
@@ -146,6 +146,9 @@ char * | ||
146 | 146 | if( NULL != pi_len ) |
147 | 147 | { *pi_len = gt_input.i_inputlen; } |
148 | 148 | |
149 | + if( NULL != pi_cursor ) | |
150 | + { *pi_cursor = gt_input.i_cursor; } | |
151 | + | |
149 | 152 | return gt_input.str_input; |
150 | 153 | } |
151 | 154 |
@@ -161,6 +164,29 @@ char * | ||
161 | 164 | /* ===========================================================================*/ |
162 | 165 | VMTUI_TUIKEY_EXTERN |
163 | 166 | int |
167 | + TuiKey_SetInputModeOption( | |
168 | + void *pv_option ) | |
169 | +{ | |
170 | + gt_input.pv_option = pv_option; | |
171 | + | |
172 | + return 0x00; | |
173 | +} | |
174 | + | |
175 | +/* ===========================================================================*/ | |
176 | +VMTUI_TUIKEY_EXTERN | |
177 | +int | |
178 | + TuiKey_ReturnMode( | |
179 | + void ) | |
180 | +{ | |
181 | + TuiKey_SetInputModeOption( NULL ); | |
182 | + TuiKey_ChangeMode( gt_input.i_retmode, REQUEST_CMD_NONE, | |
183 | + 0x00, 0x00, NULL, 0x00, TUIKEY_MODE_NONE, NULL ); | |
184 | + return 0x00; | |
185 | +} | |
186 | + | |
187 | +/* ===========================================================================*/ | |
188 | +VMTUI_TUIKEY_EXTERN | |
189 | +int | |
164 | 190 | TuiKey_ChangeMode( |
165 | 191 | int i_mode, |
166 | 192 | Byte b_reqcmd, |
@@ -180,6 +206,7 @@ int | ||
180 | 206 | gt_input.i_retmode = i_retmode; |
181 | 207 | |
182 | 208 | if( TUIKEY_MODE_INPUTSTR == i_mode ) { |
209 | + gt_input.i_cursor = 0; | |
183 | 210 | gt_input.i_inputlen = 0; |
184 | 211 | gt_input.i_input = 0; |
185 | 212 | gt_input.str_input[0] = '\0'; |
@@ -190,6 +217,7 @@ int | ||
190 | 217 | { strncpy( gt_input.str_msg, "Input String", sizeof( gt_input.str_msg ) ); } |
191 | 218 | } |
192 | 219 | else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) { |
220 | + gt_input.i_cursor = 0; | |
193 | 221 | gt_input.i_inputlen = 0; |
194 | 222 | gt_input.i_input = 0; |
195 | 223 | gt_input.str_input[0] = '\0'; |
@@ -253,12 +281,26 @@ int | ||
253 | 281 | |
254 | 282 | if( ERR == i_key ) { return i_ret; } |
255 | 283 | |
284 | + // Input Character --- | |
256 | 285 | if( isprint( i_key ) ) { |
257 | - if( gt_input.i_inputlen < sizeof(gt_input.str_input) - 1) { | |
286 | + if( gt_input.i_inputlen >= sizeof(gt_input.str_input) - 1) { return i_ret; } | |
287 | + | |
288 | + if( gt_input.i_cursor == gt_input.i_inputlen ) { | |
289 | + gt_input.i_cursor++; | |
258 | 290 | gt_input.str_input[gt_input.i_inputlen++] = (char)i_key; |
259 | 291 | gt_input.str_input[gt_input.i_inputlen] = '\0'; |
260 | 292 | } |
293 | + else { | |
294 | + bcopy( (gt_input.str_input + gt_input.i_cursor), | |
295 | + (gt_input.str_input + gt_input.i_cursor + 1), | |
296 | + (gt_input.i_inputlen - gt_input.i_cursor + 1) ); | |
297 | + | |
298 | + gt_input.i_inputlen++; | |
299 | + gt_input.str_input[gt_input.i_cursor] = (char)i_key; | |
300 | + } | |
261 | 301 | } |
302 | + | |
303 | + // Enter --- | |
262 | 304 | else if(( KEY_ENTER == i_key) || ( 10 == i_key )) { |
263 | 305 | if( NULL != gt_input.fp_inputstr ) { |
264 | 306 | gt_input.fp_inputstr( gt_input.i_hvisor, gt_input.i_guest, |
@@ -266,16 +308,51 @@ int | ||
266 | 308 | gt_input.i_inputlen, gt_input.str_input ); |
267 | 309 | } |
268 | 310 | } |
269 | - // KEY_ESC | |
311 | + | |
312 | + // KEY_ESC --- | |
270 | 313 | else if( 27 == i_key ) { |
271 | - // Return mode --- | |
272 | - TuiKey_ChangeMode( gt_input.i_retmode, REQUEST_CMD_NONE, | |
273 | - 0x00, 0x00, NULL, 0x00, TUIKEY_MODE_NONE, NULL ); | |
314 | + TuiKey_ReturnMode(); | |
274 | 315 | } |
275 | - else if( KEY_BACKSPACE == i_key ) { | |
276 | - if( 0 < gt_input.i_inputlen ) { | |
316 | + | |
317 | + // BackSpace --- | |
318 | + else if(( KEY_BACKSPACE == i_key ) || ( NCURSES_Ctrl('h') == i_key )) { | |
319 | + if( 0 >= gt_input.i_inputlen ) { return i_ret; } | |
320 | + | |
321 | + if( 0 == gt_input.i_cursor ) { | |
322 | + return 0x00; | |
323 | + } else if( gt_input.i_cursor == gt_input.i_inputlen ) { | |
324 | + gt_input.i_cursor--; | |
277 | 325 | gt_input.str_input[--gt_input.i_inputlen] = '\0'; |
278 | 326 | } |
327 | + else { | |
328 | + bcopy( (gt_input.str_input + gt_input.i_cursor), | |
329 | + (gt_input.str_input + gt_input.i_cursor - 1), | |
330 | + (gt_input.i_inputlen - gt_input.i_cursor + 1) ); | |
331 | + gt_input.i_cursor--; | |
332 | + gt_input.i_inputlen--; | |
333 | + } | |
334 | + } | |
335 | + | |
336 | + // Clear --- | |
337 | + else if( NCURSES_Ctrl('l') == i_key ) { | |
338 | + gt_input.i_cursor = 0; | |
339 | + gt_input.i_inputlen = 0; | |
340 | + gt_input.i_input = 0; | |
341 | + gt_input.str_input[0] = '\0'; | |
342 | + } | |
343 | + | |
344 | + // Move Cursor --- | |
345 | + else if(( KEY_LEFT == i_key ) || ( NCURSES_Ctrl('b') == i_key )) { | |
346 | + if( 0 < gt_input.i_cursor ) { gt_input.i_cursor--; } | |
347 | + } | |
348 | + else if(( KEY_RIGHT == i_key ) || ( NCURSES_Ctrl('f') == i_key )) { | |
349 | + if( gt_input.i_cursor < gt_input.i_inputlen ) { gt_input.i_cursor++; } | |
350 | + } | |
351 | + else if( NCURSES_Ctrl('a') == i_key ) { | |
352 | + gt_input.i_cursor = 0; | |
353 | + } | |
354 | + else if( NCURSES_Ctrl('e') == i_key ) { | |
355 | + gt_input.i_cursor = gt_input.i_inputlen; | |
279 | 356 | } |
280 | 357 | |
281 | 358 | return i_ret; |
@@ -297,9 +374,7 @@ int | ||
297 | 374 | { i_ret = 0x01; } |
298 | 375 | } |
299 | 376 | |
300 | - // Return mode --- | |
301 | - TuiKey_ChangeMode( gt_input.i_retmode, REQUEST_CMD_NONE, | |
302 | - 0x00, 0x00, NULL, 0x00, TUIKEY_MODE_NONE, NULL ); | |
377 | + TuiKey_ReturnMode(); | |
303 | 378 | |
304 | 379 | return i_ret; |
305 | 380 | } |
@@ -42,8 +42,10 @@ VMTUI_TUIKEY_EXTERN int TuiKey_TestCode( void ); | ||
42 | 42 | VMTUI_TUIKEY_EXTERN char *TuiKey_GetKeyName( char *pstr_buf, int i_len, int i_key ); |
43 | 43 | VMTUI_TUIKEY_EXTERN int TuiKey_ChangeInfoWindow( int i_direction ); |
44 | 44 | VMTUI_TUIKEY_EXTERN int TuiKey_GetMode( void ); |
45 | -VMTUI_TUIKEY_EXTERN char *TuiKey_GetInputStringAndPasswd( int *pi_len ); | |
45 | +VMTUI_TUIKEY_EXTERN char *TuiKey_GetInputStringAndPasswd( int *pi_len, int *pi_cursor ); | |
46 | 46 | VMTUI_TUIKEY_EXTERN char *TuiKey_GetPromptString( void ); |
47 | +VMTUI_TUIKEY_EXTERN int TuiKey_SetInputModeOption( void *pv_option ); | |
48 | +VMTUI_TUIKEY_EXTERN int TuiKey_ReturnMode( void ); | |
47 | 49 | VMTUI_TUIKEY_EXTERN int TuiKey_ChangeMode( |
48 | 50 | int i_mode, Byte b_reqcmd, int i_hvisor, int i_guest, |
49 | 51 | InputStrFunction fp_handler, Byte b_option, int i_retmode, char *pstr_msg ); |
@@ -88,14 +90,17 @@ typedef struct { | ||
88 | 90 | int i_guest; |
89 | 91 | Byte b_option; |
90 | 92 | |
93 | + int i_cursor; | |
94 | + | |
91 | 95 | int i_retmode; |
92 | 96 | InputStrFunction fp_inputstr; |
93 | 97 | |
94 | 98 | int i_inputlen; |
95 | 99 | int i_input; |
96 | 100 | char str_input[512]; |
97 | - char str_option[512]; | |
101 | + //char str_option[512]; | |
98 | 102 | char str_msg[128]; |
103 | + void *pv_option; | |
99 | 104 | } TuiKey_InputLine; |
100 | 105 | |
101 | 106 | #ifdef VMTUI_SRC_TUIKEY |