[M] Move literal types to types.py
This commit is contained in:
parent
4d073df750
commit
f786dce40e
6 changed files with 22 additions and 21 deletions
|
@ -2,13 +2,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
import colorsys
|
import colorsys
|
||||||
from dataclasses import dataclass, astuple
|
from dataclasses import dataclass, astuple
|
||||||
from typing_extensions import Literal
|
|
||||||
|
|
||||||
from .constants import GLOBAL_CFG
|
from .constants import GLOBAL_CFG
|
||||||
|
from .types import *
|
||||||
AnsiMode = Literal['default', 'ansi', '8bit', 'rgb']
|
|
||||||
LightDark = Literal['light', 'dark']
|
|
||||||
|
|
||||||
|
|
||||||
MINECRAFT_COLORS = ["&0/\033[0;30m", "&1/\033[0;34m", "&2/\033[0;32m", "&3/\033[0;36m", "&4/\033[0;31m",
|
MINECRAFT_COLORS = ["&0/\033[0;30m", "&1/\033[0;34m", "&2/\033[0;32m", "&3/\033[0;36m", "&4/\033[0;31m",
|
||||||
"&5/\033[0;35m", "&6/\033[0;33m", "&7/\033[0;37m", "&8/\033[1;30m", "&9/\033[1;34m",
|
"&5/\033[0;35m", "&6/\033[0;33m", "&7/\033[0;37m", "&8/\033[1;30m", "&9/\033[1;34m",
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing_extensions import Literal
|
from .types import LightDark
|
||||||
|
|
||||||
CONFIG_PATH = Path.home() / '.config/hyfetch.json'
|
CONFIG_PATH = Path.home() / '.config/hyfetch.json'
|
||||||
VERSION = '1.4.4'
|
VERSION = '1.4.4'
|
||||||
|
@ -36,10 +35,10 @@ class GlobalConfig:
|
||||||
debug: bool
|
debug: bool
|
||||||
is_light: bool
|
is_light: bool
|
||||||
|
|
||||||
def light_dark(self) -> Literal['light', 'dark']:
|
def light_dark(self) -> LightDark:
|
||||||
return 'light' if self.is_light else 'dark'
|
return 'light' if self.is_light else 'dark'
|
||||||
|
|
||||||
def default_lightness(self, term: Literal['light', 'dark'] | None = None) -> float:
|
def default_lightness(self, term: LightDark | None = None) -> float:
|
||||||
if term is None:
|
if term is None:
|
||||||
term = self.light_dark()
|
term = self.light_dark()
|
||||||
return 0.65 if term.lower() == 'dark' else 0.4
|
return 0.65 if term.lower() == 'dark' else 0.4
|
||||||
|
|
|
@ -2,10 +2,10 @@ from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
from .color_util import AnsiMode, LightDark
|
|
||||||
from .constants import CONFIG_PATH
|
from .constants import CONFIG_PATH
|
||||||
from .neofetch_util import ColorAlignment
|
from .neofetch_util import ColorAlignment
|
||||||
from .serializer import json_stringify, from_dict
|
from .serializer import json_stringify, from_dict
|
||||||
|
from .types import AnsiMode, LightDark, BackendLiteral
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -15,6 +15,7 @@ class Config:
|
||||||
light_dark: LightDark = 'dark'
|
light_dark: LightDark = 'dark'
|
||||||
lightness: float | None = None
|
lightness: float | None = None
|
||||||
color_align: ColorAlignment = field(default_factory=lambda: ColorAlignment('horizontal'))
|
color_align: ColorAlignment = field(default_factory=lambda: ColorAlignment('horizontal'))
|
||||||
|
backend: BackendLiteral = "neofetch"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, d: dict):
|
def from_dict(cls, d: dict):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import inspect
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
@ -15,12 +14,12 @@ from tempfile import TemporaryDirectory
|
||||||
from urllib.request import urlretrieve
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from typing_extensions import Literal
|
|
||||||
|
|
||||||
from hyfetch.color_util import color
|
from hyfetch.color_util import color
|
||||||
from .constants import GLOBAL_CFG, MINGIT_URL
|
from .constants import GLOBAL_CFG, MINGIT_URL
|
||||||
from .presets import ColorProfile
|
from .presets import ColorProfile
|
||||||
from .serializer import from_dict
|
from .serializer import from_dict
|
||||||
|
from .types import BackendLiteral, ColorAlignMode
|
||||||
|
|
||||||
RE_NEOFETCH_COLOR = re.compile('\\${c[0-9]}')
|
RE_NEOFETCH_COLOR = re.compile('\\${c[0-9]}')
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ def fill_starting(asc: str) -> str:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ColorAlignment:
|
class ColorAlignment:
|
||||||
mode: Literal['horizontal', 'vertical', 'custom']
|
mode: ColorAlignMode
|
||||||
|
|
||||||
# custom_colors[ascii color index] = unique color index in preset
|
# custom_colors[ascii color index] = unique color index in preset
|
||||||
custom_colors: dict[int, int] = ()
|
custom_colors: dict[int, int] = ()
|
||||||
|
@ -201,7 +200,7 @@ def check_windows_cmd():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def run_command(args: str, pipe: bool = False) -> str | None:
|
def run_neofetch_cmd(args: str, pipe: bool = False) -> str | None:
|
||||||
"""
|
"""
|
||||||
Run neofetch command
|
Run neofetch command
|
||||||
"""
|
"""
|
||||||
|
@ -237,7 +236,7 @@ def get_distro_ascii(distro: str | None = None) -> str:
|
||||||
if distro:
|
if distro:
|
||||||
cmd += f' --ascii_distro {distro}'
|
cmd += f' --ascii_distro {distro}'
|
||||||
|
|
||||||
asc = run_command(cmd, True)
|
asc = run_neofetch_cmd(cmd, True)
|
||||||
|
|
||||||
# Unescape backslashes here because backslashes are escaped in neofetch for printf
|
# Unescape backslashes here because backslashes are escaped in neofetch for printf
|
||||||
asc = asc.replace('\\\\', '\\')
|
asc = asc.replace('\\\\', '\\')
|
||||||
|
@ -246,7 +245,7 @@ def get_distro_ascii(distro: str | None = None) -> str:
|
||||||
|
|
||||||
|
|
||||||
def get_distro_name():
|
def get_distro_name():
|
||||||
return run_command('ascii_distro_name', True)
|
return run_neofetch_cmd('ascii_distro_name', True)
|
||||||
|
|
||||||
|
|
||||||
def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
|
def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
|
||||||
|
@ -269,7 +268,7 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
|
||||||
path.write_text(asc)
|
path.write_text(asc)
|
||||||
|
|
||||||
# Call neofetch with the temp file
|
# Call neofetch with the temp file
|
||||||
run_command(f'--ascii --source {path.absolute()} --ascii-colors')
|
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors')
|
||||||
|
|
||||||
|
|
||||||
def get_fore_back(distro: str | None = None) -> tuple[int, int] | None:
|
def get_fore_back(distro: str | None = None) -> tuple[int, int] | None:
|
||||||
|
|
|
@ -2,10 +2,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from typing_extensions import Literal
|
from .color_util import RGB
|
||||||
|
|
||||||
from .color_util import RGB, LightDark
|
|
||||||
from .constants import GLOBAL_CFG
|
from .constants import GLOBAL_CFG
|
||||||
|
from .types import LightDark, ColorSpacing
|
||||||
|
|
||||||
|
|
||||||
def remove_duplicates(seq: Iterable) -> list:
|
def remove_duplicates(seq: Iterable) -> list:
|
||||||
|
@ -20,7 +19,7 @@ def remove_duplicates(seq: Iterable) -> list:
|
||||||
class ColorProfile:
|
class ColorProfile:
|
||||||
raw: list[str]
|
raw: list[str]
|
||||||
colors: list[RGB]
|
colors: list[RGB]
|
||||||
spacing: Literal['equal', 'weighted'] = 'equal'
|
spacing: ColorSpacing = 'equal'
|
||||||
|
|
||||||
def __init__(self, colors: list[str] | list[RGB]):
|
def __init__(self, colors: list[str] | list[RGB]):
|
||||||
if isinstance(colors[0], str):
|
if isinstance(colors[0], str):
|
||||||
|
|
7
hyfetch/types.py
Normal file
7
hyfetch/types.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
AnsiMode = Literal['default', 'ansi', '8bit', 'rgb']
|
||||||
|
LightDark = Literal['light', 'dark']
|
||||||
|
BackendLiteral = Literal["neofetch", "fastfetch"]
|
||||||
|
ColorAlignMode = Literal['horizontal', 'vertical', 'custom']
|
||||||
|
ColorSpacing = Literal['equal', 'weighted']
|
Loading…
Reference in a new issue