def menu(): """Shows a simple menu.""" menu = 'main' while 1: if menu == 'main': click.echo('Main menu:') click.echo(' d: debug menu') click.echo(' q: quit') char = click.getchar() if char == 'd': menu = 'debug' elif char == 'q': menu = 'quit' else: click.echo('Invalid input') elif menu == 'debug': click.echo('Debug menu') click.echo(' b: back') char = click.getchar() if char == 'b': menu = 'main' else: click.echo('Invalid input') elif menu == 'quit': return
def test_getchar_windows_exceptions(runner, monkeypatch, key_char, exc): monkeypatch.setattr(asyncclick._termui_impl.msvcrt, "getwch", lambda: key_char) monkeypatch.setattr(click.termui, "_getchar", None) with pytest.raises(exc): click.getchar()
def menu(): """Shows a simple menu.""" menu = "main" while True: if menu == "main": click.echo("Main menu:") click.echo(" d: debug menu") click.echo(" q: quit") char = click.getchar() if char == "d": menu = "debug" elif char == "q": menu = "quit" else: click.echo("Invalid input") elif menu == "debug": click.echo("Debug menu") click.echo(" b: back") char = click.getchar() if char == "b": menu = "main" else: click.echo("Invalid input") elif menu == "quit": return
def test_getchar_windows_exceptions(runner, monkeypatch, key_char): monkeypatch.setattr(click._termui_impl.msvcrt, 'getwch', lambda: key_char) monkeypatch.setattr(click.termui, '_getchar', None) try: click.getchar() except KeyboardInterrupt: assert key_char == u'\x03' except EOFError: assert key_char == u'\x1a' else: assert False, 'Expected an exception because of abort-specific inputs.'
def test_getchar_special_key_windows(runner, monkeypatch, special_key_char, key_char): ordered_inputs = [key_char, special_key_char] monkeypatch.setattr(click._termui_impl.msvcrt, 'getwch', lambda: ordered_inputs.pop()) monkeypatch.setattr(click.termui, '_getchar', None) assert click.getchar() == special_key_char + key_char
def test_getchar_special_key_windows(runner, monkeypatch, special_key_char, key_char): ordered_inputs = [key_char, special_key_char] monkeypatch.setattr(asyncclick._termui_impl.msvcrt, "getwch", lambda: ordered_inputs.pop()) monkeypatch.setattr(click.termui, "_getchar", None) assert click.getchar() == f"{special_key_char}{key_char}"
def test_getchar_windows(runner, monkeypatch, key_char, echo): monkeypatch.setattr(asyncclick._termui_impl.msvcrt, "getwche", lambda: key_char) monkeypatch.setattr(asyncclick._termui_impl.msvcrt, "getwch", lambda: key_char) monkeypatch.setattr(click.termui, "_getchar", None) assert click.getchar(echo) == key_char
def ask_skip(image_path): while True: click.echo( image_path + " already exists, do you want to skip? " "[(A)lways/(Y)es/(N)o/N(e)ver]", nl=False, ) option = click.getchar(echo=True).lower() click.echo("") if option in ("y", "n", "a", "e"): break return option
async def interactive(ctx): while True: click.clear() click.echo("==================") click.echo(" Interactive Mode ") click.echo("==================") click.echo("") click.echo("What do you want to do?") click.echo("1. Download post(s).") click.echo("2. Download pool(s).") click.echo("Select: [1/2] ", nl=False) c = click.getchar() await func_table.get(c, invalid_input)(ctx) click.confirm("Do you want to do anything else?", abort=True)
def getchar_echo(): click.echo(click.getchar(echo=True))
def continue_it(): click.echo(click.getchar())
def test_getchar_windows(runner, monkeypatch, key_char, echo): monkeypatch.setattr(click._termui_impl.msvcrt, 'getwche', lambda: key_char) monkeypatch.setattr(click._termui_impl.msvcrt, 'getwch', lambda: key_char) monkeypatch.setattr(click.termui, '_getchar', None) assert click.getchar(echo) == key_char