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


Python Terminal.underline方法代码示例

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


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

示例1: ask_key

# 需要导入模块: from blessed import Terminal [as 别名]
# 或者: from blessed.Terminal import underline [as 别名]
def ask_key():
    if Terminal is None:
        try:
            value = raw_input(
                "Type the decryption key, "
                "without spaces or other special characters: ")
            return value.strip().decode('hex')
        except TypeError:
            return None
    sys.__stdin__ = sys.stdin
    t = Terminal()
    width = 64
    lwidth = 16
    movement = {
        'KEY_LEFT': -1,
        'KEY_RIGHT': 1,
        'KEY_UP': -lwidth,
        'KEY_DOWN': lwidth,
        'KEY_HOME': -width,
        'KEY_END': width,
        'KEY_BACKSPACE': -1
    }

    value = [" "] * width
    rows = ["B", "C", "D", "E"]

    def valid():
        return " " not in value

    with t.cbreak():
        val = None
        validvalue = None
        pos = 0
        nrows = width/lwidth
        print "Type the decryption key, or press 'q' to cancel"
        while val not in (u'q', u'Q',):
            for i in range(width/lwidth):
                s = lwidth / 2
                print rows[i],
                print t.underline("".join(value[2*i*s:(2*i+1)*s])),
                print t.underline("".join(value[(2*i+1)*s:(2*i+2)*s]))
            if valid():
                print "key valid, press enter to accept"
            else:
                print t.clear_eol
            if validvalue is not None:
                break
            sys.stdout.write(t.move_up * (nrows+1))
            with t.location():
                y = pos/lwidth
                x = pos % lwidth
                sys.stdout.write(t.move_down * y)
                sys.stdout.write(t.move_right * (x + 2 + (2*x)/lwidth))
                sys.stdout.flush()
                val = t.inkey(timeout=5)
                if not val:
                    pass
                elif val.is_sequence:
                    if val.name in movement:
                        newpos = pos + movement[val.name]
                        pos = min(width-1, max(0, newpos))
                    if val.name in ('KEY_DELETE', 'KEY_BACKSPACE'):
                        value[pos:width] = value[pos+1:width] + [" "]
                    elif val.name is 'KEY_ENTER' and valid():
                        validvalue = value
                elif val.lower() in "0123456789abcdef":
                    if pos < width:
                        value[pos] = val.upper()
                        if pos < width - 1:
                            pos += 1
    if validvalue is not None:
        return ("".join(validvalue)).decode('hex')
    return validvalue
开发者ID:longaccess,项目名称:longaccess-client,代码行数:75,代码来源:certinput.py


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