switch to blessed

This commit is contained in:
Ondřej Samohel 2020-12-14 18:01:09 +01:00
parent f5d8f36e1f
commit 8c70ebb78d
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
4 changed files with 53 additions and 52 deletions

View file

@ -110,45 +110,45 @@
\ \ \___/ ---- * \ \ \___/ ---- *
\ \____\ / \____\* \ \____\ / \____\*
\/____/ \/____/. \/____/ \/____/.
____________ ____________
/\ ___ \ . /\ ___ \ .
\ \ \/_\ \ * \ \ \/_\ \ *
\ \ _____/ * \ \ _____/ *
\ \ \___/ ---- * \ \ \___/ ---- *
\ \____\ / \____\ . \ \____\ / \____\ .
\/____/ \/____/ \/____/ \/____/
____________ ____________
/\ ___ \ /\ ___ \
\ \ \/_\ \ . \ \ \/_\ \ .
\ \ _____/ * \ \ _____/ *
\ \ \___/ ---- * \ \ \___/ ---- *
\ \____\ / \____\ . \ \____\ / \____\ .
\/____/ \/____/ \/____/ \/____/
____________ ____________
/\ ___ \ /\ ___ \
\ \ \/_\ \ \ \ \/_\ \
\ \ _____/ . \ \ _____/ .
\ \ \___/ ---- * \ \ \___/ ---- *
\ \____\ / \____\ . \ \____\ / \____\ .
\/____/ \/____/ \/____/ \/____/
____________ ____________
/\ ___ \ /\ ___ \
\ \ \/_\ \ \ \ \/_\ \
\ \ _____/ \ \ _____/
\ \ \___/ ---- * \ \ \___/ ---- *
\ \____\ / \____\ \ \____\ / \____\
\/____/ \/____/ \/____/ \/____/
____________ ____________
/\ ___ \ /\ ___ \
\ \ \/_\ \ \ \ \/_\ \
\ \ _____/ \ \ _____/
\ \ \___/ ---- . \ \ \___/ ---- .
\ \____\ / \____\ \ \____\ / \____\
\/____/ \/____/ \/____/ \/____/
____________ ____________
/\ ___ \ /\ ___ \
\ \ \/_\ \ \ \ \/_\ \
\ \ _____/ _ \ \ _____/ _
\ \ \___/ ---- \ \ \___/ ----
\ \____\ / \____\ \ \____\ / \____\
\/____/ \/____/ \/____/ \/____/
@ -410,4 +410,4 @@
\ \ _____/ ___ ___ ___ \ \ _____/ ___ ___ ___
\ \ \___/ ---- \ \\ \\ \ \ \ \___/ ---- \ \\ \\ \
\ \____\ / \____\ \__\\__\\__\ \ \____\ / \____\ \__\\__\\__\
\/____/ \/____/ . PYPE Club . \/____/ \/____/ . PYPE Club .

View file

@ -13,11 +13,10 @@
import re import re
import os import os
import sys import sys
noColorama = False import blessed
try:
from colorama import Fore, Style, init, ansitowin32
except ImportError: term = blessed.Terminal()
noColorama = True
class Terminal: class Terminal:
@ -30,40 +29,37 @@ class Terminal:
""" """
# shortcuts for colorama codes # shortcuts for colorama codes
if noColorama:
_SB = _RST = _LR = _LG = _LB = _LM = _R = _G = _B = _C = _Y = _W = "" _SB = term.bold
_LY = "" _RST = ""
else: _LR = term.tomato2
_SB = Style.BRIGHT _LG = term.aquamarine3
_RST = Style.RESET_ALL _LB = term.turquoise2
_LR = Fore.LIGHTRED_EX _LM = term.slateblue2
_LG = Fore.LIGHTGREEN_EX _LY = term.gold
_LB = Fore.LIGHTBLUE_EX _R = term.red
_LM = Fore.LIGHTMAGENTA_EX _G = term.green
_LY = Fore.LIGHTYELLOW_EX _B = term.blue
_R = Fore.RED _C = term.cyan
_G = Fore.GREEN _Y = term.yellow
_B = Fore.BLUE _W = term.white
_C = Fore.CYAN
_Y = Fore.YELLOW
_W = Fore.WHITE
# dictionary replacing string sequences with colorized one # dictionary replacing string sequences with colorized one
_sdict = { _sdict = {
r">>> ": _SB + _G + r">>> " + _RST, r">>> ": _SB + _LG + r">>> " + _RST,
r"!!!(?!\sCRI|\sERR)": _SB + _R + r"!!! " + _RST, r"!!!(?!\sCRI|\sERR)": _SB + _R + r"!!! " + _RST,
r"\-\-\- ": _SB + _C + 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"\*\*\* 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"\]": _SB + _LG + r"]" + _RST, r"\]": _SB + _LG + r"]" + _RST,
r"{": _LG + r"{", r"{": _LG + r"{",
r"}": r"}" + _RST, r"}": r"}" + _RST,
r"\(": _LY + r"(", r"\(": _LY + r"(",
r"\)": r")" + _RST, r"\)": r")" + _RST,
r"^\.\.\. ": _SB + _LM + r"... " + _RST, r"^\.\.\. ": _SB + _LR + r"... " + _RST,
r"!!! ERR: ": r"!!! ERR: ":
_SB + _LR + r"!!! ERR: " + _RST, _SB + _LR + r"!!! ERR: " + _RST,
r"!!! CRI: ": r"!!! CRI: ":
@ -73,8 +69,7 @@ class Terminal:
} }
def __init__(self): def __init__(self):
if not noColorama: pass
init()
@staticmethod @staticmethod
def _multiple_replace(text, adict): def _multiple_replace(text, adict):
@ -108,11 +103,6 @@ class Terminal:
str: Colorized message. str: Colorized message.
""" """
if noColorama:
print(message)
return message
if not isinstance(sys.stdout, ansitowin32.StreamWrapper):
init()
colorized = Terminal.log(message) colorized = Terminal.log(message)
print(colorized) print(colorized)

View file

@ -1,12 +1,15 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Pype terminal animation :)""" """Pype terminal animation :)"""
import os import os
import blessed
from pathlib import Path from pathlib import Path
from time import sleep from time import sleep
import sys import sys
term = blessed.Terminal()
def play_animation(): def play_animation():
print(term.home + term.clear)
frame_size = 7 frame_size = 7
splash_file = Path(__file__).parent / "splash.txt" splash_file = Path(__file__).parent / "splash.txt"
with splash_file.open("r") as sf: with splash_file.open("r") as sf:
@ -15,11 +18,17 @@ def play_animation():
animation_length = int(len(animation) / frame_size) animation_length = int(len(animation) / frame_size)
current_frame = 0 current_frame = 0
for _ in range(animation_length): for _ in range(animation_length):
if sys.platform.startswith('win'): frame = ""
os.system('cls') y = 0
else:
os.system('clear')
for scanline in animation[current_frame:current_frame + frame_size]: for scanline in animation[current_frame:current_frame + frame_size]:
print(scanline.rstrip()) frame += scanline
sleep(0.005) 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 current_frame += frame_size
print(term.move_y(7))

View file

@ -1,9 +1,11 @@
aiohttp aiohttp
appdirs appdirs
arrow arrow
blessed
certifi certifi
Click Click
clique==1.5.0 clique==1.5.0
colorama
coverage coverage
cx_Freeze cx_Freeze
ftrack-python-api==2.0.0 ftrack-python-api==2.0.0