[F] AttributeError: 'dict' object has no attribute 'recolor_ascii'
This commit is contained in:
parent
d11796ef02
commit
85eaad14f2
4 changed files with 19 additions and 3 deletions
|
@ -27,7 +27,7 @@ def check_config() -> Config:
|
||||||
:return: Config object
|
:return: Config object
|
||||||
"""
|
"""
|
||||||
if CONFIG_PATH.is_file():
|
if CONFIG_PATH.is_file():
|
||||||
return Config(**json.loads(CONFIG_PATH.read_text('utf-8')))
|
return Config.from_dict(json.loads(CONFIG_PATH.read_text('utf-8')))
|
||||||
|
|
||||||
return create_config()
|
return create_config()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from typing_extensions import Literal
|
||||||
from .color_util import AnsiMode
|
from .color_util import AnsiMode
|
||||||
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 .serializer import json_stringify, from_dict
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -18,6 +18,11 @@ class Config:
|
||||||
lightness: float | None = None
|
lightness: float | None = None
|
||||||
color_align: ColorAlignment = ColorAlignment('horizontal')
|
color_align: ColorAlignment = ColorAlignment('horizontal')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, d: dict):
|
||||||
|
d['color_align'] = ColorAlignment.from_dict(d['color_align'])
|
||||||
|
return from_dict(cls, d)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
CONFIG_PATH.parent.mkdir(exist_ok=True, parents=True)
|
CONFIG_PATH.parent.mkdir(exist_ok=True, parents=True)
|
||||||
CONFIG_PATH.write_text(json_stringify(self), 'utf-8')
|
CONFIG_PATH.write_text(json_stringify(self), 'utf-8')
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
|
@ -15,6 +16,7 @@ from typing_extensions import Literal
|
||||||
from hyfetch.color_util import color
|
from hyfetch.color_util import color
|
||||||
from .constants import GLOBAL_CFG
|
from .constants import GLOBAL_CFG
|
||||||
from .presets import ColorProfile
|
from .presets import ColorProfile
|
||||||
|
from .serializer import from_dict
|
||||||
|
|
||||||
RE_NEOFETCH_COLOR = re.compile('\\${c[0-9]}')
|
RE_NEOFETCH_COLOR = re.compile('\\${c[0-9]}')
|
||||||
|
|
||||||
|
@ -67,6 +69,10 @@ class ColorAlignment:
|
||||||
# Foreground/background ascii color index
|
# Foreground/background ascii color index
|
||||||
fore_back: tuple[int, int] = ()
|
fore_back: tuple[int, int] = ()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, d: dict):
|
||||||
|
return from_dict(cls, d)
|
||||||
|
|
||||||
def recolor_ascii(self, asc: str, preset: ColorProfile) -> str:
|
def recolor_ascii(self, asc: str, preset: ColorProfile) -> str:
|
||||||
"""
|
"""
|
||||||
Use the color alignment to recolor an ascii art
|
Use the color alignment to recolor an ascii art
|
||||||
|
@ -177,7 +183,7 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
|
||||||
color_alignments = {
|
color_alignments = {
|
||||||
'fedora': ColorAlignment('horizontal', fore_back=(2, 1)),
|
'fedora': ColorAlignment('horizontal', fore_back=(2, 1)),
|
||||||
'ubuntu': ColorAlignment('horizontal', fore_back=(2, 1)),
|
'ubuntu': ColorAlignment('horizontal', fore_back=(2, 1)),
|
||||||
'nixos': ColorAlignment('custom', {1: 1, 2: 0}),
|
'NixOS.*': ColorAlignment('custom', {1: 1, 2: 0}),
|
||||||
# 'arch': ColorAlignment('horizontal'),
|
# 'arch': ColorAlignment('horizontal'),
|
||||||
# 'centos': ColorAlignment('horizontal'),
|
# 'centos': ColorAlignment('horizontal'),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import inspect
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
|
|
||||||
|
@ -41,3 +42,7 @@ def json_stringify(obj: object, indent: int | None = None) -> str:
|
||||||
:return: Json strings
|
:return: Json strings
|
||||||
"""
|
"""
|
||||||
return json.dumps(obj, indent=indent, cls=EnhancedJSONEncoder, ensure_ascii=False)
|
return json.dumps(obj, indent=indent, cls=EnhancedJSONEncoder, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
|
def from_dict(cls, d: dict):
|
||||||
|
return cls(**{k: v for k, v in d.items() if k in inspect.signature(cls).parameters})
|
||||||
|
|
Loading…
Reference in a new issue