Ejemplo n.º 1
0
    def create_output(stdout=None, true_color=False):
        """
        Return an :class:`~prompt_toolkit.output.Output` instance for the command
        line.
        :param true_color: When True, use 24bit colors instead of 256 colors.
            (`bool` or :class:`~prompt_toolkit.filters.SimpleFilter`.)

        Notes
        -----
        This method was forked from the mainline prompt-toolkit repo.
        Copyright (c) 2014, Jonathan Slenders, All rights reserved.
        This is deprecated and slated for removal after a prompt-toolkit
        v0.57+ release.
        """
        stdout = stdout or sys.__stdout__
        true_color = to_simple_filter(true_color)

        if is_windows():
            if is_conemu_ansi():
                return ConEmuOutput(stdout)
            else:
                return Win32Output(stdout)
        else:
            term = os.environ.get('TERM', '')
            if PY2:
                term = term.decode('utf-8')

            return Vt100_Output.from_pty(stdout,
                                         true_color=true_color)  #, term=term)
Ejemplo n.º 2
0
    def create_output(stdout=None, true_color=False):
        """
        Return an :class:`~prompt_toolkit.output.Output` instance for the command
        line.
        :param true_color: When True, use 24bit colors instead of 256 colors.
            (`bool` or :class:`~prompt_toolkit.filters.SimpleFilter`.)

        Notes
        -----
        This method was forked from the mainline prompt-toolkit repo.
        Copyright (c) 2014, Jonathan Slenders, All rights reserved.
        This is deprecated and slated for removal after a prompt-toolkit
        v0.57+ release.
        """
        stdout = stdout or sys.__stdout__
        true_color = to_simple_filter(true_color)

        if is_windows():
            if is_conemu_ansi():
                return ConEmuOutput(stdout)
            else:
                return Win32Output(stdout)
        else:
            term = os.environ.get('TERM', '')
            if PY2:
                term = term.decode('utf-8')

            return Vt100_Output.from_pty(stdout, true_color=true_color)#, term=term)
Ejemplo n.º 3
0
    def attach(self, detach_other_clients=False, true_color=False):
        """
        Attach client user interface.
        """
        assert isinstance(detach_other_clients, bool)
        assert isinstance(true_color, bool)

        self._send_size()
        self._send_packet(
            {
                "cmd": "start-gui",
                "detach-others": detach_other_clients,
                "true-color": true_color,
                "term": os.environ.get("TERM", ""),
                "data": "",
            }
        )

        with raw_mode(sys.stdin.fileno()):
            data_buffer = b""

            stdin_fd = sys.stdin.fileno()
            socket_fd = self.socket.fileno()
            current_timeout = INPUT_TIMEOUT  # Timeout, used to flush escape sequences.

            with call_on_sigwinch(self._send_size):
                while True:
                    r, w, x = _select([stdin_fd, socket_fd], [], [], current_timeout)

                    if socket_fd in r:
                        # Received packet from server.
                        data = self.socket.recv(1024)

                        if data == b"":
                            # End of file. Connection closed.
                            # Reset terminal
                            o = Vt100_Output.from_pty(sys.stdout)
                            o.quit_alternate_screen()
                            o.disable_mouse_support()
                            o.disable_bracketed_paste()
                            o.reset_attributes()
                            o.flush()
                            return
                        else:
                            data_buffer += data

                            while b"\0" in data_buffer:
                                pos = data_buffer.index(b"\0")
                                self._process(data_buffer[:pos])
                                data_buffer = data_buffer[pos + 1 :]

                    elif stdin_fd in r:
                        # Got user input.
                        self._process_stdin()
                        current_timeout = INPUT_TIMEOUT

                    else:
                        # Timeout. (Tell the server to flush the vt100 Escape.)
                        self._send_packet({"cmd": "flush-input"})
                        current_timeout = None
