예제 #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 = command_parser.ex_parse(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
            )
예제 #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 = command_parser.default_parse(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]()
예제 #3
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)
예제 #4
0
파일: user_input.py 프로젝트: mkim/shim
 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 = ''
예제 #5
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
            )