Added settings attribute to history file
This commit is contained in:
@@ -23,12 +23,28 @@ class EnhancedJSONEncoder(json.JSONEncoder):
|
|||||||
class HistoryEntry:
|
class HistoryEntry:
|
||||||
last_used: str
|
last_used: str
|
||||||
flake: FlakeConfig
|
flake: FlakeConfig
|
||||||
|
settings: dict[str, Any] = dataclasses.field(default_factory=dict)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
if isinstance(self.flake, dict):
|
if isinstance(self.flake, dict):
|
||||||
self.flake = FlakeConfig(**self.flake)
|
self.flake = FlakeConfig(**self.flake)
|
||||||
|
|
||||||
|
|
||||||
|
def merge_dicts(d1: dict, d2: dict) -> dict:
|
||||||
|
# create a new dictionary that copies d1
|
||||||
|
merged = dict(d1)
|
||||||
|
# iterate over the keys and values of d2
|
||||||
|
for key, value in d2.items():
|
||||||
|
# if the key is in d1 and both values are dictionaries, merge them recursively
|
||||||
|
if key in d1 and isinstance(d1[key], dict) and isinstance(value, dict):
|
||||||
|
merged[key] = merge_dicts(d1[key], value)
|
||||||
|
# otherwise, update the value of the key in the merged dictionary
|
||||||
|
else:
|
||||||
|
merged[key] = value
|
||||||
|
# return the merged dictionary
|
||||||
|
return merged
|
||||||
|
|
||||||
|
|
||||||
def list_history() -> list[HistoryEntry]:
|
def list_history() -> list[HistoryEntry]:
|
||||||
logs: list[HistoryEntry] = []
|
logs: list[HistoryEntry] = []
|
||||||
if not user_history_file().exists():
|
if not user_history_file().exists():
|
||||||
@@ -36,6 +52,8 @@ def list_history() -> list[HistoryEntry]:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
parsed = read_history_file()
|
parsed = read_history_file()
|
||||||
|
for i, p in enumerate(parsed.copy()):
|
||||||
|
parsed[i] = merge_dicts(p, p["settings"])
|
||||||
logs = [HistoryEntry(**p) for p in parsed]
|
logs = [HistoryEntry(**p) for p in parsed]
|
||||||
except (json.JSONDecodeError, TypeError) as ex:
|
except (json.JSONDecodeError, TypeError) as ex:
|
||||||
print("Failed to load history. Invalid JSON.")
|
print("Failed to load history. Invalid JSON.")
|
||||||
|
|||||||
Reference in New Issue
Block a user