Virtual machine Management Terminal User Interface
Révision | cb903de6fbb0111465ff90abc1021753fe11ed9f (tree) |
---|---|
l'heure | 2023-06-29 22:22:58 |
Auteur | ![]() |
Commiter | Koine Yuusuke(koinec) |
Implement Int/SfxInt/IPaddr. Input mode.
@@ -209,13 +209,26 @@ int | ||
209 | 209 | gt_input.fp_inputstr = fp_handler; |
210 | 210 | gt_input.i_retmode = i_retmode; |
211 | 211 | |
212 | - if( TUIKEY_MODE_INPUTSTR == i_mode ) { | |
212 | + if( TUIKEY_MODE_INPUTSTR & ((DWord)i_mode) ) { | |
213 | 213 | gt_input.i_cursor = 0; |
214 | 214 | gt_input.b_option = b_option; |
215 | 215 | if( NULL != pstr_msg ) |
216 | 216 | { strncpy( gt_input.str_msg, pstr_msg, sizeof( gt_input.str_msg ) ); } |
217 | - else | |
218 | - { strncpy( gt_input.str_msg, "Input String", sizeof( gt_input.str_msg ) ); } | |
217 | + else { | |
218 | + if( TUIKEY_MODE_INPUTINT == i_mode ) | |
219 | + { strncpy( gt_input.str_msg, "Input Integer", sizeof( gt_input.str_msg ) ); } | |
220 | + else if( TUIKEY_MODE_INPUTDECIMAL == i_mode ) | |
221 | + { strncpy( gt_input.str_msg, "Input Floating Value", sizeof( gt_input.str_msg ) ); } | |
222 | + else if( TUIKEY_MODE_INPUTIPADDR == i_mode ) | |
223 | + { strncpy( gt_input.str_msg, "Input IP Address", sizeof( gt_input.str_msg ) ); } | |
224 | + else if( TUIKEY_MODE_INPUTSFXINT == i_mode ) | |
225 | + { strncpy( gt_input.str_msg, "Input Value with Suffix(K/G/M)", | |
226 | + sizeof( gt_input.str_msg ) ); } | |
227 | + else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) | |
228 | + { strncpy( gt_input.str_msg, "Input Password", sizeof( gt_input.str_msg ) ); } | |
229 | + else | |
230 | + { strncpy( gt_input.str_msg, "Input String", sizeof( gt_input.str_msg ) ); } | |
231 | + } | |
219 | 232 | |
220 | 233 | if( NULL != pstr_default ) { |
221 | 234 | if( i_buflen > (int)sizeof( gt_input.str_input ) ) |
@@ -226,6 +239,8 @@ int | ||
226 | 239 | gt_input.i_inputlen = i_len; |
227 | 240 | |
228 | 241 | strncpy( gt_input.str_input, pstr_default, i_buflen ); |
242 | + | |
243 | + gt_input.i_cursor = i_len; | |
229 | 244 | } |
230 | 245 | else { |
231 | 246 | gt_input.str_input[0] = '\0'; |
@@ -233,6 +248,7 @@ int | ||
233 | 248 | gt_input.i_buflen = sizeof( gt_input.str_input ); |
234 | 249 | } |
235 | 250 | } |
251 | + /* | |
236 | 252 | else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) { |
237 | 253 | gt_input.i_cursor = 0; |
238 | 254 | gt_input.b_option = b_option; |
@@ -257,6 +273,7 @@ int | ||
257 | 273 | gt_input.i_buflen = sizeof( gt_input.str_input ); |
258 | 274 | } |
259 | 275 | } |
276 | + */ | |
260 | 277 | else if( TUIKEY_MODE_YESNO == i_mode ) { |
261 | 278 | if( NULL != pstr_msg ) |
262 | 279 | { strncpy( gt_input.str_msg, pstr_msg, sizeof( gt_input.str_msg ) ); } |
@@ -311,81 +328,132 @@ int | ||
311 | 328 | |
312 | 329 | if( ERR == i_key ) { return i_ret; } |
313 | 330 | |
314 | - // Input Character --- | |
315 | - if( isprint( i_key ) ) { | |
316 | - if( gt_input.i_inputlen >= gt_input.i_buflen - 1) { return i_ret; } | |
331 | + // Move Cursor --- | |
332 | + if( TUIKEY_MODE_INPUTPASSWD != gi_keymode ) { | |
333 | + if(( KEY_LEFT == i_key ) || ( NCURSES_Ctrl('b') == i_key )) { | |
334 | + if( 0 < gt_input.i_cursor ) | |
335 | + { gt_input.i_cursor--; } | |
317 | 336 | |
318 | - if( gt_input.i_cursor == gt_input.i_inputlen ) { | |
319 | - gt_input.i_cursor++; | |
320 | - gt_input.str_input[gt_input.i_inputlen++] = (char)i_key; | |
321 | - gt_input.str_input[gt_input.i_inputlen] = '\0'; | |
337 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
322 | 338 | } |
323 | - else { | |
324 | - bcopy( (gt_input.str_input + gt_input.i_cursor), | |
325 | - (gt_input.str_input + gt_input.i_cursor + 1), | |
326 | - (gt_input.i_inputlen - gt_input.i_cursor + 1) ); | |
339 | + else if(( KEY_RIGHT == i_key ) || ( NCURSES_Ctrl('f') == i_key )) { | |
340 | + if( gt_input.i_cursor < gt_input.i_inputlen ) | |
341 | + { gt_input.i_cursor++; } | |
342 | + | |
343 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
344 | + } | |
345 | + else if( NCURSES_Ctrl('a') == i_key ) { | |
346 | + gt_input.i_cursor = 0; | |
327 | 347 | |
328 | - gt_input.i_inputlen++; | |
329 | - gt_input.str_input[gt_input.i_cursor] = (char)i_key; | |
330 | - gt_input.i_cursor++; | |
348 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
349 | + } | |
350 | + else if( NCURSES_Ctrl('e') == i_key ) { | |
351 | + gt_input.i_cursor = gt_input.i_inputlen; | |
352 | + | |
353 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
331 | 354 | } |
332 | 355 | } |
333 | 356 | |
334 | 357 | // Enter --- |
335 | - else if(( KEY_ENTER == i_key) || ( 10 == i_key )) { | |
358 | + if(( KEY_ENTER == i_key) || ( 10 == i_key )) { | |
336 | 359 | if( NULL != gt_input.fp_inputstr ) { |
337 | 360 | gt_input.fp_inputstr( gt_input.i_hvisor, gt_input.i_guest, |
338 | 361 | gt_input.b_reqcmd, gt_input.b_option, |
339 | 362 | gt_input.i_inputlen, gt_input.str_input ); |
340 | 363 | } |
341 | - } | |
342 | 364 | |
365 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
366 | + } | |
343 | 367 | // KEY_ESC --- |
344 | 368 | else if( 27 == i_key ) { |
345 | 369 | TuiKey_ReturnMode(); |
346 | - } | |
347 | 370 | |
371 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
372 | + } | |
348 | 373 | // BackSpace --- |
349 | 374 | else if(( KEY_BACKSPACE == i_key ) || ( NCURSES_Ctrl('h') == i_key )) { |
350 | - if( 0 >= gt_input.i_inputlen ) { return i_ret; } | |
351 | - | |
352 | - if( 0 == gt_input.i_cursor ) { | |
353 | - return 0x00; | |
354 | - } else if( gt_input.i_cursor == gt_input.i_inputlen ) { | |
355 | - gt_input.i_cursor--; | |
356 | - gt_input.str_input[--gt_input.i_inputlen] = '\0'; | |
357 | - } | |
358 | - else { | |
359 | - bcopy( (gt_input.str_input + gt_input.i_cursor), | |
360 | - (gt_input.str_input + gt_input.i_cursor - 1), | |
361 | - (gt_input.i_inputlen - gt_input.i_cursor + 1) ); | |
362 | - gt_input.i_cursor--; | |
363 | - gt_input.i_inputlen--; | |
375 | + if(( 0 < gt_input.i_inputlen ) && ( 0 < gt_input.i_cursor )) { | |
376 | + if( gt_input.i_cursor == gt_input.i_inputlen ) { | |
377 | + gt_input.i_cursor--; | |
378 | + gt_input.str_input[--gt_input.i_inputlen] = '\0'; | |
379 | + } | |
380 | + else { | |
381 | + bcopy( (gt_input.str_input + gt_input.i_cursor), | |
382 | + (gt_input.str_input + gt_input.i_cursor - 1), | |
383 | + (gt_input.i_inputlen - gt_input.i_cursor + 1) ); | |
384 | + gt_input.i_cursor--; | |
385 | + gt_input.i_inputlen--; | |
386 | + } | |
364 | 387 | } |
365 | - } | |
366 | 388 | |
389 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
390 | + } | |
367 | 391 | // Clear --- |
368 | 392 | else if( NCURSES_Ctrl('l') == i_key ) { |
369 | 393 | gt_input.i_cursor = 0; |
370 | 394 | gt_input.i_inputlen = 0; |
371 | - //gt_input.i_input = 0; | |
372 | 395 | gt_input.str_input[0] = '\0'; |
396 | + | |
397 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
373 | 398 | } |
374 | 399 | |
375 | - // Move Cursor --- | |
376 | - else if(( KEY_LEFT == i_key ) || ( NCURSES_Ctrl('b') == i_key )) { | |
377 | - if( 0 < gt_input.i_cursor ) { gt_input.i_cursor--; } | |
400 | + // Input Character --- | |
401 | + if( gt_input.i_inputlen >= gt_input.i_buflen - 1) | |
402 | + { goto goto_TuiKey_Dispatch_Mode_InputStr_post; } | |
403 | + if( ! isprint( i_key ) ) { goto goto_TuiKey_Dispatch_Mode_InputStr_post; } | |
404 | + | |
405 | + if( TUIKEY_MODE_INPUTSTR == gi_keymode ) | |
406 | + { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
407 | + else if( TUIKEY_MODE_INPUTPASSWD == gi_keymode ) | |
408 | + { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
409 | + else if( TUIKEY_MODE_INPUTINT == gi_keymode ) { | |
410 | + if( isdigit( i_key ) ) { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
378 | 411 | } |
379 | - else if(( KEY_RIGHT == i_key ) || ( NCURSES_Ctrl('f') == i_key )) { | |
380 | - if( gt_input.i_cursor < gt_input.i_inputlen ) { gt_input.i_cursor++; } | |
412 | + else if(( TUIKEY_MODE_INPUTDECIMAL == gi_keymode ) | |
413 | + || ( TUIKEY_MODE_INPUTIPADDR == gi_keymode )) { | |
414 | + | |
415 | + if( isdigit( i_key ) ) { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
416 | + if( '.' == i_key ) { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
381 | 417 | } |
382 | - else if( NCURSES_Ctrl('a') == i_key ) { | |
383 | - gt_input.i_cursor = 0; | |
418 | + else if( TUIKEY_MODE_INPUTSFXINT == gi_keymode ) { | |
419 | + if( isdigit( i_key ) ) { | |
420 | + if( 0 == gt_input.i_inputlen ) | |
421 | + { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
422 | + if( isdigit( gt_input.str_input[ gt_input.i_inputlen-1 ] ) ) | |
423 | + { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
424 | + } | |
425 | + | |
426 | + if(( 'k' == i_key ) || ( 'K' == i_key ) | |
427 | + || ( 'm' == i_key ) || ( 'M' == i_key ) | |
428 | + || ( 'g' == i_key ) || ( 'G' == i_key )) { | |
429 | + if( 0 < gt_input.i_inputlen ) { | |
430 | + if( isdigit( gt_input.str_input[ gt_input.i_inputlen-1 ] ) ) | |
431 | + { goto goto_TuiKey_Dispatch_Mode_InputStr_OK; } | |
432 | + } | |
433 | + } | |
384 | 434 | } |
385 | - else if( NCURSES_Ctrl('e') == i_key ) { | |
386 | - gt_input.i_cursor = gt_input.i_inputlen; | |
435 | + | |
436 | + goto goto_TuiKey_Dispatch_Mode_InputStr_post; | |
437 | + | |
438 | +goto_TuiKey_Dispatch_Mode_InputStr_OK: | |
439 | + | |
440 | + if( gt_input.i_cursor == gt_input.i_inputlen ) { | |
441 | + gt_input.i_cursor++; | |
442 | + gt_input.str_input[gt_input.i_inputlen++] = (char)i_key; | |
443 | + gt_input.str_input[gt_input.i_inputlen] = '\0'; | |
387 | 444 | } |
445 | + else { | |
446 | + bcopy( (gt_input.str_input + gt_input.i_cursor), | |
447 | + (gt_input.str_input + gt_input.i_cursor + 1), | |
448 | + (gt_input.i_inputlen - gt_input.i_cursor + 1) ); | |
449 | + | |
450 | + gt_input.i_inputlen++; | |
451 | + gt_input.str_input[gt_input.i_cursor] = (char)i_key; | |
452 | + gt_input.i_cursor++; | |
453 | + } | |
454 | + | |
388 | 455 | |
456 | +goto_TuiKey_Dispatch_Mode_InputStr_post: | |
389 | 457 | return i_ret; |
390 | 458 | } |
391 | 459 |
@@ -61,9 +61,13 @@ VMTUI_TUIKEY_EXTERN int TuiKey_Term( void ); | ||
61 | 61 | #define TUIKEY_MODE_GUEST (0x02+TUIKEY_MODE_INFO) |
62 | 62 | #define TUIKEY_MODE_CONSOLE (0x03+TUIKEY_MODE_INFO) |
63 | 63 | #define TUIKEY_MODE_ERRINFO (0x04+TUIKEY_MODE_INFO) |
64 | -#define TUIKEY_MODE_INPUTSTR 0x21 | |
65 | -#define TUIKEY_MODE_INPUTPASSWD 0x22 | |
66 | -#define TUIKEY_MODE_YESNO 0x23 | |
64 | +#define TUIKEY_MODE_INPUTSTR 0x20 | |
65 | +#define TUIKEY_MODE_INPUTINT 0x21 // bit 1 : digit | |
66 | +#define TUIKEY_MODE_INPUTDECIMAL 0x23 // bit 2 : digit + '.' | |
67 | +#define TUIKEY_MODE_INPUTIPADDR 0x23 | |
68 | +#define TUIKEY_MODE_INPUTSFXINT 0x24 // bit 3 : suffix | |
69 | +#define TUIKEY_MODE_INPUTPASSWD 0x28 // bit 4 : password | |
70 | +#define TUIKEY_MODE_YESNO 0x50 | |
67 | 71 | #define TUIKEY_MODE_NONE 0xff |
68 | 72 | |
69 | 73 | #define NCURSES_KEY_ENTER 10 |
@@ -99,7 +103,6 @@ typedef struct { | ||
99 | 103 | int i_inputlen; |
100 | 104 | int i_buflen; |
101 | 105 | char str_input[512]; |
102 | - //char str_option[512]; | |
103 | 106 | char str_msg[128]; |
104 | 107 | void *pv_option; |
105 | 108 | } TuiKey_InputLine; |