Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/screen.c @ 102:2b4cc6bc5bf2
[/trunk] Changeset 116 by mikael
* Can now complete command parameters :-)
author | mikael |
---|---|
date | Thu, 21 Apr 2005 19:06:27 +0000 |
parents | 4f3ad00b5187 |
children | 93dcc4e15d4a |
comparison
equal
deleted
inserted
replaced
101:4f3ad00b5187 | 102:2b4cc6bc5bf2 |
---|---|
585 // which_row() | 585 // which_row() |
586 // Tells which row our cursor is in, in the command line. | 586 // Tells which row our cursor is in, in the command line. |
587 // -1 -> normal text | 587 // -1 -> normal text |
588 // 0 -> command | 588 // 0 -> command |
589 // 1 -> parameter 1 (etc.) | 589 // 1 -> parameter 1 (etc.) |
590 int which_row(void) | 590 // If > 0, then *p_row is set to the beginning of the row |
591 int which_row(char **p_row) | |
591 { | 592 { |
592 int row = -1; | 593 int row = -1; |
593 char *p; | 594 char *p; |
594 int quote = FALSE; | 595 int quote = FALSE; |
595 | 596 |
605 quote = FALSE; | 606 quote = FALSE; |
606 continue; | 607 continue; |
607 } | 608 } |
608 if (*p == '"' && *(p-1) != '\\') { | 609 if (*p == '"' && *(p-1) != '\\') { |
609 quote = TRUE; | 610 quote = TRUE; |
610 } else if (*p == ' ' && *(p-1) != ' ') | 611 } else if (*p == ' ' && *(p-1) != ' ') { |
611 row++; | 612 row++; |
613 *p_row = p+1; | |
614 } | |
612 } | 615 } |
613 return row; | 616 return row; |
614 } | 617 } |
615 | 618 |
616 void scr_insert_text(const char *text) | 619 void scr_insert_text(const char *text) |
628 strcpy(ptr_inputline, tmpLine); | 631 strcpy(ptr_inputline, tmpLine); |
629 } | 632 } |
630 | 633 |
631 void scr_handle_tab(void) | 634 void scr_handle_tab(void) |
632 { | 635 { |
633 int row; | 636 int nrow; |
634 row = which_row(); | 637 cmd *com; |
635 | 638 char *row; |
636 if (row == -1) return; // No completion if no leading slash | 639 const char *cchar; |
637 | 640 |
638 if (row == 0) { // Command completion | 641 nrow = which_row(&row); |
639 const char *cchar; | 642 |
643 if (nrow == -1) return; // No completion if no leading slash | |
644 | |
645 if (nrow == 0) { // Command completion | |
640 if (!completion_started) { | 646 if (!completion_started) { |
641 GSList *list = compl_get_category_list(COMPL_CMD); | 647 GSList *list = compl_get_category_list(COMPL_CMD); |
642 if (list) { | 648 if (list) { |
643 char *prefix = g_strndup(&inputLine[1], ptr_inputline-inputLine-1); | 649 char *prefix = g_strndup(&inputLine[1], ptr_inputline-inputLine-1); |
644 // Init completion | 650 // Init completion |
648 cchar = complete(); | 654 cchar = complete(); |
649 if (cchar) | 655 if (cchar) |
650 scr_insert_text(cchar); | 656 scr_insert_text(cchar); |
651 completion_started = TRUE; | 657 completion_started = TRUE; |
652 } | 658 } |
653 } else { | 659 } else { // Completion already initialized |
654 char *c; | 660 char *c; |
655 guint back = cancel_completion(); | 661 guint back = cancel_completion(); |
656 // Remove $back chars | 662 // Remove $back chars |
657 ptr_inputline -= back; | 663 ptr_inputline -= back; |
658 c = ptr_inputline; | 664 c = ptr_inputline; |
665 } | 671 } |
666 return; | 672 return; |
667 } | 673 } |
668 | 674 |
669 // Other completion, depending on the command | 675 // Other completion, depending on the command |
670 scr_LogPrint("I'm unable to complete that yet"); | 676 com = cmd_get(inputLine); |
677 if (!com) { | |
678 scr_LogPrint("I cannot complete for this command"); | |
679 return; | |
680 } | |
681 // Now we have the command and the column. | |
682 scr_LogPrint("CMD_FLAGR1=%d COL=%d row=[%s]", com->completion_flags[0], nrow, row); | |
683 | |
684 // We can't have more than 2 parameters (we use 2 flags) | |
685 if (nrow > 2) | |
686 return; | |
687 | |
688 // Dirty copy & paste | |
689 if (!completion_started) { | |
690 GSList *list = compl_get_category_list(com->completion_flags[nrow-1]); | |
691 if (list) { | |
692 char *prefix = g_strndup(row, ptr_inputline-row); | |
693 // Init completion | |
694 new_completion(prefix, list); | |
695 g_free(prefix); | |
696 // Now complete | |
697 cchar = complete(); | |
698 if (cchar) | |
699 scr_insert_text(cchar); | |
700 completion_started = TRUE; | |
701 } | |
702 } else { // Completion already initialized | |
703 char *c; | |
704 guint back = cancel_completion(); | |
705 // Remove $back chars | |
706 ptr_inputline -= back; | |
707 c = ptr_inputline; | |
708 for ( ; *c ; c++) | |
709 *c = *(c+back); | |
710 // Now complete again | |
711 cchar = complete(); | |
712 if (cchar) | |
713 scr_insert_text(cchar); | |
714 } | |
671 } | 715 } |
672 | 716 |
673 void scr_cancel_current_completion(void) | 717 void scr_cancel_current_completion(void) |
674 { | 718 { |
675 char *c; | 719 char *c; |