summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Levin <avi.levin@samsung.com>2015-09-02 16:55:48 +0300
committerAvi Levin <avi.levin@samsung.com>2015-09-02 16:55:48 +0300
commitdfd9a754ac6ff30632ad4b5b88cb2de538b2500a (patch)
tree6e51b40491db8f01f8d388c16e838a12ab0eb0a9
parentf4738ea75213138db1ef184574bd78411650f0b6 (diff)
Add autocompletions for Eo classes
After running list command autocompletions for classes is filled up. Next time we can write: list Evas[Tab] and it will autocomplete.
-rw-r--r--src/bin/cli.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/bin/cli.c b/src/bin/cli.c
index efb04e0..35b093c 100644
--- a/src/bin/cli.c
+++ b/src/bin/cli.c
@@ -14,7 +14,7 @@
14 14
15#define MAX_EVENTS 5 15#define MAX_EVENTS 5
16 16
17struct Ac_Node *ac_commands_root = NULL; 17struct Ac_Node *ac_commands_root = NULL, *ac_classes_root = NULL;
18 18
19static Eina_Hash *vars_hash = NULL; 19static Eina_Hash *vars_hash = NULL;
20static Eina_Bool exit_required = EINA_FALSE; 20static Eina_Bool exit_required = EINA_FALSE;
@@ -77,6 +77,26 @@ _next_token(Lexer *l, const char *token)
77 return EINA_FALSE; 77 return EINA_FALSE;
78} 78}
79 79
80static const char *
81_last_word(Lexer *l, const char *special)
82{
83 if(l->buf_end <= 0)
84 return NULL;
85
86 if (!special) special = "";
87
88 const char *str = l->buffer+(l->buf_end-1);
89 while (*str &&
90 ((*str >= 'a' && *str <= 'z') ||
91 (*str >= 'A' && *str <= 'Z') ||
92 (*str >= '0' && *str <= '9') ||
93 strchr(special, *str) ||
94 *str == '_')) str--;
95 if (str == (l->buffer + l->buf_end - 1)) return NULL;
96 str++;
97 return str;
98}
99
80static char * 100static char *
81_next_word(Lexer *l, const char *special) 101_next_word(Lexer *l, const char *special)
82{ 102{
@@ -349,13 +369,20 @@ _char_consume(Lexer *l, char c)
349 } 369 }
350 case 0x09: /* Tab */ 370 case 0x09: /* Tab */
351 { 371 {
352 char *word = _next_word(l, NULL); 372 char *word = _last_word(l, NULL);
373
353 char *buffer; 374 char *buffer;
354 Eina_List *comps = NULL; 375 Eina_List *comps = NULL;
355 376
356 if(word) 377 if(word)
357 { 378 {
358 comps = ac_get_autocompletions(ac_commands_root, word, 1); 379 if(word == l->current){/* First word */
380
381 comps = ac_get_autocompletions(ac_commands_root, word, 1);
382 }
383 else{
384 comps = ac_get_autocompletions(ac_classes_root, word, 1);
385 }
359 } 386 }
360 387
361 printf("\r%*c\r", l->buf_end, ' '); 388 printf("\r%*c\r", l->buf_end, ' ');
@@ -363,11 +390,10 @@ _char_consume(Lexer *l, char c)
363 if(comps) 390 if(comps)
364 { 391 {
365 buffer = eina_list_nth(comps, 0); 392 buffer = eina_list_nth(comps, 0);
393
366 strcpy(l->buffer+l->buf_end, buffer); 394 strcpy(l->buffer+l->buf_end, buffer);
367 printf("%s", l->buffer+l->buf_end-strlen(word));
368 395
369 l->buf_end += strlen(buffer); 396 l->buf_end += strlen(buffer);
370 l->current -= strlen(word);
371 397
372 free(buffer); 398 free(buffer);
373 eina_list_free(comps); 399 eina_list_free(comps);
@@ -375,8 +401,9 @@ _char_consume(Lexer *l, char c)
375 else 401 else
376 { 402 {
377 l->buffer[l->buf_end] = '\0'; 403 l->buffer[l->buf_end] = '\0';
378 printf("%s", l->buffer);
379 } 404 }
405 printf("%s", l->buffer);
406
380 break; 407 break;
381 } 408 }
382 default: 409 default:
@@ -441,6 +468,7 @@ _list_resp_handler(const void *buf, int size, void **buf_ret, int *size_ret)
441 { 468 {
442 eina_hash_add(objects_hash, &info->ptr, 469 eina_hash_add(objects_hash, &info->ptr,
443 info); 470 info);
471 ac_insert(&ac_classes_root, info->kl_name);
444 } 472 }
445 473
446 /* Fill children lists */ 474 /* Fill children lists */
@@ -559,6 +587,7 @@ main()
559 free(buffer); 587 free(buffer);
560 588
561 ac_free(ac_commands_root); 589 ac_free(ac_commands_root);
590 ac_free(ac_classes_root);
562 591
563 eolian_shutdown(); 592 eolian_shutdown();
564 593