From de981febc7f1b61206abf7313cd42f27d050413e Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 22 Oct 2018 10:28:07 +0200 Subject: [PATCH] ui: switch ClickUI to use stderr --- trezorlib/ui.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/trezorlib/ui.py b/trezorlib/ui.py index 6796bac2d..1e95217ce 100644 --- a/trezorlib/ui.py +++ b/trezorlib/ui.py @@ -31,10 +31,18 @@ PIN_NEW = PinMatrixRequestType.NewFirst PIN_CONFIRM = PinMatrixRequestType.NewSecond +def echo(*args, **kwargs): + return click.echo(*args, err=True, **kwargs) + + +def prompt(*args, **kwargs): + return click.prompt(*args, err=True, **kwargs) + + class ClickUI: @staticmethod def button_request(code): - click.echo("Please confirm action on your Trezor device") + echo("Please confirm action on your Trezor device") @staticmethod def get_pin(code=None): @@ -46,28 +54,28 @@ class ClickUI: desc = "new PIN again" else: desc = "PIN" - click.echo(PIN_MATRIX_DESCRIPTION) + echo(PIN_MATRIX_DESCRIPTION) while True: - pin = click.prompt("Please enter {}".format(desc), hide_input=True) + pin = prompt("Please enter {}".format(desc), hide_input=True) if not pin.isdigit(): - click.echo("Non-numerical PIN provided, please try again") + echo("Non-numerical PIN provided, please try again") else: return pin @staticmethod def get_passphrase(): if os.getenv("PASSPHRASE") is not None: - click.echo("Passphrase required. Using PASSPHRASE environment variable.") + echo("Passphrase required. Using PASSPHRASE environment variable.") return os.getenv("PASSPHRASE") while True: - passphrase = click.prompt("Passphrase required", hide_input=True) - second = click.prompt("Confirm your passphrase", hide_input=True) + passphrase = prompt("Passphrase required", hide_input=True) + second = prompt("Confirm your passphrase", hide_input=True) if passphrase == second: return passphrase else: - click.echo("Passphrase did not match. Please try again.") + echo("Passphrase did not match. Please try again.") def mnemonic_words(expand=False, language="english"): @@ -84,14 +92,14 @@ def mnemonic_words(expand=False, language="english"): matches = [w for w in wordlist if w.startswith(word)] if len(matches) == 1: return word - click.echo("Choose one of: " + ", ".join(matches)) + echo("Choose one of: " + ", ".join(matches)) raise KeyError(word) def get_word(type): assert type == WordRequestType.Plain while True: try: - word = click.prompt("Enter one word of mnemonic") + word = prompt("Enter one word of mnemonic") return expand_word(word) except KeyError: pass