• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Virtual machine Management Terminal User Interface


Commit MetaInfo

Revisioncb903de6fbb0111465ff90abc1021753fe11ed9f (tree)
Time2023-06-29 22:22:58
AuthorKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

Implement Int/SfxInt/IPaddr. Input mode.

Change Summary

Incremental Difference

--- a/src/tuikey.c
+++ b/src/tuikey.c
@@ -209,13 +209,26 @@ int
209209 gt_input.fp_inputstr = fp_handler;
210210 gt_input.i_retmode = i_retmode;
211211
212- if( TUIKEY_MODE_INPUTSTR == i_mode ) {
212+ if( TUIKEY_MODE_INPUTSTR & ((DWord)i_mode) ) {
213213 gt_input.i_cursor = 0;
214214 gt_input.b_option = b_option;
215215 if( NULL != pstr_msg )
216216 { 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+ }
219232
220233 if( NULL != pstr_default ) {
221234 if( i_buflen > (int)sizeof( gt_input.str_input ) )
@@ -226,6 +239,8 @@ int
226239 gt_input.i_inputlen = i_len;
227240
228241 strncpy( gt_input.str_input, pstr_default, i_buflen );
242+
243+ gt_input.i_cursor = i_len;
229244 }
230245 else {
231246 gt_input.str_input[0] = '\0';
@@ -233,6 +248,7 @@ int
233248 gt_input.i_buflen = sizeof( gt_input.str_input );
234249 }
235250 }
251+ /*
236252 else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) {
237253 gt_input.i_cursor = 0;
238254 gt_input.b_option = b_option;
@@ -257,6 +273,7 @@ int
257273 gt_input.i_buflen = sizeof( gt_input.str_input );
258274 }
259275 }
276+ */
260277 else if( TUIKEY_MODE_YESNO == i_mode ) {
261278 if( NULL != pstr_msg )
262279 { strncpy( gt_input.str_msg, pstr_msg, sizeof( gt_input.str_msg ) ); }
@@ -311,81 +328,132 @@ int
311328
312329 if( ERR == i_key ) { return i_ret; }
313330
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--; }
317336
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;
322338 }
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;
327347
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;
331354 }
332355 }
333356
334357 // Enter ---
335- else if(( KEY_ENTER == i_key) || ( 10 == i_key )) {
358+ if(( KEY_ENTER == i_key) || ( 10 == i_key )) {
336359 if( NULL != gt_input.fp_inputstr ) {
337360 gt_input.fp_inputstr( gt_input.i_hvisor, gt_input.i_guest,
338361 gt_input.b_reqcmd, gt_input.b_option,
339362 gt_input.i_inputlen, gt_input.str_input );
340363 }
341- }
342364
365+ goto goto_TuiKey_Dispatch_Mode_InputStr_post;
366+ }
343367 // KEY_ESC ---
344368 else if( 27 == i_key ) {
345369 TuiKey_ReturnMode();
346- }
347370
371+ goto goto_TuiKey_Dispatch_Mode_InputStr_post;
372+ }
348373 // BackSpace ---
349374 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+ }
364387 }
365- }
366388
389+ goto goto_TuiKey_Dispatch_Mode_InputStr_post;
390+ }
367391 // Clear ---
368392 else if( NCURSES_Ctrl('l') == i_key ) {
369393 gt_input.i_cursor = 0;
370394 gt_input.i_inputlen = 0;
371- //gt_input.i_input = 0;
372395 gt_input.str_input[0] = '\0';
396+
397+ goto goto_TuiKey_Dispatch_Mode_InputStr_post;
373398 }
374399
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; }
378411 }
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; }
381417 }
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+ }
384434 }
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';
387444 }
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+
388455
456+goto_TuiKey_Dispatch_Mode_InputStr_post:
389457 return i_ret;
390458 }
391459
--- a/src/tuikey.h
+++ b/src/tuikey.h
@@ -61,9 +61,13 @@ VMTUI_TUIKEY_EXTERN int TuiKey_Term( void );
6161 #define TUIKEY_MODE_GUEST (0x02+TUIKEY_MODE_INFO)
6262 #define TUIKEY_MODE_CONSOLE (0x03+TUIKEY_MODE_INFO)
6363 #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
6771 #define TUIKEY_MODE_NONE 0xff
6872
6973 #define NCURSES_KEY_ENTER 10
@@ -99,7 +103,6 @@ typedef struct {
99103 int i_inputlen;
100104 int i_buflen;
101105 char str_input[512];
102- //char str_option[512];
103106 char str_msg[128];
104107 void *pv_option;
105108 } TuiKey_InputLine;