Beispiel #1
0
 def on_feed_key(self, key_press):
     """Handles the magictyping when a key is pressed"""
     if key_press.key in {Keys.Escape, Keys.ControlC}:
         echo(carriage_return=True)
         raise Abort()
     if key_press.key == Keys.Backspace:
         if self.current_command_pos > 0:
             self.current_command_pos -= 1
         return key_press
     ret = None
     if key_press.key != Keys.CPRResponse:
         if self.current_command_pos < len(self.current_command):
             current_key = self.current_command_key
             ret = KeyPress(current_key)
             increment = min([
                 self.speed,
                 len(self.current_command) - self.current_command_pos
             ])
             self.current_command_pos += increment
         else:
             # Command is finished, wait for Enter
             if key_press.key != Keys.Enter:
                 return None
             self.current_command_index += 1
             self.current_command_pos = 0
             ret = key_press
     return ret
Beispiel #2
0
    def _next_keys(self, key_press):
        """Handles the magic typing when a key is pressed"""

        if key_press.key in {Keys.Escape, Keys.ControlC}:
            echo(carriage_return=True)
            raise Abort()

        if key_press.key == Keys.Backspace:
            self.current_command_pos = max(0, self.current_command_pos - 1)
            return [key_press]

        if key_press.key == Keys.CPRResponse:
            return []

        if self.current_command_pos < len(self.current_command()):
            current_keys = self.current_command_keys()
            self.advance()
            return [KeyPress(k) for k in current_keys]

        # Command is finished, wait for Enter
        if key_press.key != Keys.Enter:
            return []

        self.current_command_index += 1
        self.current_command_pos = 0
        return [key_press]
Beispiel #3
0
    def interact(self, display_banner=DISPLAY_BANNER_DEPRECATED):

        if display_banner is not DISPLAY_BANNER_DEPRECATED:
            warn(
                "interact `display_banner` argument is deprecated since IPython 5.0. "
                "Call `show_banner()` if needed.",
                DeprecationWarning,
                stacklevel=2,
            )  # noqa

        self.keep_running = True
        while self.keep_running:
            print(self.separate_in, end="")

            if self.current_command_index > len(self.commands) - 1:
                echo("Do you really want to exit ([y]/n)? ", nl=False)
                wait_for(RETURNS)
                self.ask_exit()
                return None

            try:
                code = self.prompt_for_code()
            except EOFError:
                if (not self.confirm_exit) or self.ask_yes_no(
                        "Do you really want to exit ([y]/n)?", "y", "n"):
                    self.ask_exit()

            else:
                if code:
                    self.run_cell(code, store_history=True)
Beispiel #4
0
    def interact(self):
        self.keep_running = True
        while self.keep_running:
            print(self.separate_in, end="")

            if self.current_command_index > len(self.commands) - 1:
                echo("Do you really want to exit ([y]/n)? ", nl=False)
                wait_for(RETURNS)
                self.ask_exit()
                return None

            try:
                code = self.prompt_for_code()
            except EOFError:
                if (not self.confirm_exit) or self.ask_yes_no(
                        "Do you really want to exit ([y]/n)?", "y", "n"):
                    self.ask_exit()

            else:
                if code:
                    self.run_cell(code, store_history=True)