Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
120 lines (91 loc) · 3.27 KB
/
Copy pathconfig.py
File metadata and controls
120 lines (91 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
User configuration management.
Stores user preferences locally in a JSON file.
"""
import json
from pathlib import Path
from typing import Optional, List
# Config file location - in the data directory
CONFIG_DIR = Path(__file__).parent / "data"
CONFIG_FILE = CONFIG_DIR / "user_config.json"
# Default configuration
DEFAULT_CONFIG = {
"user_name": "", # User's name for personalized prompts
"relationship_names": [], # List of people the user wants to track
"setup_complete": False, # Whether initial setup has been done
"theme": "void", # UI theme (currently only void)
}
def ensure_config():
"""Ensure config file exists with defaults."""
CONFIG_DIR.mkdir(exist_ok=True)
if not CONFIG_FILE.exists():
save_config(DEFAULT_CONFIG)
def load_config() -> dict:
"""Load user configuration."""
ensure_config()
try:
with open(CONFIG_FILE, 'r') as f:
config = json.load(f)
# Merge with defaults for any missing keys
for key, value in DEFAULT_CONFIG.items():
if key not in config:
config[key] = value
return config
except (json.JSONDecodeError, IOError):
return DEFAULT_CONFIG.copy()
def save_config(config: dict):
"""Save user configuration."""
CONFIG_DIR.mkdir(exist_ok=True)
with open(CONFIG_FILE, 'w') as f:
json.dump(config, f, indent=2)
def get_user_name() -> str:
"""Get the configured user name, or empty string if not set."""
config = load_config()
return config.get("user_name", "")
def set_user_name(name: str):
"""Set the user's name."""
config = load_config()
config["user_name"] = name
save_config(config)
def get_relationship_names() -> List[str]:
"""Get the list of relationship names to track."""
config = load_config()
return config.get("relationship_names", [])
def set_relationship_names(names: List[str]):
"""Set the list of relationship names."""
config = load_config()
config["relationship_names"] = names
save_config(config)
def add_relationship_name(name: str):
"""Add a name to the relationship tracking list."""
names = get_relationship_names()
name_lower = name.lower().strip()
if name_lower and name_lower not in [n.lower() for n in names]:
names.append(name_lower)
set_relationship_names(names)
def remove_relationship_name(name: str):
"""Remove a name from the relationship tracking list."""
names = get_relationship_names()
name_lower = name.lower().strip()
names = [n for n in names if n.lower() != name_lower]
set_relationship_names(names)
def is_setup_complete() -> bool:
"""Check if initial setup has been completed."""
config = load_config()
return config.get("setup_complete", False)
def mark_setup_complete():
"""Mark initial setup as complete."""
config = load_config()
config["setup_complete"] = True
save_config(config)
def reset_config():
"""Reset configuration to defaults."""
save_config(DEFAULT_CONFIG.copy())
# Helper to get name for prompts (with fallback)
def get_prompt_name() -> str:
"""
Get the name to use in prompts.
Returns the user's name if set, otherwise 'you'.
"""
name = get_user_name()
return name if name else "you"