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


Python readchar.readkey方法代码示例

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


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

示例1: get_input

# 需要导入模块: import readchar [as 别名]
# 或者: from readchar import readkey [as 别名]
def get_input(self):
        """ Retrieve input from user with every keystroke buffered """
        while True:
            keypress = readkey()
            if keypress == key.CTRL_C:
                raise KeyboardInterrupt('Ctrl + C combination detected')
            if keypress in (key.ENTER, key.CR):
                print('\n\r', end='')
                break
            if keypress in (key.UP, key.DOWN, key.LEFT, key.RIGHT):
                continue
            if keypress == key.BACKSPACE:
                self.buffer = self.buffer[:-1]
            else:
                self.buffer = self.buffer + keypress
            print("\r\033[K" + self.buffer, end='', flush=True)
        result = str(self.buffer)
        self.buffer = ""
        return result 
开发者ID:Haider8,项目名称:tmessage,代码行数:21,代码来源:input.py

示例2: display_help

# 需要导入模块: import readchar [as 别名]
# 或者: from readchar import readkey [as 别名]
def display_help():
    # Clear screen and show the help text
    call(['clear'])
    puts(colored.cyan('Available commands (press any key to exit)'))

    puts(' enter       - Connect to your selection')
    puts(' crtl+c | q  - Quit sshmenu')
    puts(' k (up)      - Move your selection up')
    puts(' j (down)    - Move your selection down')
    puts(' h           - Show help menu')
    puts(' c           - Create new connection')
    puts(' d           - Delete connection')
    puts(' e           - Edit connection')
    puts(' + (plus)    - Move connection up')
    puts(' - (minus)   - Move connection down')

    # Hang until we get a keypress
    readchar.readkey() 
开发者ID:mmeyer724,项目名称:sshmenu,代码行数:20,代码来源:sshmenu.py

示例3: select

# 需要导入模块: import readchar [as 别名]
# 或者: from readchar import readkey [as 别名]
def select(
        options: List[str],
        selected_index: int = 0) -> int:
    print('\n' * (len(options) - 1))
    while True:
        print(f'\033[{len(options) + 1}A')
        for i, option in enumerate(options):
            print('\033[K{}{}'.format(
                '\033[1m[\033[32;1m x \033[0;1m]\033[0m ' if i == selected_index else
                '\033[1m[   ]\033[0m ', option))
        keypress = readchar.readkey()
        if keypress == readchar.key.UP:
            new_index = selected_index
            while new_index > 0:
                new_index -= 1
                selected_index = new_index
                break
        elif keypress == readchar.key.DOWN:
            new_index = selected_index
            while new_index < len(options) - 1:
                new_index += 1
                selected_index = new_index
                break
        elif keypress == readchar.key.ENTER:
            break
        elif keypress == readchar.key.CTRL_C:
            raise KeyboardInterrupt
    return selected_index 
开发者ID:t0thkr1s,项目名称:revshellgen,代码行数:30,代码来源:revshellgen.py

示例4: __init__

# 需要导入模块: import readchar [as 别名]
# 或者: from readchar import readkey [as 别名]
def __init__(self, *data, raise_on_empty=True):
        cutie.readchar.readkey = yield_input(*data, raise_on_empty=raise_on_empty) 
开发者ID:Kamik423,项目名称:cutie,代码行数:4,代码来源:__init__.py

示例5: __exit__

# 需要导入模块: import readchar [as 别名]
# 或者: from readchar import readkey [as 别名]
def __exit__(self, *a):
        cutie.readchar.readkey = readchar.readkey 
开发者ID:Kamik423,项目名称:cutie,代码行数:4,代码来源:__init__.py

示例6: select

# 需要导入模块: import readchar [as 别名]
# 或者: from readchar import readkey [as 别名]
def select(
        options: List[str],
        caption_indices: Optional[List[int]] = None,
        deselected_prefix: str = '\033[1m[ ]\033[0m ',
        selected_prefix: str = '\033[1m[\033[32;1mx\033[0;1m]\033[0m ',
        caption_prefix: str = '',
        selected_index: int = 0,
        confirm_on_select: bool = True) -> int:
    """Select an option from a list.

    Args:
        options (List[str]): The options to select from.
        caption_indices (List[int], optional): Non-selectable indices.
        deselected_prefix (str, optional): Prefix for deselected option ([ ]).
        selected_prefix (str, optional): Prefix for selected option ([x]).
        caption_prefix (str, optional): Prefix for captions ().
        selected_index (int, optional): The index to be selected at first.
        confirm_on_select (bool, optional): Select keys also confirm.

    Returns:
        int: The index that has been selected.
    """
    print('\n' * (len(options) - 1))
    if caption_indices is None:
        caption_indices = []
    while True:
        print(f'\033[{len(options) + 1}A')
        for i, option in enumerate(options):
            if i not in caption_indices:
                print('\033[K{}{}'.format(
                    selected_prefix if i == selected_index else
                    deselected_prefix, option))
            elif i in caption_indices:
                print('\033[K{}{}'.format(caption_prefix, options[i]))
        keypress = readchar.readkey()
        if keypress in DefaultKeys.up:
            new_index = selected_index
            while new_index > 0:
                new_index -= 1
                if new_index not in caption_indices:
                    selected_index = new_index
                    break
        elif keypress in DefaultKeys.down:
            new_index = selected_index
            while new_index < len(options) - 1:
                new_index += 1
                if new_index not in caption_indices:
                    selected_index = new_index
                    break
        elif keypress in DefaultKeys.confirm or \
                confirm_on_select and keypress in DefaultKeys.select:
            break
        elif keypress in DefaultKeys.interrupt:
            raise KeyboardInterrupt
    return selected_index 
开发者ID:Kamik423,项目名称:cutie,代码行数:57,代码来源:cutie.py


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