Beispiel #1
0
    def user_key_ex(self, key):
        """
        Handle keys in ex mode
        TODO: expand this section to handle multi command
        arguments
        i.e finds should work in visual mode
        Dependent upon a proper command parser however

        This mode is kind of limited for now since we don't
        have a proper command parser yet
        """
        if key == 'Return':
            cmd = self._ex_parser.parse_string(self._command_buffer)
            interaction_manager.input_command(
                cmd, self._graphics,
                self.get_curr_instance(), self
            )
            self._curr_state = 'Default'
            self._command_buffer = ''
        else:
            self._command_buffer = (
                self._command_buffer + key,
                self._command_buffer[:-1]
            )[key == 'BackSpace']

            interaction_manager.render_page(
                self._graphics,
                self.get_curr_instance(), self
            )
Beispiel #2
0
    def user_key_default(self, key):
        """
        Handle keys in default mode
        """
        mode_dict = {
            'i': self.init_insert_mode,
            'v': self.init_visual_mode,
            ':': self.init_ex_mode,
        }

        if key in DEFAULT_COMMAND_LEADERS \
            or self.is_digit(key) \
                or len(self._command_buffer):
            self._command_buffer += key
            s_par = self._default_parser.parse_string(self._command_buffer)

            if s_par != '' or key in DEFAULT_BREAK_MOVEMENTS:
                cmd = s_par if s_par != '' else DEFAULT_BREAK_MOVEMENTS[key]
                interaction_manager.input_command(cmd, self._graphics,
                                                  self.get_curr_instance(),
                                                  self)
                self._command_buffer = ''

        elif key in DEFAULT_MOVEMENTS:  # default movement requested
            interaction_manager.input_command(DEFAULT_MOVEMENTS[key],
                                              self._graphics,
                                              self.get_curr_instance(), self)
            self._command_buffer = ''
        elif key in mode_dict:  # mode change requested
            mode_dict[key]()
Beispiel #3
0
    def user_key_default(self, key):
        """
        Handle keys in default mode
        """
        mode_dict = {
            'i': self.init_insert_mode,
            'v': self.init_visual_mode,
            ':': self.init_ex_mode,
        }

        if key in DEFAULT_COMMAND_LEADERS \
            or self.is_digit(key) \
                or len(self._command_buffer):
            self._command_buffer += key
            s_par = self._default_parser.parse_string(
                self._command_buffer
            )

            if s_par != '' or key in DEFAULT_BREAK_MOVEMENTS:
                cmd = s_par if s_par != '' else DEFAULT_BREAK_MOVEMENTS[key]
                interaction_manager.input_command(
                    cmd, self._graphics, self.get_curr_instance(), self)
                self._command_buffer = ''

        elif key in DEFAULT_MOVEMENTS:  # default movement requested
            interaction_manager.input_command(
                DEFAULT_MOVEMENTS[key], self._graphics,
                self.get_curr_instance(), self
            )
            self._command_buffer = ''
        elif key in mode_dict:  # mode change requested
            mode_dict[key]()
Beispiel #4
0
 def mouse_scroll(self, event):
     """
     Scroll mouse depending on direction moved by
     calling cursor up or cursor down repeatedly.
     TODO: This is clearly not optimal. The calling
     move_cursor_up or down re-renders the page repeatedly and
     is inefficient
     """
     delta = event.delta * -1
     self._curr_state = 'Default'
     self._command_buffer = ''
     cmd = ['n' + str(delta), 'mouse_scroll']
     interaction_manager.input_command(
         cmd, self._graphics, self.get_curr_instance(), None)
Beispiel #5
0
 def mouse_scroll(self, event):
     """
     Scroll mouse depending on direction moved by
     calling cursor up or cursor down repeatedly.
     TODO: This is clearly not optimal. The calling
     move_cursor_up or down re-renders the page repeatedly and
     is inefficient
     """
     delta = event.delta * -1
     self._curr_state = 'Default'
     self._command_buffer = ''
     cmd = ['n' + str(delta), 'mouse_scroll']
     interaction_manager.input_command(cmd, self._graphics,
                                       self.get_curr_instance(), None)
