Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
beucismis committed Apr 14, 2024
1 parent a9e1847 commit 855b49f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/tinyfetch/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "0.0.3"
from tinyfetch.module import Color, Module

__version__ = "0.0.4"
16 changes: 13 additions & 3 deletions src/tinyfetch/cli.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import argparse

import tinyfetch
from tinyfetch import core
from tinyfetch import core, module


def main() -> None:
parser = argparse.ArgumentParser(
prog="tinyfetch",
description="Python and system information command-line fetch tool",
)
parser.add_argument(
"--title-color",
default="blue",
choices=list(c.name for c in module.Color),
help="set default the title color",
)
parser.add_argument(
"--no-color",
action="store_true",
help="turn off all colors and disables",
)
parser.add_argument(
"--version",
action="version",
version="%(prog)s v{}".format(tinyfetch.__version__),
)
args = parser.parse_args()

if args:
core.render()
core.render(title_color=args.title_color, no_color=args.no_color)
35 changes: 18 additions & 17 deletions src/tinyfetch/core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from tinyfetch import module
from tinyfetch.module import Color

modules_list = [
module.Space,
module.UserHost,
module.SplitLine,
module.PythonVersion,
module.PIPVersion,
module.PIPPackages,
module.Implementation,
module.Compiler,
module.Space,
module.Kernel,
module.OperationSystem,
module.Space,
]

def render() -> None:
modules = [
module.Space(),
module.UserHost(),
module.SplitLine(),
module.PythonVersion(),
module.PIPVersion(),
module.PIPPackages(),
module.Implementation(),
module.Compiler(),
module.Space(),
module.Kernel(),
module.OperationSystem(),
module.Space(),
]

for m in modules:
print(m.output())
def render(title_color: str, no_color: bool = False) -> None:
for m in modules_list:
print(m.__call__(title_color=Color[title_color], no_color=no_color).output())
36 changes: 27 additions & 9 deletions src/tinyfetch/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,42 @@
import os
import platform
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import Union

RESET = "\u001b[0m"
BOLD = "\u001b[1m"
MAIN = BOLD + "\u001b[034m"
RESET = "\u001b[0m"


class Color(Enum):
red = "\u001b[31m"
green = "\u001b[32m"
yellow = "\u001b[33m"
blue = "\u001b[34m"
magenta = "\u001b[35m"
cyan = "\u001b[36m"


@dataclass
class Module:
title: str = field(init=False, default=None)
title: Union[str, None] = field(init=False, default=None)
value: str = field(init=False)
title_color: str = field(default=Color["blue"])
no_color: bool = field(default=False)

def output(self):
def output(self) -> str:
if self.title is None:
return self.value
return f"{MAIN}{self.title}:{RESET} {self.value}"
if self.no_color:
return f"{self.title}: {self.value}"
return f"{BOLD}{self.title_color.value}{self.title}:{RESET} {self.value}"


@dataclass
class Space(Module):
def __post_init__(self):
self.value = " "
self.value = ""


@dataclass
Expand All @@ -33,9 +47,13 @@ def __post_init__(self):
user = getpass.getuser()
host = os.uname().nodename
self.userhost = f"{user}@{host}"
self.value = MAIN + self.userhost + RESET

def __len__(self):
if self.no_color:
self.value = self.userhost
else:
self.value = f"{BOLD}{self.title_color.value}{self.userhost}{RESET}"

def __len__(self) -> int:
return len(self.userhost)


Expand Down Expand Up @@ -102,7 +120,7 @@ def __post_init__(self):
if os.name == "posix":
self.value = self.posix_os_name()

def posix_os_name(self):
def posix_os_name(self) -> str:
path = Path("/etc/os-release")
with open(path) as file:
reader = csv.reader(file, delimiter="=")
Expand Down

0 comments on commit 855b49f

Please sign in to comment.