python类tigetnum()的实例源码

snmpbrute.py 文件源码 项目:OSPTF 作者: xSploited 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def has_colours(stream):
    if not hasattr(stream, "isatty"):
        return False
    if not stream.isatty():
        return False # auto color only on TTYs
    try:
        import curses
        curses.setupterm()
        return curses.tigetnum("colors") > 2
    except:
        # guess false in case of error
        return False
os4tw.py 文件源码 项目:os4tw 作者: mattiareggiani 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def has_colours(stream):
    if not (hasattr(stream, "isatty") and stream.isatty()):
        return False
    try:
        import curses
        curses.setupterm()
        return curses.tigetnum("colors") > 2
    except:
        # TODO: log console
        return False
stringpict.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def terminal_width(self):
        """Return the terminal width if possible, otherwise return 0.
        """
        ncols = 0
        try:
            import curses
            import io
            try:
                curses.setupterm()
                ncols = curses.tigetnum('cols')
            except AttributeError:
                # windows curses doesn't implement setupterm or tigetnum
                # code below from
                # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440694
                from ctypes import windll, create_string_buffer
                # stdin handle is -10
                # stdout handle is -11
                # stderr handle is -12
                h = windll.kernel32.GetStdHandle(-12)
                csbi = create_string_buffer(22)
                res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
                if res:
                    import struct
                    (bufx, bufy, curx, cury, wattr,
                     left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
                    ncols = right - left + 1
            except curses.error:
                pass
            except io.UnsupportedOperation:
                pass
        except (ImportError, TypeError):
            pass
        return ncols
misc_util.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def terminal_has_colors():
    if sys.platform=='cygwin' and 'USE_COLOR' not in os.environ:
        # Avoid importing curses that causes illegal operation
        # with a message:
        #  PYTHON2 caused an invalid page fault in
        #  module CYGNURSES7.DLL as 015f:18bbfc28
        # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]
        #          ssh to Win32 machine from debian
        #          curses.version is 2.2
        #          CYGWIN_98-4.10, release 1.5.7(0.109/3/2))
        return 0
    if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
        try:
            import curses
            curses.setupterm()
            if (curses.tigetnum("colors") >= 0
                and curses.tigetnum("pairs") >= 0
                and ((curses.tigetstr("setf") is not None
                      and curses.tigetstr("setb") is not None)
                     or (curses.tigetstr("setaf") is not None
                         and curses.tigetstr("setab") is not None)
                     or curses.tigetstr("scp") is not None)):
                return 1
        except Exception:
            pass
    return 0
termcap.py 文件源码 项目:pwndemo 作者: zh-explorer 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get(cap, *args, **kwargs):
    default = kwargs.pop('default', '')

    if 'PWNLIB_NOTERM' in os.environ:
        return ''

    if kwargs != {}:
        raise TypeError("get(): No such argument %r" % kwargs.popitem()[0])

    if cache == None:
        init()
    s = cache.get(cap)
    if not s:
        s = curses.tigetstr(cap)
        if s == None:
            s = curses.tigetnum(cap)
            if s == -2:
                s = curses.tigetflag(cap)
                if s == -1:
                    # default to empty string so tparm doesn't fail
                    s = ''
                else:
                    s = bool(s)
        cache[cap] = s
    # if `s' is not set `curses.tparm' will throw an error if given arguments
    if args and s:
        return curses.tparm(s, *args)
    else:
        return s
log_utils.py 文件源码 项目:style_transfer 作者: crowsonkb 项目源码 文件源码 阅读 54 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color
colorlog.py 文件源码 项目:pep517 作者: pypa 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color
log.py 文件源码 项目:My-Web-Server-Framework-With-Python2.7 作者: syjsu 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color
Command.py 文件源码 项目:hive 作者: tdeheurles 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def _verbose(self, message):
        BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)

        # following from Python cookbook, #475186
        def has_colours(stream):
            if not hasattr(stream, "isatty"):
                return False
            if not stream.isatty():
                return False  # auto color only on TTYs
            try:
                import curses
                curses.setupterm()
                return curses.tigetnum("colors") > 2
            except:
                # guess false in case of error
                return False

        has_colours = has_colours(sys.stdout)

        def printout(text, colour=WHITE):
            if has_colours:
                seq = "\x1b[1;%dm" % (30 + colour) + text + "\x1b[0m\n"
                sys.stdout.write(seq)
            else:
                sys.stdout.write(text)

        if self.verboseMode:
            printout("hive-python: " + message, BLUE)
color.py 文件源码 项目:pssh 作者: lilydjwg 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def has_colors(stream):
    '''Returns boolean indicating whether or not the supplied stream supports
    ANSI color.
    '''
    if not hasattr(stream, "isatty"):
        return False
    if not stream.isatty():
        return False # auto color only on TTYs
    try:
        import curses
        curses.setupterm()
        return curses.tigetnum("colors") > 2
    except:
        # guess false in case of error
        return False
