sources/interface.cpp

changeset 53
8f1a6f40d1b4
parent 52
ae5b486f6882
child 54
e20e306c886d
equal deleted inserted replaced
52:ae5b486f6882 53:8f1a6f40d1b4
61 static InputState g_inputState = INPUTSTATE_NORMAL; 61 static InputState g_inputState = INPUTSTATE_NORMAL;
62 static Function<void (void)> g_disconnectConfirmFunction = nullptr; 62 static Function<void (void)> g_disconnectConfirmFunction = nullptr;
63 static IPAddress g_address; 63 static IPAddress g_address;
64 static String g_statusBarText; 64 static String g_statusBarText;
65 static StringList g_playerNames; 65 static StringList g_playerNames;
66 static String g_pasteBuffer;
66 67
67 // ------------------------------------------------------------------------------------------------- 68 // -------------------------------------------------------------------------------------------------
68 // 69 //
69 static FUNCTION 70 static FUNCTION
70 interface_color_pair (Color fg, Color bg) -> int 71 interface_color_pair (Color fg, Color bg) -> int
625 return pos; 626 return pos;
626 } 627 }
627 628
628 // ------------------------------------------------------------------------------------------------- 629 // -------------------------------------------------------------------------------------------------
629 // 630 //
631 static FUNCTION
632 interface_yank_and_delete (int a, int b) -> void
633 {
634 if (a >= b)
635 return;
636
637 if (g_cursor > a and g_cursor <= b)
638 g_cursor = a;
639
640 String& input = mutable_current_input();
641 g_pasteBuffer = input.mid (a, b);
642 input.remove (a, b - a);
643 g_needInputRender = true;
644 }
645
646 // -------------------------------------------------------------------------------------------------
647 //
630 FUNCTION 648 FUNCTION
631 Interface::handle_input() -> void 649 Interface::handle_input() -> void
632 { 650 {
633 int ch = ::getch(); 651 int ch = ::getch();
634 652
761 break; 779 break;
762 780
763 case 'U' - 'A' + 1: // readline ^U - delete from start to cursor 781 case 'U' - 'A' + 1: // readline ^U - delete from start to cursor
764 if (g_cursor > 0) 782 if (g_cursor > 0)
765 { 783 {
766 mutable_current_input().remove (0, g_cursor); 784 interface_yank_and_delete (0, g_cursor);
767 g_cursor = 0; 785 g_cursor = 0;
786 }
787 break;
788
789 case 'K' - 'A' + 1: // readline ^K - delete from cursor to end
790 interface_yank_and_delete (g_cursor, mutable_current_input().length());
791 break;
792
793 case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current
794 interface_yank_and_delete (interface_find_previous_word(), g_cursor);
795 break;
796
797 case 'Y' - 'A' + 1: // readline ^Y - paste previously deleted text
798 if (not g_pasteBuffer.is_empty())
799 {
800 mutable_current_input().insert (g_cursor, g_pasteBuffer);
801 g_cursor += g_pasteBuffer.length();
768 g_needInputRender = true; 802 g_needInputRender = true;
769 } 803 }
770 break; 804 else
771 805 print ("paste buffer is empty\n");
772 case 'K' - 'A' + 1: // readline ^K - delete from cursor to end
773 if (g_cursor < current_input().length())
774 {
775 String& input = mutable_current_input();
776 input.remove (g_cursor, input.length() - g_cursor);
777 g_needInputRender = true;
778 }
779 break;
780
781 case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current
782 {
783 int start = interface_find_previous_word();
784
785 if (start != g_cursor)
786 {
787 mutable_current_input().remove (start, g_cursor - start);
788 g_cursor = start;
789 g_needInputRender = true;
790 }
791 }
792 break; 806 break;
793 807
794 case '\n': 808 case '\n':
795 case KEY_ENTER: 809 case KEY_ENTER:
796 switch (g_inputState) 810 switch (g_inputState)
863 break; 877 break;
864 878
865 case 'd': 879 case 'd':
866 case 'D': 880 case 'D':
867 // readline alt-d - delete from here till next word boundary 881 // readline alt-d - delete from here till next word boundary
868 mutable_current_input().remove (g_cursor, interface_find_next_word() - g_cursor); 882 interface_yank_and_delete (g_cursor, interface_find_next_word());
869 g_needInputRender = true;
870 break; 883 break;
871 } 884 }
872 } 885 }
873 else 886 else
874 { 887 {

mercurial