Ejemplo n.º 4
0
    def attach(self, detach_other_clients=False, ansi_colors_only=False, true_color=False):
        """
        Attach client user interface.
        """
        assert isinstance(detach_other_clients, bool)
        assert isinstance(ansi_colors_only, bool)
        assert isinstance(true_color, bool)

        self._send_size()
        self._send_packet({
            'cmd': 'start-gui',
            'detach-others': detach_other_clients,
            'ansi-colors-only': ansi_colors_only,
            'true-color': true_color,
            'term': os.environ.get('TERM', ''),
            'data': ''
        })

        with raw_mode(sys.stdin.fileno()):
            data_buffer = b''

            stdin_fd = sys.stdin.fileno()
            socket_fd = self.socket.fileno()
            current_timeout = INPUT_TIMEOUT  # Timeout, used to flush escape sequences.

            with call_on_sigwinch(self._send_size):
                while True:
                    r = select_fds([stdin_fd, socket_fd], current_timeout)

                    if socket_fd in r:
                        # Received packet from server.
                        data = self.socket.recv(1024)

                        if data == b'':
                            # End of file. Connection closed.
                            # Reset terminal
                            o = Vt100_Output.from_pty(sys.stdout)
                            o.quit_alternate_screen()
                            o.disable_mouse_support()
                            o.disable_bracketed_paste()
                            o.reset_attributes()
                            o.flush()
                            return
                        else:
                            data_buffer += data

                            while b'\0' in data_buffer:
                                pos = data_buffer.index(b'\0')
                                self._process(data_buffer[:pos])
                                data_buffer = data_buffer[pos + 1:]

                    elif stdin_fd in r:
                        # Got user input.
                        self._process_stdin()
                        current_timeout = INPUT_TIMEOUT

                    else:
                        # Timeout. (Tell the server to flush the vt100 Escape.)
                        self._send_packet({'cmd': 'flush-input'})
                        current_timeout = None
Ejemplo n.º 5
0
    def attach(self, detach_other_clients=False, true_color=False):
        """
        Attach client user interface.
        """
        assert isinstance(detach_other_clients, bool)
        assert isinstance(true_color, bool)

        self._send_size()
        self._send_packet({
            'cmd': 'start-gui',
            'detach-others': detach_other_clients,
            'true-color': true_color,
            'term': os.environ.get('TERM', ''),
            'data': ''
        })

        with raw_mode(sys.stdin.fileno()):
            data_buffer = b''

            stdin_fd = sys.stdin.fileno()
            socket_fd = self.socket.fileno()
            current_timeout = INPUT_TIMEOUT  # Timeout, used to flush escape sequences.

            with call_on_sigwinch(self._send_size):
                while True:
                    r, w, x = _select([stdin_fd, socket_fd], [], [],
                                      current_timeout)

                    if socket_fd in r:
                        # Received packet from server.
                        data = self.socket.recv(1024)

                        if data == b'':
                            # End of file. Connection closed.
                            # Reset terminal
                            o = Vt100_Output.from_pty(sys.stdout)
                            o.quit_alternate_screen()
                            o.disable_mouse_support()
                            o.disable_bracketed_paste()
                            o.reset_attributes()
                            o.flush()
                            return
                        else:
                            data_buffer += data

                            while b'\0' in data_buffer:
                                pos = data_buffer.index(b'\0')
                                self._process(data_buffer[:pos])
                                data_buffer = data_buffer[pos + 1:]

                    elif stdin_fd in r:
                        # Got user input.
                        self._process_stdin()
                        current_timeout = INPUT_TIMEOUT

                    else:
                        # Timeout. (Tell the server to flush the vt100 Escape.)
                        self._send_packet({'cmd': 'flush-input'})
                        current_timeout = None
Ejemplo n.º 6
0
 def run_standalone(self, true_color=False):
     """
     Run pymux standalone, rather than using a client/server architecture.
     This is mainly useful for debugging.
     """
     self._runs_standalone = True
     cli = self.create_cli(connection=None,
                           output=Vt100_Output.from_pty(
                               sys.stdout, true_color=true_color))
     cli._is_running = False
     cli.run()
Ejemplo n.º 7
0
 def run_standalone(self, true_color=False):
     """
     Run pymux standalone, rather than using a client/server architecture.
     This is mainly useful for debugging.
     """
     self._runs_standalone = True
     cli = self.create_cli(
         connection=None,
         output=Vt100_Output.from_pty(sys.stdout, true_color=true_color))
     cli._is_running = False
     cli.run()