当前位置: 首页>>代码示例>>Python>>正文


Python curses.setupterm方法代码示例

本文整理汇总了Python中curses.setupterm方法的典型用法代码示例。如果您正苦于以下问题:Python curses.setupterm方法的具体用法?Python curses.setupterm怎么用?Python curses.setupterm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在curses的用法示例。


在下文中一共展示了curses.setupterm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(cls, stream=sys.stdout):
        """
        A class method that returns True if the current platform supports
        coloring terminal output using this method. Returns False otherwise.
        """
        if not stream.isatty():
            return False  # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except:
                raise
                # guess false in case of error
                return False 
开发者ID:MIC-DKFZ,项目名称:medicaldetectiontoolkit,代码行数:24,代码来源:exp_utils.py

示例2: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(cls, stream=sys.stdout):
        """
        A class method that returns True if the current platform supports
        coloring terminal output using this method. Returns False otherwise.
        """
        if not stream.isatty():
            return False  # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except Exception:
                # guess false in case of error
                return False 
开发者ID:openstack,项目名称:ec2-api,代码行数:23,代码来源:colorizer.py

示例3: setterm

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def setterm(self, term):
    # Dummy file for the purpose of tests.
    with open('/dev/null', 'w') as f:
      curses.setupterm(
          term, f.fileno())  # This will raise if the termtype is not supported
      self.TERM = term
      self.ESCSEQ = {}
      for k in self.KEYS.keys():
        str_ = curses.tigetstr(curses.has_key._capability_names[k])
        if str_:
          self.ESCSEQ[str_] = k
      self.CODES['DEOL'] = curses.tigetstr('el')
      self.CODES['DEL'] = curses.tigetstr('dch1')
      self.CODES['INS'] = curses.tigetstr('ich1')
      self.CODES['CSRLEFT'] = curses.tigetstr('cub1')
      self.CODES['CSRRIGHT'] = curses.tigetstr('cuf1') 
开发者ID:johnnykv,项目名称:heralding,代码行数:18,代码来源:telnet.py

示例4: _stderr_supports_color

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def _stderr_supports_color() -> bool:
    try:
        if hasattr(sys.stderr, "isatty") and sys.stderr.isatty():
            if curses:
                curses.setupterm()
                if curses.tigetnum("colors") > 0:
                    return True
            elif colorama:
                if sys.stderr is getattr(
                    colorama.initialise, "wrapped_stderr", object()
                ):
                    return True
    except Exception:
        # Very broad exception handling because it's always better to
        # fall back to non-colored logs than to break at startup.
        pass
    return False 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:log.py

示例5: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(cls, stream=sys.stdout):
        """Check the current platform supports coloring terminal output

        A class method that returns True if the current platform supports
        coloring terminal output using this method. Returns False otherwise.
        """
        if not stream.isatty():
            return False  # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except Exception:
                # guess false in case of error
                return False 
开发者ID:openstack,项目名称:os-testr,代码行数:24,代码来源:colorizer.py

示例6: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(cls, stream=sys.stdout):
        """
        A class method that returns True if the current platform supports
        coloring terminal output using this method. Returns False otherwise.
        """
        if not stream.isatty():
            return False # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except:
                # guess false in case of error
                return False 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:reporter.py

示例7: setterm

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def setterm(self, term):
        "Set the curses structures for this terminal"
        log.debug("Setting termtype to %s" % (term, ))
        curses.setupterm(term) # This will raise if the termtype is not supported
        self.TERM = term
        self.ESCSEQ = {}
        for k in self.KEYS.keys():
            str = curses.tigetstr(curses.has_key._capability_names[k])
            if str:
                self.ESCSEQ[str] = k
        # Create a copy to prevent altering the class
        self.CODES = self.CODES.copy()
        self.CODES['DEOL'] = curses.tigetstr('el')
        self.CODES['DEL'] = curses.tigetstr('dch1')
        self.CODES['INS'] = curses.tigetstr('ich1')
        self.CODES['CSRLEFT'] = curses.tigetstr('cub1')
        self.CODES['CSRRIGHT'] = curses.tigetstr('cuf1') 
开发者ID:stamparm,项目名称:hontel,代码行数:19,代码来源:telnetsrvlib.py

示例8: __has_colors

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def __has_colors(stream):
        """
        Is tty output check
        :param object stream: input stream
        :return: bool
        """

        if not hasattr(stream, "isatty"):
            return False
        # noinspection PyUnresolvedReferences
        if not stream.isatty():
            return False  # auto color only on TTYs
        # noinspection PyBroadException
        try:
            import curses
            curses.setupterm()
            return curses.tigetnum("colors") > 2
        except Exception:
            # guess false in case of error
            return False 
