Skip to content

Commit 420cda2

Browse files
committed
multiple providers
1 parent a173d1b commit 420cda2

File tree

2 files changed

+66
-20
lines changed

2 files changed

+66
-20
lines changed

src/gitfetch/cli.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import sys
77
from typing import Optional
88

9+
import readchar
10+
911
from .display import DisplayFormatter
1012
from .cache import CacheManager
1113
from .config import ConfigManager
@@ -15,7 +17,7 @@
1517
def parse_args() -> argparse.Namespace:
1618
"""Parse command-line arguments."""
1719
parser = argparse.ArgumentParser(
18-
description="A neofetch-style CLI tool for GitHub statistics",
20+
description="A neofetch-style CLI tool for git provider statistics",
1921
formatter_class=argparse.RawDescriptionHelpFormatter
2022
)
2123

@@ -203,26 +205,42 @@ def _prompt_username() -> Optional[str]:
203205

204206

205207
def _prompt_provider() -> Optional[str]:
206-
"""Prompt user for git provider."""
207-
try:
208-
print("Available git providers:")
209-
print("1. GitHub")
210-
print("2. GitLab")
211-
print("3. Gitea/Forgejo/Codeberg")
212-
print("4. Sourcehut")
208+
"""Prompt user for git provider with interactive selection."""
209+
providers = [
210+
('github', 'GitHub'),
211+
('gitlab', 'GitLab'),
212+
('gitea', 'Gitea/Forgejo/Codeberg'),
213+
('sourcehut', 'Sourcehut')
214+
]
215+
216+
selected = 0
213217

218+
try:
214219
while True:
215-
choice = input("Choose your git provider (1-4): ").strip()
216-
if choice == '1':
217-
return 'github'
218-
elif choice == '2':
219-
return 'gitlab'
220-
elif choice == '3':
221-
return 'gitea'
222-
elif choice == '4':
223-
return 'sourcehut'
224-
else:
225-
print("Invalid choice. Please enter 1-4.")
220+
# Clear screen and print header
221+
print("\033[2J\033[H", end="")
222+
print("Choose your git provider:")
223+
print()
224+
225+
# Print options with cursor
226+
for i, (key, name) in enumerate(providers):
227+
indicator = "●" if i == selected else "○"
228+
print(f"{indicator} {name}")
229+
230+
print()
231+
print("Use ↑/↓ arrows, ● = selected, Enter to confirm")
232+
233+
# Read key
234+
key = readchar.readkey()
235+
236+
if key == readchar.key.UP:
237+
selected = (selected - 1) % len(providers)
238+
elif key == readchar.key.DOWN:
239+
selected = (selected + 1) % len(providers)
240+
elif key == readchar.key.ENTER:
241+
print() # New line after selection
242+
return providers[selected][0]
243+
226244
except (KeyboardInterrupt, EOFError):
227245
print()
228246
return None

src/gitfetch/config.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,34 @@ def set_provider_url(self, url: str) -> None:
176176

177177
def save(self) -> None:
178178
"""Save configuration to file."""
179+
import os
179180
self._ensure_config_dir()
181+
# Remove the file if it exists to ensure clean write
182+
if self.CONFIG_FILE.exists():
183+
os.remove(self.CONFIG_FILE)
180184
with open(self.CONFIG_FILE, 'w') as f:
181-
self.config.write(f)
185+
f.write("# gitfetch configuration file\n")
186+
f.write("# See docs/providers.md for provider configuration\n")
187+
f.write("# See docs/colors.md for color customization\n\n")
188+
189+
f.write("[DEFAULT]\n")
190+
username = self.config.get('DEFAULT', 'username', fallback='')
191+
f.write(f"username = {username}\n\n")
192+
193+
cache_hours = self.config.get('DEFAULT', 'cache_expiry_hours',
194+
fallback='24')
195+
f.write(f"cache_expiry_hours = {cache_hours}\n\n")
196+
197+
provider = self.config.get('DEFAULT', 'provider', fallback='')
198+
f.write(f"provider = {provider}\n\n")
199+
200+
provider_url = self.config.get('DEFAULT', 'provider_url',
201+
fallback='')
202+
f.write(f"provider_url = {provider_url}\n\n")
203+
204+
if 'COLORS' in self.config:
205+
f.write("[COLORS]\n")
206+
for key, value in self.config['COLORS'].items():
207+
f.write(f"{key} = {value}\n")
208+
f.write("\n")
209+
f.write("\n")

0 commit comments

Comments
 (0)