Beispiel #6
0
 def user_key_visual(self, key):
     """
     Handle keys in visual mode
     TODO: expand this section to handle multi command
     arguments
     i.e finds should work in visual mode
     Dependent upon a proper command parser however
     """
     if key in VISUAL_MOVEMENTS:
         motion = VISUAL_MOVEMENTS[key]
         cmd = ['s' + motion[0], 'visual_movement']
         interaction_manager.input_command(cmd, self._graphics,
                                           self.get_curr_instance(), self)
         self._command_buffer = ''
     elif key in VISUAL_BREAK_MOVEMENTS:
         cmd = VISUAL_BREAK_MOVEMENTS[key]
         interaction_manager.input_command(cmd, self._graphics,
                                           self.get_curr_instance(), self)
         self._command_buffer = ''
Beispiel #7
0
 def user_key_visual(self, key):
     """
     Handle keys in visual mode
     TODO: expand this section to handle multi command
     arguments
     i.e finds should work in visual mode
     Dependent upon a proper command parser however
     """
     if key in VISUAL_MOVEMENTS:
         motion = VISUAL_MOVEMENTS[key]
         cmd = ['s' + motion[0], 'visual_movement']
         interaction_manager.input_command(
             cmd, self._graphics,
             self.get_curr_instance(), self
         )
         self._command_buffer = ''
     elif key in VISUAL_BREAK_MOVEMENTS:
         cmd = VISUAL_BREAK_MOVEMENTS[key]
         interaction_manager.input_command(
             cmd, self._graphics,
             self.get_curr_instance(), self
         )
         self._command_buffer = ''
Beispiel #8
0
    def user_key_ex(self, key):
        """
        Handle keys in ex mode
        TODO: expand this section to handle multi command
        arguments
        i.e finds should work in visual mode
        Dependent upon a proper command parser however

        This mode is kind of limited for now since we don't
        have a proper command parser yet
        """
        if key == 'Return':
            cmd = self._ex_parser.parse_string(self._command_buffer)
            interaction_manager.input_command(cmd, self._graphics,
                                              self.get_curr_instance(), self)
            self._curr_state = 'Default'
            self._command_buffer = ''
        else:
            self._command_buffer = (
                self._command_buffer + key,
                self._command_buffer[:-1])[key == 'BackSpace']

            interaction_manager.render_page(self._graphics,
                                            self.get_curr_instance(), self)
Beispiel #9
0
    def user_key_insert(self, key):
        """
        Handle keys in insert mode

        This should be the only state that should contain
        at least these mappings no matter the configuration
        """
        if key not in ['BackSpace', 'Return']:
            cmd = ['s' + key, 'insert_text']
            interaction_manager.input_command(cmd, self._graphics,
                                              self.get_curr_instance(), self)
        elif key == 'BackSpace':
            interaction_manager.input_command(['delete_char'], self._graphics,
                                              self.get_curr_instance(), self)
        # similar to above
        elif key == 'Return':
            interaction_manager.input_command(['add_new_line'], self._graphics,
                                              self.get_curr_instance(), self)
Beispiel #10
0
    def user_key_insert(self, key):
        """
        Handle keys in insert mode

        This should be the only state that should contain
        at least these mappings no matter the configuration
        """
        if key not in ['BackSpace', 'Return']:
            cmd = ['s' + key, 'insert_text']
            interaction_manager.input_command(
                cmd, self._graphics,
                self.get_curr_instance(), self
            )
        elif key == 'BackSpace':
            interaction_manager.input_command(
                ['delete_char'], self._graphics,
                self.get_curr_instance(), self
            )
        # similar to above
        elif key == 'Return':
            interaction_manager.input_command(
                ['add_new_line'], self._graphics,
                self.get_curr_instance(), self
            )