Replace clear_screen() function
This is now part of wk.ansi and is fully cross-compatible.
This commit is contained in:
parent
95d7159414
commit
44ddb3c258
2 changed files with 6 additions and 11 deletions
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue