• 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

Revisionbbc568effb50bfc8595c2ce09568596cbad37cdc (tree)
Time2023-06-27 22:28:41
AuthorKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

Support input cursor with InputString/InputPassword Mode.

Change Summary

Incremental Difference

--- a/src/tuicmd.c
+++ b/src/tuicmd.c
@@ -38,6 +38,9 @@ int
3838 {
3939 int i_mode;
4040 int i_len;
41+ int i_cursor;
42+ int i_start;
43+ int i_row;
4144 char *pstr_input;
4245 char *pstr_prompt;
4346 char str_pass[ HVISOR_SSH_MAXLEN_PASSWORD ];
@@ -46,18 +49,22 @@ int
4649
4750 pstr_prompt = TuiKey_GetPromptString();
4851
49- mvwprintw( gp_cmd_win, 0, 0, "%s", pstr_prompt );
52+ mvwprintw( gp_cmd_win, 0, 0, "%s => ", pstr_prompt );
5053
5154 i_mode = TuiKey_GetMode();
5255 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 );
5562 }
5663 else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) {
57- pstr_input = TuiKey_GetInputStringAndPasswd( &i_len );
64+ pstr_input = TuiKey_GetInputStringAndPasswd( &i_len, NULL );
5865 str_pass[ i_len-- ] = '\0';
5966 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 );
6168 }
6269
6370 touchwin( gp_cmd_win );
--- a/src/tuikey.c
+++ b/src/tuikey.c
@@ -137,7 +137,7 @@ int
137137 VMTUI_TUIKEY_EXTERN
138138 char *
139139 TuiKey_GetInputStringAndPasswd(
140- int *pi_len )
140+ int *pi_len, int *pi_cursor )
141141 {
142142 if(( TUIKEY_MODE_INPUTSTR != gi_keymode ) && ( TUIKEY_MODE_INPUTPASSWD != gi_keymode )) {
143143 return NULL;
@@ -146,6 +146,9 @@ char *
146146 if( NULL != pi_len )
147147 { *pi_len = gt_input.i_inputlen; }
148148
149+ if( NULL != pi_cursor )
150+ { *pi_cursor = gt_input.i_cursor; }
151+
149152 return gt_input.str_input;
150153 }
151154
@@ -161,6 +164,29 @@ char *
161164 /* ===========================================================================*/
162165 VMTUI_TUIKEY_EXTERN
163166 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
164190 TuiKey_ChangeMode(
165191 int i_mode,
166192 Byte b_reqcmd,
@@ -180,6 +206,7 @@ int
180206 gt_input.i_retmode = i_retmode;
181207
182208 if( TUIKEY_MODE_INPUTSTR == i_mode ) {
209+ gt_input.i_cursor = 0;
183210 gt_input.i_inputlen = 0;
184211 gt_input.i_input = 0;
185212 gt_input.str_input[0] = '\0';
@@ -190,6 +217,7 @@ int
190217 { strncpy( gt_input.str_msg, "Input String", sizeof( gt_input.str_msg ) ); }
191218 }
192219 else if( TUIKEY_MODE_INPUTPASSWD == i_mode ) {
220+ gt_input.i_cursor = 0;
193221 gt_input.i_inputlen = 0;
194222 gt_input.i_input = 0;
195223 gt_input.str_input[0] = '\0';
@@ -253,12 +281,26 @@ int
253281
254282 if( ERR == i_key ) { return i_ret; }
255283
284+ // Input Character ---
256285 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++;
258290 gt_input.str_input[gt_input.i_inputlen++] = (char)i_key;
259291 gt_input.str_input[gt_input.i_inputlen] = '\0';
260292 }
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+ }
261301 }
302+
303+ // Enter ---
262304 else if(( KEY_ENTER == i_key) || ( 10 == i_key )) {
263305 if( NULL != gt_input.fp_inputstr ) {
264306 gt_input.fp_inputstr( gt_input.i_hvisor, gt_input.i_guest,
@@ -266,16 +308,51 @@ int
266308 gt_input.i_inputlen, gt_input.str_input );
267309 }
268310 }
269- // KEY_ESC
311+
312+ // KEY_ESC ---
270313 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();
274315 }
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--;
277325 gt_input.str_input[--gt_input.i_inputlen] = '\0';
278326 }
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;
279356 }
280357
281358 return i_ret;
@@ -297,9 +374,7 @@ int
297374 { i_ret = 0x01; }
298375 }
299376
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();
303378
304379 return i_ret;
305380 }
--- a/src/tuikey.h
+++ b/src/tuikey.h
@@ -42,8 +42,10 @@ VMTUI_TUIKEY_EXTERN int TuiKey_TestCode( void );
4242 VMTUI_TUIKEY_EXTERN char *TuiKey_GetKeyName( char *pstr_buf, int i_len, int i_key );
4343 VMTUI_TUIKEY_EXTERN int TuiKey_ChangeInfoWindow( int i_direction );
4444 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 );
4646 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 );
4749 VMTUI_TUIKEY_EXTERN int TuiKey_ChangeMode(
4850 int i_mode, Byte b_reqcmd, int i_hvisor, int i_guest,
4951 InputStrFunction fp_handler, Byte b_option, int i_retmode, char *pstr_msg );
@@ -88,14 +90,17 @@ typedef struct {
8890 int i_guest;
8991 Byte b_option;
9092
93+ int i_cursor;
94+
9195 int i_retmode;
9296 InputStrFunction fp_inputstr;
9397
9498 int i_inputlen;
9599 int i_input;
96100 char str_input[512];
97- char str_option[512];
101+ //char str_option[512];
98102 char str_msg[128];
103+ void *pv_option;
99104 } TuiKey_InputLine;
100105
101106 #ifdef VMTUI_SRC_TUIKEY