Use colorama for terminal colors, to get Windows support

This commit is contained in:
Micah Lee 2021-05-02 15:13:50 -07:00
parent 7554d0e3fd
commit 94d5544bda
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 116 additions and 122 deletions

View File

@ -29,6 +29,9 @@ import time
import shutil
from pkg_resources import resource_filename
import colorama
from colorama import Fore, Back, Style
from .settings import Settings
@ -43,18 +46,11 @@ class Common:
The Common object is shared amongst all parts of OnionShare.
"""
C_RESET = "\033[0m"
C_BG_PURPLE = "\033[45m"
C_BOLD = "\033[01m"
C_WHITE = "\033[97m"
C_LIGHTGRAY = "\033[37m"
C_DARKGRAY = "\033[90m"
C_LIGHTPURPLE = "\033[95m"
C_DARKPURPLE = "\033[35m"
def __init__(self, verbose=False):
self.verbose = verbose
colorama.init(autoreset=True)
# The platform OnionShare is running on
self.platform = platform.system()
if self.platform.endswith("BSD") or self.platform == "DragonFly":
@ -90,219 +86,195 @@ class Common:
"""
if self.platform == "Windows":
pass
else:
pass
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
+ "╭───────────────────────────────────────────╮"
+ self.C_RESET
Back.MAGENTA + Fore.WHITE + "╭───────────────────────────────────────────╮"
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_WHITE
+ Fore.WHITE
+ "▄▄█████▄▄"
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▄████▀▀▀████▄"
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▀▀█▀ ▀██▄ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_WHITE
+ Fore.WHITE
+ "▄█▄ ▀██▄ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▄█████▄ ███"
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " -+- "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ███ ▀█████▀ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▀██▄ ▀█▀ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_WHITE
+ Fore.WHITE
+ "▀██▄ ▄█▄▄"
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " * "
+ self.C_WHITE
+ Fore.WHITE
+ "▀████▄▄▄████▀ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▀▀█████▀▀ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTPURPLE
+ Fore.LIGHTMAGENTA_EX
+ " -+- * "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▄▀▄ ▄▀▀ █ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " █ █ ▀ ▀▄ █ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " █ █ █▀▄ █ ▄▀▄ █▀▄ ▀▄ █▀▄ ▄▀▄ █▄▀ ▄█▄ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_WHITE
+ Fore.WHITE
+ " ▀▄▀ █ █ █ ▀▄▀ █ █ ▄▄▀ █ █ ▀▄█ █ ▀▄▄ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
+ "│ │"
+ self.C_RESET
Back.MAGENTA + Fore.WHITE + "│ │"
)
left_spaces = (43 - len(self.version) - 1) // 2
right_spaces = left_spaces
if left_spaces + len(self.version) + right_spaces < 43:
right_spaces += 1
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ f"{' '*left_spaces}v{self.version}{' '*right_spaces}"
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
+ "│ │"
+ self.C_RESET
Back.MAGENTA + Fore.WHITE + "│ │"
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
Back.MAGENTA
+ Fore.WHITE
+ ""
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ " https://onionshare.org/ "
+ self.C_LIGHTGRAY
+ Fore.WHITE
+ ""
+ self.C_RESET
)
print(
self.C_BG_PURPLE
+ self.C_LIGHTGRAY
+ "╰───────────────────────────────────────────╯"
+ self.C_RESET
Back.MAGENTA + Fore.WHITE + "╰───────────────────────────────────────────╯"
)
print()
@ -319,9 +291,11 @@ class Common:
"""
if self.verbose:
timestamp = time.strftime("%b %d %Y %X")
final_msg = f"{self.C_DARKGRAY}[{timestamp}]{self.C_RESET} {self.C_LIGHTGRAY}{module}.{func}{self.C_RESET}"
final_msg = f"{Fore.BLACK + Style.BRIGHT}[{timestamp}]{Style.RESET_ALL} {Fore.WHITE + Style.DIM}{module}.{func}{Style.RESET_ALL}"
if msg:
final_msg = f"{final_msg}{self.C_LIGHTGRAY}: {msg}{self.C_RESET}"
final_msg = (
f"{final_msg}{Fore.WHITE + Style.DIM}: {msg}{Style.RESET_ALL}"
)
print(final_msg)
def get_resource_path(self, filename):

23
cli/poetry.lock generated
View File

@ -63,7 +63,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
name = "colorama"
version = "0.4.4"
description = "Cross-platform colored terminal text."
category = "dev"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
@ -424,7 +424,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt
[metadata]
lock-version = "1.1"
python-versions = "^3.6"
content-hash = "27f9680e537bbe672c9dc3e65a88e3d9f19c4f849135153580a4209773bbced5"
content-hash = "af196689bfa09fc05b61fc0829e1b0b54888b5503602ff04174bc967d688c180"
[metadata.files]
atomicwrites = [
@ -559,20 +559,39 @@ markupsafe = [
{file = "MarkupSafe-1.1.1-cp35-cp35m-win32.whl", hash = "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1"},
{file = "MarkupSafe-1.1.1-cp35-cp35m-win_amd64.whl", hash = "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d53bc011414228441014aa71dbec320c66468c1030aae3a6e29778a3382d96e5"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:3b8a6499709d29c2e2399569d96719a1b21dcd94410a586a18526b143ec8470f"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:84dee80c15f1b560d55bcfe6d47b27d070b4681c699c572af2e3c7cc90a3b8e0"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:b1dba4527182c95a0db8b6060cc98ac49b9e2f5e64320e2b56e47cb2831978c7"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-win32.whl", hash = "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66"},
{file = "MarkupSafe-1.1.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_6_intel.whl", hash = "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:bf5aa3cbcfdf57fa2ee9cd1822c862ef23037f5c832ad09cfea57fa846dec193"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:6fffc775d90dcc9aed1b89219549b329a9250d918fd0b8fa8d93d154918422e1"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:a6a744282b7718a2a62d2ed9d993cad6f5f585605ad352c11de459f4108df0a1"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:195d7d2c4fbb0ee8139a6cf67194f3973a6b3042d742ebe0a9ed36d8b6f0c07f"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"},
{file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"},
{file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"},
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"},
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"},
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:acf08ac40292838b3cbbb06cfe9b2cb9ec78fce8baca31ddb87aaac2e2dc3bc2"},
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:d9be0ba6c527163cbed5e0857c451fcd092ce83947944d6c14bc95441203f032"},
{file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:caabedc8323f1e93231b52fc32bdcde6db817623d33e100708d9a68e1f53b26b"},
{file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"},
{file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"},
{file = "MarkupSafe-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d73a845f227b0bfe8a7455ee623525ee656a9e2e749e4742706d80a6065d5e2c"},
{file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:98bae9582248d6cf62321dcb52aaf5d9adf0bad3b40582925ef7c7f0ed85fceb"},
{file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:2beec1e0de6924ea551859edb9e7679da6e4870d32cb766240ce17e0a0ba2014"},
{file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:7fed13866cf14bba33e7176717346713881f56d9d2bcebab207f7a036f41b850"},
{file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:6f1e273a344928347c1290119b493a1f0303c52f5a5eae5f16d74f48c15d4a85"},
{file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621"},
{file = "MarkupSafe-1.1.1-cp39-cp39-win32.whl", hash = "sha256:22c178a091fc6630d0d045bdb5992d2dfe14e3259760e713c490da5323866c39"},
{file = "MarkupSafe-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8"},
{file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"},
]
packaging = [

View File

@ -30,6 +30,7 @@ unidecode = "*"
urllib3 = "*"
eventlet = "*"
setuptools = "*"
colorama = "^0.4.4"
[tool.poetry.dev-dependencies]
pytest = "*"