Skip to content

Commit

Permalink
Clear scrollback
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdowne committed Sep 17, 2024
1 parent 6ce2d09 commit 0047d3d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ethstaker_deposit/cli/generate_bls_to_execution_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
closest_match,
load_text,
)
from ethstaker_deposit.utils.terminal import clear_terminal
from ethstaker_deposit.settings import (
MAINNET,
ALL_CHAIN_KEYS,
Expand Down Expand Up @@ -208,7 +209,7 @@ def generate_bls_to_execution_change(
if not json_file_validation_result:
raise ValidationError(load_text(['err_verify_btec']))

click.clear()
clear_terminal()
click.echo(OWL_0)
click.echo(load_text(['msg_creation_success']) + str(bls_to_execution_changes_folder))

Expand Down
3 changes: 2 additions & 1 deletion ethstaker_deposit/cli/generate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
closest_match,
load_text,
)
from ethstaker_deposit.utils.terminal import clear_terminal
from ethstaker_deposit.settings import (
MAINNET,
ALL_CHAIN_KEYS,
Expand Down Expand Up @@ -140,7 +141,7 @@ def generate_keys(ctx: click.Context, validator_start_index: int,

if not os.path.exists(folder):
os.mkdir(folder)
click.clear()
clear_terminal()
click.echo(RHINO_0)
click.echo(load_text(['msg_key_creation']))
credentials = CredentialList.from_mnemonic(
Expand Down
7 changes: 4 additions & 3 deletions ethstaker_deposit/cli/new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
load_text,
get_first_options,
)
from ethstaker_deposit.utils.terminal import clear_terminal

from .generate_keys import (
generate_keys,
Expand Down Expand Up @@ -50,14 +51,14 @@ def new_mnemonic(ctx: click.Context, mnemonic_language: str, **kwargs: Any) -> N
mnemonic = get_mnemonic(language=mnemonic_language, words_path=WORD_LISTS_PATH)
test_mnemonic = ''
while mnemonic != reconstruct_mnemonic(test_mnemonic, WORD_LISTS_PATH):
click.clear()
clear_terminal()
click.echo(load_text(['msg_mnemonic_presentation']))
click.echo('\n\n%s\n\n' % mnemonic)
click.pause(load_text(['msg_press_any_key']))

click.clear()
clear_terminal()
test_mnemonic = click.prompt(load_text(['msg_mnemonic_retype_prompt']) + '\n\n')
click.clear()
clear_terminal()
# Do NOT use mnemonic_password.
ctx.obj = {'mnemonic': mnemonic, 'mnemonic_password': ''}
ctx.params['validator_start_index'] = 0
Expand Down
23 changes: 23 additions & 0 deletions ethstaker_deposit/utils/terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import subprocess
import sys
import shutil
import click


def clear_terminal() -> None:
if sys.platform == 'win32':
try:
subprocess.call('cls', shell=True)
except Exception:
click.clear()
elif sys.platform == 'linux' or sys.platform == 'darwin':
if shutil.which('tput'):
subprocess.call(['tput', 'reset'])
elif shutil.which('reset'):
subprocess.call(['reset'])
elif shutil.which('clear'):
subprocess.call(['clear'])
else:
click.clear()
else:
click.clear()

0 comments on commit 0047d3d

Please sign in to comment.