Text box key validator: Callback of key strokes. Handles a user's keypress in the input text box. Translates certain keys to terminator keys for the textbox to allow its edit() method to return. Also handles special key-triggered events such as PgUp/PgDown scrolling of the screen ou
(self, x)
| 775 | return txt.strip() |
| 776 | |
| 777 | def _on_textbox_keypress(self, x): |
| 778 | """Text box key validator: Callback of key strokes. |
| 779 | |
| 780 | Handles a user's keypress in the input text box. Translates certain keys to |
| 781 | terminator keys for the textbox to allow its edit() method to return. |
| 782 | Also handles special key-triggered events such as PgUp/PgDown scrolling of |
| 783 | the screen output. |
| 784 | |
| 785 | Args: |
| 786 | x: (int) Key code. |
| 787 | |
| 788 | Returns: |
| 789 | (int) A translated key code. In most cases, this is identical to the |
| 790 | input x. However, if x is a Return key, the return value will be |
| 791 | CLI_TERMINATOR_KEY, so that the text box's edit() method can return. |
| 792 | |
| 793 | Raises: |
| 794 | TypeError: If the input x is not of type int. |
| 795 | debugger_cli_common.CommandLineExit: If a mouse-triggered command returns |
| 796 | an exit token when dispatched. |
| 797 | """ |
| 798 | if not isinstance(x, int): |
| 799 | raise TypeError("Key validator expected type int, received type %s" % |
| 800 | type(x)) |
| 801 | |
| 802 | if x in self.CLI_CR_KEYS: |
| 803 | # Make Enter key the terminator |
| 804 | self._textbox_curr_terminator = x |
| 805 | return self.CLI_TERMINATOR_KEY |
| 806 | elif x == self.CLI_TAB_KEY: |
| 807 | self._textbox_curr_terminator = self.CLI_TAB_KEY |
| 808 | return self.CLI_TERMINATOR_KEY |
| 809 | elif x == curses.KEY_PPAGE: |
| 810 | self._scroll_output(_SCROLL_UP_A_LINE) |
| 811 | return x |
| 812 | elif x == curses.KEY_NPAGE: |
| 813 | self._scroll_output(_SCROLL_DOWN_A_LINE) |
| 814 | return x |
| 815 | elif x == curses.KEY_HOME: |
| 816 | self._scroll_output(_SCROLL_HOME) |
| 817 | return x |
| 818 | elif x == curses.KEY_END: |
| 819 | self._scroll_output(_SCROLL_END) |
| 820 | return x |
| 821 | elif x in [curses.KEY_UP, curses.KEY_DOWN]: |
| 822 | # Command history navigation. |
| 823 | if not self._active_command_history: |
| 824 | hist_prefix = self._screen_gather_textbox_str() |
| 825 | self._active_command_history = ( |
| 826 | self._command_history_store.lookup_prefix( |
| 827 | hist_prefix, self._command_history_limit)) |
| 828 | |
| 829 | if self._active_command_history: |
| 830 | if x == curses.KEY_UP: |
| 831 | if self._command_pointer < len(self._active_command_history): |
| 832 | self._command_pointer += 1 |
| 833 | elif x == curses.KEY_DOWN: |
| 834 | if self._command_pointer > 0: |