diff --git a/whyfetch/__init__.py b/whyfetch/__init__.py index 576fc60..95fc59f 100644 --- a/whyfetch/__init__.py +++ b/whyfetch/__init__.py @@ -1,8 +1,9 @@ from whyfetch.data import Data + def separator_from_longest_prop(props: list[str]): j: int = 0 - + for i in props: if len(i) > j: j = len(i) @@ -10,7 +11,8 @@ def separator_from_longest_prop(props: list[str]): else: continue - return "━"*j + return "━" * j + class Colours: red: str = "\x1b[1;31m" @@ -18,9 +20,10 @@ class Colours: white: str = "\x1b[1;39m" magenta: str = "\x1b[1;35m" + def __main__(): d: Data = Data() - + props: list[str] = [ f"{d.username}@{d.hostname}", f"kernel: {d.kernel}", @@ -28,17 +31,29 @@ def __main__(): f"shell: {d.shell}", f"ram: {d.ram}", f"up: {d.uptime}", - f"locale: {d.locale}" + f"locale: {d.locale}", ] separator: str = separator_from_longest_prop(props) - print(f'{Colours.white}━━━━━━━━━━━━━━━{separator}') - print(f' {Colours.red}_.----._{Colours.white} {Colours.magenta}{d.username}{Colours.white}@{Colours.magenta}{d.hostname}') - print(f' {Colours.red}.\' \'.{Colours.white} {Colours.magenta}kernel:{Colours.white} {d.kernel}') - print(f'{Colours.red}/{Colours.white}._ _.--._ {Colours.red}\\{Colours.white} {Colours.magenta}os:{Colours.white} {d.os}') - print(f'|_ \'-\' _.._ `| {Colours.magenta}shell:{Colours.white} {d.shell}') - print(f'{Colours.blue}\\{Colours.white} `---\' `-{Colours.blue}/{Colours.white} {Colours.magenta}ram:{Colours.white} {d.ram}') - print(f' {Colours.blue}\'._ _.\'{Colours.white} {Colours.magenta}up:{Colours.white} {d.uptime}') - print(f' {Colours.blue}\'----\'{Colours.white} {Colours.magenta}locale:{Colours.white} {d.locale}') - print(f'━━━━━━━━━━━━━━━{separator}') + print(f"{Colours.white}━━━━━━━━━━━━━━━{separator}") + print( + f" {Colours.red}_.----._{Colours.white} {Colours.magenta}{d.username}{Colours.white}@{Colours.magenta}{d.hostname}" + ) + print( + f" {Colours.red}.' '.{Colours.white} {Colours.magenta}kernel:{Colours.white} {d.kernel}" + ) + print( + f"{Colours.red}/{Colours.white}._ _.--._ {Colours.red}\\{Colours.white} {Colours.magenta}os:{Colours.white} {d.os}" + ) + print(f"|_ '-' _.._ `| {Colours.magenta}shell:{Colours.white} {d.shell}") + print( + f"{Colours.blue}\\{Colours.white} `---' `-{Colours.blue}/{Colours.white} {Colours.magenta}ram:{Colours.white} {d.ram}" + ) + print( + f" {Colours.blue}'._ _.'{Colours.white} {Colours.magenta}up:{Colours.white} {d.uptime}" + ) + print( + f" {Colours.blue}'----'{Colours.white} {Colours.magenta}locale:{Colours.white} {d.locale}" + ) + print(f"━━━━━━━━━━━━━━━{separator}") diff --git a/whyfetch/data.py b/whyfetch/data.py index cb5de54..59bf76b 100644 --- a/whyfetch/data.py +++ b/whyfetch/data.py @@ -12,6 +12,7 @@ import os ures: pl.uname_result = pl.uname() sys: str = pl.system() + class Data: def __init__(self) -> None: self.username: str = gp.getuser() @@ -23,13 +24,13 @@ class Data: self.uptime: str = self.get_uptime() self.locale: str = lc.setlocale(lc.LC_CTYPE) pass - + def get_os(self) -> str: if "Linux" == ures.system: linux_res: dict[str, str] = pl.freedesktop_os_release() - return linux_res['PRETTY_NAME'] + return linux_res["PRETTY_NAME"] - if [ "FreeBSD", "OpenBSD", "NetBSD" ] not in [ ures.system ]: + if ["FreeBSD", "OpenBSD", "NetBSD"] not in [ures.system]: return ures.system if sys == "Darwin": @@ -44,7 +45,7 @@ class Data: win_release: str = win_res[0] win_ver: str = win_res[1] return f"{win_release} {win_edition} {win_ver}" - + raise ValueError("Unknown operating system. %r" % sys) def get_shell(self) -> str: @@ -53,11 +54,11 @@ class Data: shell: str = shell_info[0] except sh.ShellDetectionFailure: shell: str = provide_default_shell() - + return shell def get_ram(self) -> str: - to_gb: Callable[[int], float] = lambda s: s / (1024 ** 3) + to_gb: Callable[[int], float] = lambda s: s / (1024**3) vm: NamedTuple = ps.virtual_memory() total: float = to_gb(vm.total) used: float = to_gb(vm.used) @@ -68,9 +69,10 @@ class Data: current_uptime: tm.struct_time = tm.gmtime(tm.time() - ps.boot_time()) return tm.strftime("%H hours, %M minutes, %S seconds", current_uptime) + def provide_default_shell() -> str: - if os.name == 'nt': - return os.environ['COMSPEC'] - elif os.name == 'posix': - return os.environ['SHELL'] - raise NotImplementedError(f'OS {os.name!r} support not available') + if os.name == "nt": + return os.environ["COMSPEC"] + elif os.name == "posix": + return os.environ["SHELL"] + raise NotImplementedError(f"OS {os.name!r} support not available")