开发者ID:stanislav-web,项目名称:OpenDoor,代码行数:22,代码来源:color.py

示例9: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(stream=sys.stdout):
        """
        A method that returns True if the current platform supports
        coloring terminal output using this method. Returns False otherwise.
        """
        if not stream.isatty():
            return False  # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except Exception:
                # guess false in case of error
                return False 
开发者ID:openstack,项目名称:glance_store,代码行数:23,代码来源:colorizer.py

示例10: DrawLine

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def DrawLine(LineChr,LineColor,LineCount):
    """
    Function	     : Drawing of Line with various character type, color and count
    Usage of DrawLine:
        LineChr      - Character to use as line
        LineColor    - Color of the line
        LineCount    - Number of character to print. "" is print from one end to another
    Examples         : Lookup DemoDrawLine for examples
    """
 
    printd(fcolor.CDebugB + "DrawLine Function\n" + fcolor.CDebug + "       LineChr - " + str(LineChr) + "\n       " + "LineColor = " + str(LineColor) + "\n       " + "LineCount = " + str(LineCount))
    if LineColor=="":
        LineColor=fcolor.SBlack
    if LineChr=="":
        LineChr="_"
    if LineCount=="":
        curses.setupterm()
        TWidth=curses.tigetnum('cols')
        TWidth=TWidth-1
    else:
        TWidth=LineCount
    print LineColor + LineChr * TWidth 
开发者ID:SYWorks,项目名称:wireless-ids,代码行数:24,代码来源:wids.py

示例11: enable_pretty_logging

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def enable_pretty_logging():
    """Turns on formatted logging output as configured."""
    if (options.log_to_stderr or
        (options.log_to_stderr is None and not options.log_file_prefix)):
        # 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:
                pass
        channel = logging.StreamHandler()
        channel.setFormatter(_LogFormatter(color=color))
        logging.getLogger().addHandler(channel)

    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))
        logging.getLogger().addHandler(channel) 
开发者ID:omererdem,项目名称:honeything,代码行数:26,代码来源:options.py

示例12: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(stream=sys.stdout):
        """Method that checks if the current terminal supports coloring.

        Returns True or False.
        """
        if not stream.isatty():
            return False  # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except Exception:
                # guess false in case of error
                return False 
开发者ID:openstack,项目名称:searchlight,代码行数:23,代码来源:colorizer.py

示例13: supported

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def supported(cls, stream=sys.stdout):
        """
        A class method that returns True if the current platform supports
        coloring terminal output using this method. Returns False otherwise.
        """
        if not stream.isatty():
            return False  # auto color only on TTYs
        try:
            import curses
        except ImportError:
            return False
        else:
            try:
                try:
                    return curses.tigetnum("colors") > 2
                except curses.error:
                    curses.setupterm()
                    return curses.tigetnum("colors") > 2
            except:
                # guess false in case of error
                return False 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:23,代码来源:test_lib.py

示例14: _height_and_width

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def _height_and_width(self):
        """Return a tuple of (terminal height, terminal width).

        Start by trying TIOCGWINSZ (Terminal I/O-Control: Get Window Size),
        falling back to environment variables (LINES, COLUMNS), and returning
        (None, None) if those are unavailable or invalid.

        """
        # tigetnum('lines') and tigetnum('cols') update only if we call
        # setupterm() again.
        for descriptor in self._init_descriptor, sys.__stdout__:
            try:
                return struct.unpack(
                        'hhhh', ioctl(descriptor, TIOCGWINSZ, '\000' * 8))[0:2]
            except IOError:
                # when the output stream or init descriptor is not a tty, such
                # as when when stdout is piped to another program, fe. tee(1),
                # these ioctls will raise IOError
                pass
        try:
            return int(environ.get('LINES')), int(environ.get('COLUMNS'))
        except TypeError:
            return None, None 
开发者ID:xtiankisutsa,项目名称:MARA_Framework,代码行数:25,代码来源:__init__.py

示例15: __init__

# 需要导入模块: import curses [as 别名]
# 或者: from curses import setupterm [as 别名]
def __init__(self):
        self.data = []
        self.has_ipython = True
        self.display_type = "multi"
        self.global_data_size = 0
        self.global_val_data_size = 0
        self.snapped = False

        global CURSES_SUPPORTED
        if CURSES_SUPPORTED:
            try:
                curses.setupterm()
                sys.stdout.write(curses.tigetstr('civis').decode())
            except Exception:
                CURSES_SUPPORTED = False
        
        try:
            clear_output
        except NameError:
            self.has_ipython = False 
开发者ID:limbo018,项目名称:FRU,代码行数:22,代码来源:callbacks.py


注:本文中的curses.setupterm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。