mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-22 20:42:03 +00:00
ui: switch ClickUI to use stderr
This commit is contained in:
parent
cc908fb90c
commit
de981febc7
@ -31,10 +31,18 @@ PIN_NEW = PinMatrixRequestType.NewFirst
|
|||||||
PIN_CONFIRM = PinMatrixRequestType.NewSecond
|
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:
|
class ClickUI:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def button_request(code):
|
def button_request(code):
|
||||||
click.echo("Please confirm action on your Trezor device")
|
echo("Please confirm action on your Trezor device")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_pin(code=None):
|
def get_pin(code=None):
|
||||||
@ -46,28 +54,28 @@ class ClickUI:
|
|||||||
desc = "new PIN again"
|
desc = "new PIN again"
|
||||||
else:
|
else:
|
||||||
desc = "PIN"
|
desc = "PIN"
|
||||||
click.echo(PIN_MATRIX_DESCRIPTION)
|
echo(PIN_MATRIX_DESCRIPTION)
|
||||||
|
|
||||||
while True:
|
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():
|
if not pin.isdigit():
|
||||||
click.echo("Non-numerical PIN provided, please try again")
|
echo("Non-numerical PIN provided, please try again")
|
||||||
else:
|
else:
|
||||||
return pin
|
return pin
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_passphrase():
|
def get_passphrase():
|
||||||
if os.getenv("PASSPHRASE") is not None:
|
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")
|
return os.getenv("PASSPHRASE")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
passphrase = click.prompt("Passphrase required", hide_input=True)
|
passphrase = prompt("Passphrase required", hide_input=True)
|
||||||
second = click.prompt("Confirm your passphrase", hide_input=True)
|
second = prompt("Confirm your passphrase", hide_input=True)
|
||||||
if passphrase == second:
|
if passphrase == second:
|
||||||
return passphrase
|
return passphrase
|
||||||
else:
|
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"):
|
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)]
|
matches = [w for w in wordlist if w.startswith(word)]
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
return word
|
return word
|
||||||
click.echo("Choose one of: " + ", ".join(matches))
|
echo("Choose one of: " + ", ".join(matches))
|
||||||
raise KeyError(word)
|
raise KeyError(word)
|
||||||
|
|
||||||
def get_word(type):
|
def get_word(type):
|
||||||
assert type == WordRequestType.Plain
|
assert type == WordRequestType.Plain
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
word = click.prompt("Enter one word of mnemonic")
|
word = prompt("Enter one word of mnemonic")
|
||||||
return expand_word(word)
|
return expand_word(word)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user