From e7de95c0dd3ccd95202908070183a8b96824687e Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 29 Jan 2026 11:34:25 +0000 Subject: [PATCH] Initial commit: Add http-convert project --- src/http_convert/config.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/http_convert/config.py diff --git a/src/http_convert/config.py b/src/http_convert/config.py new file mode 100644 index 0000000..538ddb0 --- /dev/null +++ b/src/http_convert/config.py @@ -0,0 +1,68 @@ +from pathlib import Path +from typing import Optional +import yaml + + +class Config: + DEFAULT_PATH = Path.home() / ".http-convert.yaml" + + def __init__(self, path: Optional[Path] = None): + self.path = path or self.DEFAULT_PATH + self.data = self._load() + + def _load(self) -> dict: + if self.path.exists(): + try: + with open(self.path, 'r') as f: + return yaml.safe_load(f) or {} + except Exception: + return {} + return {} + + def save(self) -> None: + self.path.parent.mkdir(parents=True, exist_ok=True) + with open(self.path, 'w') as f: + yaml.dump(self.data, f) + + def get(self, key: str, default=None): + return self.data.get(key, default) + + def set(self, key: str, value) -> None: + self.data[key] = value + self.save() + + @property + def default_format(self) -> str: + return self.get("default_format", "curl") + + @default_format.setter + def default_format(self, value: str) -> None: + self.set("default_format", value) + + @property + def syntax_highlighting(self) -> bool: + return self.get("syntax_highlighting", True) + + @syntax_highlighting.setter + def syntax_highlighting(self, value: bool) -> None: + self.set("syntax_highlighting", value) + + @property + def compact_output(self) -> bool: + return self.get("compact_output", False) + + @compact_output.setter + def compact_output(self, value: bool) -> None: + self.set("compact_output", value) + + @property + def theme(self) -> str: + return self.get("theme", "monokai") + + @theme.setter + def theme(self, value: str) -> None: + self.set("theme", value) + + def reset(self) -> None: + self.data = {} + self.save()