implementing more settings

This commit is contained in:
SpookyDervish
2025-10-30 06:59:20 +11:00
parent c21af8508e
commit 7bc671ef63
2 changed files with 47 additions and 16 deletions

View File

@@ -1,40 +1,44 @@
from pathlib import Path
import os, subprocess
import os
import configparser
class ConfigHandler:
def __init__(self):
self.config = configparser.ConfigParser()
self.config: configparser.ConfigParser = configparser.ConfigParser()
self.config_dir = self.ensure_hidden_config_dir()
self.load_settings(self.config_dir)
self.config_dir: str = self.ensure_hidden_config_dir()
self.load_settings()
def ensure_hidden_config_dir(self):
config_dir = Path.home() / ".berry"
config_dir.mkdir(parents=True, exist_ok=True)
# If Windows, apply hidden attribute
if os.name == "nt":
subprocess.run(["attrib", "+h", str(config_dir)], shell=True)
return config_dir
def get(self, section: str, option: str):
return self.config.get(section, option)
def set(self, section: str, option: str, new_value: str):
return self.config.set(section, option, new_value)
def load_settings(self):
if os.path.isfile(self.config_dir / "config.ini"):
with open(self.config_dir / "config.ini", "r") as configfile:
self.config.read(configfile)
self.config.read(self.config_dir / "config.ini")
return
self.config["config"] = {
"version": "1"
}
self.config["editor"] = {
"word_wrap": True
"word_wrap": "0"
}
self.config["plugins"] = {
"enabled": True
"enabled": "1"
}
self.config["appearance"] = {
"colour_theme": "textual-dark"
}
with open(self.config_dir / "config.ini") as configfile:
with open(self.config_dir / "config.ini", "w") as configfile:
self.config.write(configfile)