Skip to content

Commit 855b49f

Browse files
committed
Bump version
1 parent a9e1847 commit 855b49f

4 files changed

Lines changed: 61 additions & 30 deletions

File tree

src/tinyfetch/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
__version__ = "0.0.3"
1+
from tinyfetch.module import Color, Module
2+
3+
__version__ = "0.0.4"

src/tinyfetch/cli.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import argparse
22

33
import tinyfetch
4-
from tinyfetch import core
4+
from tinyfetch import core, module
55

66

77
def main() -> None:
88
parser = argparse.ArgumentParser(
99
prog="tinyfetch",
1010
description="Python and system information command-line fetch tool",
1111
)
12+
parser.add_argument(
13+
"--title-color",
14+
default="blue",
15+
choices=list(c.name for c in module.Color),
16+
help="set default the title color",
17+
)
18+
parser.add_argument(
19+
"--no-color",
20+
action="store_true",
21+
help="turn off all colors and disables",
22+
)
1223
parser.add_argument(
1324
"--version",
1425
action="version",
1526
version="%(prog)s v{}".format(tinyfetch.__version__),
1627
)
1728
args = parser.parse_args()
1829

19-
if args:
20-
core.render()
30+
core.render(title_color=args.title_color, no_color=args.no_color)

src/tinyfetch/core.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
from tinyfetch import module
2+
from tinyfetch.module import Color
23

4+
modules_list = [
5+
module.Space,
6+
module.UserHost,
7+
module.SplitLine,
8+
module.PythonVersion,
9+
module.PIPVersion,
10+
module.PIPPackages,
11+
module.Implementation,
12+
module.Compiler,
13+
module.Space,
14+
module.Kernel,
15+
module.OperationSystem,
16+
module.Space,
17+
]
318

4-
def render() -> None:
5-
modules = [
6-
module.Space(),
7-
module.UserHost(),
8-
module.SplitLine(),
9-
module.PythonVersion(),
10-
module.PIPVersion(),
11-
module.PIPPackages(),
12-
module.Implementation(),
13-
module.Compiler(),
14-
module.Space(),
15-
module.Kernel(),
16-
module.OperationSystem(),
17-
module.Space(),
18-
]
1919

20-
for m in modules:
21-
print(m.output())
20+
def render(title_color: str, no_color: bool = False) -> None:
21+
for m in modules_list:
22+
print(m.__call__(title_color=Color[title_color], no_color=no_color).output())

src/tinyfetch/module.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,42 @@
33
import os
44
import platform
55
from dataclasses import dataclass, field
6+
from enum import Enum
67
from pathlib import Path
8+
from typing import Union
79

8-
RESET = "\u001b[0m"
910
BOLD = "\u001b[1m"
10-
MAIN = BOLD + "\u001b[034m"
11+
RESET = "\u001b[0m"
12+
13+
14+
class Color(Enum):
15+
red = "\u001b[31m"
16+
green = "\u001b[32m"
17+
yellow = "\u001b[33m"
18+
blue = "\u001b[34m"
19+
magenta = "\u001b[35m"
20+
cyan = "\u001b[36m"
1121

1222

1323
@dataclass
1424
class Module:
15-
title: str = field(init=False, default=None)
25+
title: Union[str, None] = field(init=False, default=None)
1626
value: str = field(init=False)
27+
title_color: str = field(default=Color["blue"])
28+
no_color: bool = field(default=False)
1729

18-
def output(self):
30+
def output(self) -> str:
1931
if self.title is None:
2032
return self.value
21-
return f"{MAIN}{self.title}:{RESET} {self.value}"
33+
if self.no_color:
34+
return f"{self.title}: {self.value}"
35+
return f"{BOLD}{self.title_color.value}{self.title}:{RESET} {self.value}"
2236

2337

2438
@dataclass
2539
class Space(Module):
2640
def __post_init__(self):
27-
self.value = " "
41+
self.value = ""
2842

2943

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

38-
def __len__(self):
51+
if self.no_color:
52+
self.value = self.userhost
53+
else:
54+
self.value = f"{BOLD}{self.title_color.value}{self.userhost}{RESET}"
55+
56+
def __len__(self) -> int:
3957
return len(self.userhost)
4058

4159

@@ -102,7 +120,7 @@ def __post_init__(self):
102120
if os.name == "posix":
103121
self.value = self.posix_os_name()
104122

105-
def posix_os_name(self):
123+
def posix_os_name(self) -> str:
106124
path = Path("/etc/os-release")
107125
with open(path) as file:
108126
reader = csv.reader(file, delimiter="=")

0 commit comments

Comments
 (0)