options.py 文件源码 项目:time2go 作者: twitchyliquid64 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def enable_pretty_logging():
    """Turns on formatted logging output as configured.

    This is called automatically by `parse_command_line`.
    """
    root_logger = logging.getLogger()
    if options.log_file_prefix:
        channel = logging.handlers.RotatingFileHandler(
            filename=options.log_file_prefix,
            maxBytes=options.log_file_max_size,
            backupCount=options.log_file_num_backups)
        channel.setFormatter(_LogFormatter(color=False))
        root_logger.addHandler(channel)

    if (options.log_to_stderr or
        (options.log_to_stderr is None and not root_logger.handlers)):
        # Set up color if we are in a tty and curses is installed
        color = False
        if curses and sys.stderr.isatty():
            try:
                curses.setupterm()
                if curses.tigetnum("colors") > 0:
                    color = True
            except Exception:
                pass
        channel = logging.StreamHandler()
        channel.setFormatter(_LogFormatter(color=color))
        root_logger.addHandler(channel)
build_ffmpeg.py 文件源码 项目:nwjs-ffmpeg-prebuilt 作者: iteufel 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def has_colours(stream):
    if not hasattr(stream, "isatty"):
        return False
    if not stream.isatty():
        return False # auto color only on TTYs
    try:
        import curses
        curses.setupterm()
        return curses.tigetnum("colors") > 2
    except:
        # guess false in case of error
        return False
misc_util.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def terminal_has_colors():
    if sys.platform=='cygwin' and 'USE_COLOR' not in os.environ:
        # Avoid importing curses that causes illegal operation
        # with a message:
        #  PYTHON2 caused an invalid page fault in
        #  module CYGNURSES7.DLL as 015f:18bbfc28
        # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]
        #          ssh to Win32 machine from debian
        #          curses.version is 2.2
        #          CYGWIN_98-4.10, release 1.5.7(0.109/3/2))
        return 0
    if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
        try:
            import curses
            curses.setupterm()
            if (curses.tigetnum("colors") >= 0
                and curses.tigetnum("pairs") >= 0
                and ((curses.tigetstr("setf") is not None
                      and curses.tigetstr("setb") is not None)
                     or (curses.tigetstr("setaf") is not None
                         and curses.tigetstr("setab") is not None)
                     or curses.tigetstr("scp") is not None)):
                return 1
        except Exception:
            pass
    return 0
log.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color
log.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color
log.py 文件源码 项目:annotated-py-tornado 作者: hhstore 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color
misc_util.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def terminal_has_colors():
    if sys.platform=='cygwin' and 'USE_COLOR' not in os.environ:
        # Avoid importing curses that causes illegal operation
        # with a message:
        #  PYTHON2 caused an invalid page fault in
        #  module CYGNURSES7.DLL as 015f:18bbfc28
        # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]
        #          ssh to Win32 machine from debian
        #          curses.version is 2.2
        #          CYGWIN_98-4.10, release 1.5.7(0.109/3/2))
        return 0
    if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
        try:
            import curses
            curses.setupterm()
            if (curses.tigetnum("colors") >= 0
                and curses.tigetnum("pairs") >= 0
                and ((curses.tigetstr("setf") is not None
                      and curses.tigetstr("setb") is not None)
                     or (curses.tigetstr("setaf") is not None
                         and curses.tigetstr("setab") is not None)
                     or curses.tigetstr("scp") is not None)):
                return 1
        except Exception:
            pass
    return 0
options.py 文件源码 项目:deprecated_thedap 作者: unitedvote 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def enable_pretty_logging():
    """Turns on formatted logging output as configured.

    This is called automatically by `parse_command_line`.
    """
    root_logger = logging.getLogger()
    if options.log_file_prefix:
        channel = logging.handlers.RotatingFileHandler(
            filename=options.log_file_prefix,
            maxBytes=options.log_file_max_size,
            backupCount=options.log_file_num_backups)
        channel.setFormatter(_LogFormatter(color=False))
        root_logger.addHandler(channel)

    if (options.log_to_stderr or
        (options.log_to_stderr is None and not root_logger.handlers)):
        # Set up color if we are in a tty and curses is installed
        color = False
        if curses and sys.stderr.isatty():
            try:
                curses.setupterm()
                if curses.tigetnum("colors") > 0:
                    color = True
            except Exception:
                pass
        channel = logging.StreamHandler()
        channel.setFormatter(_LogFormatter(color=color))
        root_logger.addHandler(channel)
tui.py 文件源码 项目:mccurse 作者: khardix 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def select_mod(
    choices: Sequence[Mod],
    header: Optional[str] = None,
    footer: Optional[str] = None,
) -> Optional[Mod]:
    """Present user with a TUI menu and return his choice.

    Keyword arguments:
        choices: The :class:`Mod`s to choose from.
        header: Optional menu heading.
        footer: Optional menu footing.

    Returns:
        The selected mod.
    """

    menu = ModMenu(choices)

    head = urwid.Text(('title', header), align='center') if header else None
    foot = urwid.Text(('description', footer), align='center') if footer else None  # noqa: E501

    if head or foot:
        top = urwid.Frame(menu, head, foot)
    else:
        top = menu

    try:
        colors = curses.tigetnum('colors')
    except curses.error:  # Uninitialized terminal
        colors = 16

    event_loop = urwid.MainLoop(
        top,
        palette=ModMenu.palette,
        unhandled_input=exit_loop_on_q_esc,
    )
    event_loop.screen.set_terminal_properties(colors=colors)
    event_loop.run()

    return menu.chosen
log.py 文件源码 项目:get_started_with_respeaker 作者: respeaker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _stderr_supports_color():
    color = False
    if curses and sys.stderr.isatty():
        try:
            curses.setupterm()
            if curses.tigetnum("colors") > 0:
                color = True
        except Exception:
            pass
    return color


问题


面经


文章

微信
公众号

扫码关注公众号