diff --git a/scripts/wk/ansi.py b/scripts/wk/ansi.py index 2acf515d..2c21c0ed 100644 --- a/scripts/wk/ansi.py +++ b/scripts/wk/ansi.py @@ -23,6 +23,11 @@ COLORS = { # Functions +def clear_screen(): + """Clear screen using ANSI escape.""" + print('\033c', end='', flush=True) + + def color_string(strings, colors, sep=' '): """Build colored string using ANSI escapes, returns str.""" clear_code = COLORS['CLEAR'] diff --git a/scripts/wk/ui/cli.py b/scripts/wk/ui/cli.py index 6aa5a128..298fecaf 100644 --- a/scripts/wk/ui/cli.py +++ b/scripts/wk/ui/cli.py @@ -17,7 +17,7 @@ except ImportError: # Assuming Python is < 3.9 from functools import lru_cache as cache -from wk.ansi import color_string, strip_colors +from wk.ansi import clear_screen, color_string, strip_colors from wk.cfg.main import ( ENABLED_UPLOAD_DATA, INDENT, @@ -622,16 +622,6 @@ def choice(choices, prompt='答えろ!'): return answer -def clear_screen(): - """Simple wrapper for clear/cls.""" - cmd = 'cls' if os.name == 'nt' else 'clear' - proc = subprocess.run(cmd, check=False, shell=True, stderr=subprocess.PIPE) - - # Workaround for live macOS env - if proc.returncode != 0: - print('\033c') - - @cache def get_exception(name): """Get exception by name, returns exception object.