예제 #1
0
 def responds_to_cpr(self) -> bool:
     # When the input is a tty, we assume that CPR is supported.
     # It's not when the input is piped from Pexpect.
     if os.environ.get("PROMPT_TOOLKIT_NO_CPR", "") == "1":
         return False
     if is_dumb_terminal():
         return False
     try:
         return self.stdin.isatty()
     except ValueError:
         return False  # ValueError: I/O operation on closed file
예제 #2
0
파일: vt100.py 프로젝트: Cold5nap/sobolIter
    def get_default_color_depth(self) -> ColorDepth:
        """
        Return the default color depth for a vt100 terminal, according to the
        our term value.

        We prefer 256 colors almost always, because this is what most terminals
        support these days, and is a good default.
        """
        if self.default_color_depth is not None:
            return self.default_color_depth

        term = self.term

        if term is None:
            return ColorDepth.DEFAULT

        if is_dumb_terminal(term):
            return ColorDepth.DEPTH_1_BIT

        if term in ("linux", "eterm-color"):
            return ColorDepth.DEPTH_4_BIT

        return ColorDepth.DEFAULT
예제 #3
0
    def default(cls, term: Optional[str] = None) -> "ColorDepth":
        """
        Return the default color depth, according to the $TERM value.

        We prefer 256 colors almost always, because this is what most terminals
        support these days, and is a good default.

        The $PROMPT_TOOLKIT_COLOR_DEPTH environment variable can be used to
        override this outcome. This is a way to enforce a certain color depth
        in all prompt_toolkit applications.

        If no `term` parameter is given, we use the $TERM environment variable.
        """
        # Take `TERM` value from environment variable if nothing was passed.
        if term is None:
            term = os.environ.get("TERM", "")

        if is_dumb_terminal(term):
            return cls.DEPTH_1_BIT

        if term in ("linux", "eterm-color"):
            return cls.DEPTH_4_BIT

        # For now, always use 4 bit color on Windows 10 by default, even when
        # vt100 escape sequences with ENABLE_VIRTUAL_TERMINAL_PROCESSING are
        # supported. We don't have a reliable way yet to know whether our
        # console supports true color or only 4-bit.
        if is_windows() and "PROMPT_TOOLKIT_COLOR_DEPTH" not in os.environ:
            return cls.DEPTH_4_BIT

        # Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable.
        all_values = [i.value for i in ColorDepth]

        if os.environ.get("PROMPT_TOOLKIT_COLOR_DEPTH") in all_values:
            return cls(os.environ["PROMPT_TOOLKIT_COLOR_DEPTH"])

        return cls.DEPTH_8_BIT