sources/interface.cpp

changeset 43
0bc07f54f522
parent 42
9699687081df
child 44
693d7751fff0
equal deleted inserted replaced
42:9699687081df 43:0bc07f54f522
582 mvprintw (y, interface_prompt_string().length(), " "); 582 mvprintw (y, interface_prompt_string().length(), " ");
583 } 583 }
584 584
585 // ------------------------------------------------------------------------------------------------- 585 // -------------------------------------------------------------------------------------------------
586 // 586 //
587 static FUNCTION
588 interface_find_previous_word() -> int
589 {
590 const String& input = current_input();
591 int pos = g_cursor;
592
593 // Move past whitespace
594 while (pos > 0 and isspace (input[pos - 1]))
595 pos--;
596
597 // Move past the word
598 while (pos > 0 and not isspace (input[pos - 1]))
599 pos--;
600
601 return pos;
602 }
603
604 // -------------------------------------------------------------------------------------------------
605 //
606 static FUNCTION
607 interface_find_next_word() -> int
608 {
609 const String& input = current_input();
610 int pos = g_cursor;
611
612 // Move past current whitespace
613 while (pos < input.length() and isspace (input[pos]))
614 pos++;
615
616 // Move past the word
617 while (input[pos] != '\0' and not isspace (input[pos]))
618 pos++;
619
620 return pos;
621 }
622
623 // -------------------------------------------------------------------------------------------------
624 //
587 FUNCTION 625 FUNCTION
588 Interface::handle_input() -> void 626 Interface::handle_input() -> void
589 { 627 {
590 int ch = ::getch(); 628 int ch = ::getch();
591 629
647 case INPUTSTATE_ADDRESS: 685 case INPUTSTATE_ADDRESS:
648 set_input_state (INPUTSTATE_NORMAL); 686 set_input_state (INPUTSTATE_NORMAL);
649 } 687 }
650 break; 688 break;
651 689
652 case '\e':
653 if (g_inputState == INPUTSTATE_PASSWORD)
654 set_input_state (INPUTSTATE_ADDRESS);
655 else if (g_inputState == INPUTSTATE_ADDRESS)
656 set_input_state (INPUTSTATE_NORMAL);
657 break;
658
659 case KEY_LEFT: 690 case KEY_LEFT:
660 case 'B' - 'A' + 1: // readline ^B 691 case 'B' - 'A' + 1: // readline ^B
661 if (g_cursor > 0) 692 if (g_cursor > 0)
662 { 693 {
663 g_cursor--; 694 g_cursor--;
788 819
789 case 'N' - 'A' + 1: // ^N 820 case 'N' - 'A' + 1: // ^N
790 if (g_inputState == INPUTSTATE_NORMAL) 821 if (g_inputState == INPUTSTATE_NORMAL)
791 safe_disconnect ([]() {set_input_state (INPUTSTATE_ADDRESS);}); 822 safe_disconnect ([]() {set_input_state (INPUTSTATE_ADDRESS);});
792 break; 823 break;
824
825 case '\e': // Escape
826 // We may have an alt key coming
827 ch = ::getch();
828
829 if (ch != ERR)
830 {
831 switch (ch)
832 {
833 case 'b':
834 case 'B':
835 // readline alt-b - move one word to the left
836 g_cursor = interface_find_previous_word();
837 g_needInputRender = true;
838 break;
839
840 case 'f':
841 case 'F':
842 // readline alt-f - move one word to the right
843 g_cursor = interface_find_next_word();
844 g_needInputRender = true;
845 break;
846 }
847 }
848 else
849 {
850 // No alt-key, handle pure escape
851 if (g_inputState == INPUTSTATE_PASSWORD)
852 set_input_state (INPUTSTATE_ADDRESS);
853 else if (g_inputState == INPUTSTATE_ADDRESS)
854 set_input_state (INPUTSTATE_NORMAL);
855 }
856 break;
793 } 857 }
794 } 858 }
795 859
796 // ------------------------------------------------------------------------------------------------- 860 // -------------------------------------------------------------------------------------------------
797 // 861 //

mercurial