From 8c70ebb78dabb2e4625271b7bf7a258e20d32631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Mon, 14 Dec 2020 18:01:09 +0100 Subject: [PATCH] switch to blessed --- pype/lib/splash.txt | 26 ++++++++--------- pype/lib/terminal.py | 56 +++++++++++++++---------------------- pype/lib/terminal_splash.py | 21 ++++++++++---- requirements.txt | 2 ++ 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/pype/lib/splash.txt b/pype/lib/splash.txt index 929b0e9f1e..833bcd4b9c 100644 --- a/pype/lib/splash.txt +++ b/pype/lib/splash.txt @@ -110,45 +110,45 @@ \ \ \___/ ---- * \ \____\ / \____\* \/____/ \/____/. - ____________ + ____________ /\ ___ \ . \ \ \/_\ \ * \ \ _____/ * \ \ \___/ ---- * \ \____\ / \____\ . - \/____/ \/____/ + \/____/ \/____/ ____________ - /\ ___ \ + /\ ___ \ \ \ \/_\ \ . \ \ _____/ * \ \ \___/ ---- * \ \____\ / \____\ . - \/____/ \/____/ + \/____/ \/____/ ____________ /\ ___ \ - \ \ \/_\ \ + \ \ \/_\ \ \ \ _____/ . \ \ \___/ ---- * \ \____\ / \____\ . - \/____/ \/____/ + \/____/ \/____/ ____________ /\ ___ \ \ \ \/_\ \ - \ \ _____/ + \ \ _____/ \ \ \___/ ---- * - \ \____\ / \____\ - \/____/ \/____/ + \ \____\ / \____\ + \/____/ \/____/ ____________ /\ ___ \ \ \ \/_\ \ \ \ _____/ \ \ \___/ ---- . - \ \____\ / \____\ - \/____/ \/____/ + \ \____\ / \____\ + \/____/ \/____/ ____________ /\ ___ \ \ \ \/_\ \ - \ \ _____/ _ + \ \ _____/ _ \ \ \___/ ---- \ \____\ / \____\ \/____/ \/____/ @@ -410,4 +410,4 @@ \ \ _____/ ___ ___ ___ \ \ \___/ ---- \ \\ \\ \ \ \____\ / \____\ \__\\__\\__\ - \/____/ \/____/ . PYPE Club . \ No newline at end of file + \/____/ \/____/ . PYPE Club . diff --git a/pype/lib/terminal.py b/pype/lib/terminal.py index 61d074f474..afaca8241a 100644 --- a/pype/lib/terminal.py +++ b/pype/lib/terminal.py @@ -13,11 +13,10 @@ import re import os import sys -noColorama = False -try: - from colorama import Fore, Style, init, ansitowin32 -except ImportError: - noColorama = True +import blessed + + +term = blessed.Terminal() class Terminal: @@ -30,40 +29,37 @@ class Terminal: """ # shortcuts for colorama codes - if noColorama: - _SB = _RST = _LR = _LG = _LB = _LM = _R = _G = _B = _C = _Y = _W = "" - _LY = "" - else: - _SB = Style.BRIGHT - _RST = Style.RESET_ALL - _LR = Fore.LIGHTRED_EX - _LG = Fore.LIGHTGREEN_EX - _LB = Fore.LIGHTBLUE_EX - _LM = Fore.LIGHTMAGENTA_EX - _LY = Fore.LIGHTYELLOW_EX - _R = Fore.RED - _G = Fore.GREEN - _B = Fore.BLUE - _C = Fore.CYAN - _Y = Fore.YELLOW - _W = Fore.WHITE + + _SB = term.bold + _RST = "" + _LR = term.tomato2 + _LG = term.aquamarine3 + _LB = term.turquoise2 + _LM = term.slateblue2 + _LY = term.gold + _R = term.red + _G = term.green + _B = term.blue + _C = term.cyan + _Y = term.yellow + _W = term.white # dictionary replacing string sequences with colorized one _sdict = { - r">>> ": _SB + _G + r">>> " + _RST, + r">>> ": _SB + _LG + r">>> " + _RST, r"!!!(?!\sCRI|\sERR)": _SB + _R + r"!!! " + _RST, r"\-\-\- ": _SB + _C + r"--- " + _RST, - r"\*\*\*(?!\sWRN)": _SB + _LM + r"***" + _RST, + r"\*\*\*(?!\sWRN)": _SB + _LY + r"***" + _RST, r"\*\*\* WRN": _SB + _LY + r"*** WRN" + _RST, - r" \- ": _SB + _Y + r" - " + _RST, + r" \- ": _SB + _LY + r" - " + _RST, r"\[ ": _SB + _LG + r"[ " + _RST, r"\]": _SB + _LG + r"]" + _RST, r"{": _LG + r"{", r"}": r"}" + _RST, r"\(": _LY + r"(", r"\)": r")" + _RST, - r"^\.\.\. ": _SB + _LM + r"... " + _RST, + r"^\.\.\. ": _SB + _LR + r"... " + _RST, r"!!! ERR: ": _SB + _LR + r"!!! ERR: " + _RST, r"!!! CRI: ": @@ -73,8 +69,7 @@ class Terminal: } def __init__(self): - if not noColorama: - init() + pass @staticmethod def _multiple_replace(text, adict): @@ -108,11 +103,6 @@ class Terminal: str: Colorized message. """ - if noColorama: - print(message) - return message - if not isinstance(sys.stdout, ansitowin32.StreamWrapper): - init() colorized = Terminal.log(message) print(colorized) diff --git a/pype/lib/terminal_splash.py b/pype/lib/terminal_splash.py index 7ff982c509..7f3f9d74fa 100644 --- a/pype/lib/terminal_splash.py +++ b/pype/lib/terminal_splash.py @@ -1,12 +1,15 @@ # -*- coding: utf-8 -*- """Pype terminal animation :)""" import os +import blessed from pathlib import Path from time import sleep import sys +term = blessed.Terminal() def play_animation(): + print(term.home + term.clear) frame_size = 7 splash_file = Path(__file__).parent / "splash.txt" with splash_file.open("r") as sf: @@ -15,11 +18,17 @@ def play_animation(): animation_length = int(len(animation) / frame_size) current_frame = 0 for _ in range(animation_length): - if sys.platform.startswith('win'): - os.system('cls') - else: - os.system('clear') + frame = "" + y = 0 for scanline in animation[current_frame:current_frame + frame_size]: - print(scanline.rstrip()) - sleep(0.005) + frame += scanline + y += 1 + + with term.location(0, 0): + # term.aquamarine3_bold(frame) + print(f"{term.bold}{term.aquamarine3}{frame}{term.normal}") + + + sleep(0.05) current_frame += frame_size + print(term.move_y(7)) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ac197b9b1e..d1855ed31a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,11 @@ aiohttp appdirs arrow +blessed certifi Click clique==1.5.0 +colorama coverage cx_Freeze ftrack-python-api==2.0.0