Added version command to cli

This commit is contained in:
2020-12-16 14:35:43 +01:00
parent 88362006ef
commit 5fb20035d8
7 changed files with 87 additions and 11 deletions

View File

@@ -1,5 +1,8 @@
import os
from typing import Union, Optional
import pyfiglet
from tabulate import tabulate
from termcolor import colored
from sh_edraft.console.model.background_color import BackgroundColor
@@ -7,6 +10,8 @@ from sh_edraft.console.model.foreground_color import ForegroundColor
class Console:
_is_first_write = True
_background_color: BackgroundColor = BackgroundColor.default
_foreground_color: ForegroundColor = ForegroundColor.default
_x: Optional[int] = None
@@ -64,6 +69,9 @@ class Console:
if cls._disabled:
return
if cls._is_first_write:
cls._is_first_write = False
args = []
colored_args = []
@@ -88,6 +96,11 @@ class Console:
Useful public methods
"""
@classmethod
def banner(cls, string: str):
ascii_banner = pyfiglet.figlet_format(string)
cls.write_line(ascii_banner)
@staticmethod
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
@@ -103,6 +116,15 @@ class Console:
def disable(cls):
cls._disabled = True
@classmethod
def error(cls, string: str, tb: str = None):
cls.set_foreground_color('red')
if tb is not None:
cls.write_line(f'{string} -> {tb}')
else:
cls.write_line(string)
cls.set_foreground_color('default')
@classmethod
def enable(cls):
cls._disabled = False
@@ -126,6 +148,12 @@ class Console:
cls._background_color = BackgroundColor.default
cls._foreground_color = ForegroundColor.default
@classmethod
def table(cls, header: list[str], values: list[list[str]]):
table = tabulate(values, headers=header)
Console.write_line(table)
@classmethod
def write(cls, *args):
string = ' '.join(map(str, args))
@@ -139,11 +167,13 @@ class Console:
@classmethod
def write_line(cls, *args):
string = ' '.join(map(str, args))
cls._output('')
if not cls._is_first_write:
cls._output('')
cls._output(string, end='')
@classmethod
def write_line_at(cls, x: int, y: int, *args):
string = ' '.join(map(str, args))
cls._output('', end='')
if not cls._is_first_write:
cls._output('', end='')
cls._output(string, x, y, end='')