Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear scrollback #158

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -22,6 +22,7 @@
load_text,
get_first_options,
)
from ethstaker_deposit.utils.terminal import clear_terminal

from .generate_keys import (
generate_keys,
Expand Down Expand Up @@ -51,14 +52,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()
# Clear clipboard
try: # Failing this on headless Linux is expected
pyperclip.copy(' ')
Expand Down
27 changes: 27 additions & 0 deletions ethstaker_deposit/utils/terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess
import os
import sys
import shutil
import click


def clear_terminal() -> None:
if sys.platform == 'win32':
# Special-case for asyncio pytest on Windows
if os.getenv("IS_ASYNC_TEST") == "1":
click.clear()
elif shutil.which('clear'):
subprocess.call(['clear'])
else:
subprocess.call('cls', shell=True)
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()
9 changes: 9 additions & 0 deletions tests/test_cli/test_new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys

import pytest
import inspect
from click.testing import CliRunner

from eth_utils import decode_hex
Expand All @@ -20,6 +21,14 @@
from .helpers import clean_key_folder, get_permissions, get_uuid


@pytest.fixture(autouse=True)
def check_async(request):
if inspect.iscoroutinefunction(request.node.obj):
os.environ['IS_ASYNC_TEST'] = '1'
else:
os.environ['IS_ASYNC_TEST'] = '0'


def test_new_mnemonic_bls_withdrawal(monkeypatch) -> None:
# monkeypatch get_mnemonic
def mock_get_mnemonic(language, words_path, entropy=None) -> str:
Expand Down