mirror of https://github.com/deadc0de6/catcli
refactoring
parent
34fb8d4894
commit
101f2d217b
@ -0,0 +1,37 @@
|
|||||||
|
"""
|
||||||
|
author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
|
Copyright (c) 2022, deadc0de6
|
||||||
|
|
||||||
|
shell colors
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Colors:
|
||||||
|
"""shell colors"""
|
||||||
|
|
||||||
|
RED = '\033[91m'
|
||||||
|
GREEN = '\033[92m'
|
||||||
|
YELLOW = '\033[93m'
|
||||||
|
PURPLE = '\033[1;35m'
|
||||||
|
BLUE = '\033[94m'
|
||||||
|
GRAY = '\033[0;37m'
|
||||||
|
MAGENTA = '\033[95m'
|
||||||
|
RESET = '\033[0m'
|
||||||
|
EMPH = '\033[33m'
|
||||||
|
BOLD = '\033[1m'
|
||||||
|
UND = '\033[4m'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def no_color(cls):
|
||||||
|
"""disable colors"""
|
||||||
|
Colors.RED = ''
|
||||||
|
Colors.GREEN = ''
|
||||||
|
Colors.YELLOW = ''
|
||||||
|
Colors.PURPLE = ''
|
||||||
|
Colors.BLUE = ''
|
||||||
|
Colors.GRAY = ''
|
||||||
|
Colors.MAGENTA = ''
|
||||||
|
Colors.RESET = ''
|
||||||
|
Colors.EMPH = ''
|
||||||
|
Colors.BOLD = ''
|
||||||
|
Colors.UND = ''
|
@ -0,0 +1,61 @@
|
|||||||
|
"""
|
||||||
|
author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
|
Copyright (c) 2022, deadc0de6
|
||||||
|
|
||||||
|
Class for printing nodes
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from catcli.colors import Colors
|
||||||
|
from catcli.utils import fix_badchars
|
||||||
|
|
||||||
|
|
||||||
|
class NodePrinter:
|
||||||
|
"""a node printer class"""
|
||||||
|
|
||||||
|
STORAGE = 'storage'
|
||||||
|
ARCHIVE = 'archive'
|
||||||
|
NBFILES = 'nbfiles'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def print_storage_native(cls, pre, name, args, attr):
|
||||||
|
"""print a storage node"""
|
||||||
|
end = ''
|
||||||
|
if attr:
|
||||||
|
end = f' {Colors.GRAY}({attr}){Colors.RESET}'
|
||||||
|
out = f'{pre}{Colors.UND}{cls.STORAGE}{Colors.RESET}:'
|
||||||
|
out += ' ' + Colors.PURPLE + fix_badchars(name) + \
|
||||||
|
Colors.RESET + end + '\n'
|
||||||
|
out += f' {Colors.GRAY}{args}{Colors.RESET}'
|
||||||
|
sys.stdout.write(f'{out}\n')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def print_file_native(cls, pre, name, attr):
|
||||||
|
"""print a file node"""
|
||||||
|
nobad = fix_badchars(name)
|
||||||
|
out = f'{pre}{nobad}'
|
||||||
|
out += f' {Colors.GRAY}[{attr}]{Colors.RESET}'
|
||||||
|
sys.stdout.write(f'{out}\n')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def print_dir_native(cls, pre, name, depth='', attr=None):
|
||||||
|
"""print a directory node"""
|
||||||
|
end = []
|
||||||
|
if depth != '':
|
||||||
|
end.append(f'{cls.NBFILES}:{depth}')
|
||||||
|
if attr:
|
||||||
|
end.append(' '.join([f'{x}:{y}' for x, y in attr]))
|
||||||
|
if end:
|
||||||
|
endstring = ', '.join(end)
|
||||||
|
end = f' [{endstring}]'
|
||||||
|
out = pre + Colors.BLUE + fix_badchars(name) + Colors.RESET
|
||||||
|
out += f'{Colors.GRAY}{end}{Colors.RESET}'
|
||||||
|
sys.stdout.write(f'{out}\n')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def print_archive_native(cls, pre, name, archive):
|
||||||
|
"""archive to stdout"""
|
||||||
|
out = pre + Colors.YELLOW + fix_badchars(name) + Colors.RESET
|
||||||
|
out += f' {Colors.GRAY}[{cls.ARCHIVE}:{archive}]{Colors.RESET}'
|
||||||
|
sys.stdout.write(f'{out}\n')
|
Loading…
Reference in New Issue