From 9b32c417e910562d8cce275dd81c469bb2759971 Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Wed, 4 Feb 2026 19:47:16 +1100 Subject: [PATCH] switched from tabs to spaces lmao --- screens/repo_view_screen.py | 11 +++ screens/search_screen.py | 176 ++++++++++++++++++------------------ screens/welcome_screen.py | 66 +++++++------- widgets/navbar.py | 32 +++---- 4 files changed, 148 insertions(+), 137 deletions(-) create mode 100644 screens/repo_view_screen.py diff --git a/screens/repo_view_screen.py b/screens/repo_view_screen.py new file mode 100644 index 0000000..7fb2578 --- /dev/null +++ b/screens/repo_view_screen.py @@ -0,0 +1,11 @@ +from textual.screen import Screen +from textual.app import ComposeResult +from widgets import Navbar + + +class RepoViewScreen(Screen): + def __init__(self, repo_id: int): + super().__init__(self) + + def compose(self) -> ComposeResult: + yield Navbar() \ No newline at end of file diff --git a/screens/search_screen.py b/screens/search_screen.py index c9458d3..5e83cd9 100644 --- a/screens/search_screen.py +++ b/screens/search_screen.py @@ -11,104 +11,104 @@ import requests class SearchResult(HorizontalGroup): - DEFAULT_CSS = """ - SearchResult { - padding: 0 1; - margin: 0 1; - margin-top: 1; - border: tall $surface; + DEFAULT_CSS = """ + SearchResult { + padding: 0 1; + margin: 0 1; + margin-top: 1; + border: tall $surface; - Static { - width: auto; - link-style: bold; - link-color: $primary; - } - } - """ - - def __init__( - self, - repo_data: dict - ): - super().__init__() - self.repo_data = repo_data - self.author = repo_data["owner"] - self.repo_name = repo_data["name"] - self.description = repo_data["description"] - self.is_fork = repo_data["fork"] - self.updated_at = datetime.fromisoformat(repo_data["updated_at"]).replace(tzinfo=None) - - def compose(self) -> ComposeResult: - updated_string = time_delta(datetime.now() - self.updated_at) - yield Static(f"[@click='view_user({self.author["id"]})']{self.author["login"]}[/] / [@click=view_repo('')]{self.repo_name}[/]{' [d]\[[cyan]fork[/]]' if self.is_fork else ''}\n{self.description}\n[d]Updated {updated_string} ago") + Static { + width: auto; + link-style: bold; + link-color: $primary; + } + } + """ + + def __init__( + self, + repo_data: dict + ): + super().__init__() + self.repo_data = repo_data + self.author = repo_data["owner"] + self.repo_name = repo_data["name"] + self.description = repo_data["description"] + self.is_fork = repo_data["fork"] + self.updated_at = datetime.fromisoformat(repo_data["updated_at"]).replace(tzinfo=None) + + def compose(self) -> ComposeResult: + updated_string = time_delta(datetime.now() - self.updated_at) + yield Static(f"[@click='view_user({self.author["id"]})']{self.author["login"]}[/] / [@click=view_repo('')]{self.repo_name}[/]{' [d]\[[cyan]fork[/]]' if self.is_fork else ''}\n{self.description}\n[d]Updated {updated_string} ago") class SearchScreen(Screen): - DEFAULT_CSS = """ - #search-box { - padding: 1; - padding-bottom: 0; - border-bottom: hkey $surface; + DEFAULT_CSS = """ + #search-box { + padding: 1; + padding-bottom: 0; + border-bottom: hkey $surface; - #query { - width: 1fr; - } + #query { + width: 1fr; + } - #search-select { - width: 25; - } - } - """ + #search-select { + width: 25; + } + } + """ - def action_search_query(self): - query_input = self.query_one("#query") - loading = self.query_one(LoadingIndicator) - results = self.query_one(ScrollableContainer) + def action_search_query(self): + query_input = self.query_one("#query") + loading = self.query_one(LoadingIndicator) + results = self.query_one(ScrollableContainer) - loading.display = True - - # send off a request - response = requests.get( - url=self.app.GITEA_HOST + "api/v1/repos/search", - params={ - "q": query_input.value, - "limit": 20 - } - ) + loading.display = True + + # send off a request + response = requests.get( + url=self.app.GITEA_HOST + "api/v1/repos/search", + params={ + "q": query_input.value, + "limit": 20 + } + ) - loading.display = False + loading.display = False - # error handling - if not response.ok: - self.notify(response.text, title="Error while getting search results:", severity="error") - return + # error handling + if not response.ok: + self.notify(response.text, title="Error while getting search results:", severity="error") + return - # display results - results.remove_children(SearchResult) - to_mount = [] - print(response.json()) - for result in response.json()["data"]: - to_mount.append(SearchResult(result)) - results.mount_all(to_mount) + # display results + results.remove_children(SearchResult) + to_mount = [] + print(response.json()) + for result in response.json()["data"]: + to_mount.append(SearchResult(result)) + results.mount_all(to_mount) - # self explanitory - query_input.clear() + # self explanitory + query_input.clear() - def on_input_submitted(self, event: Input.Submitted): - if event.input.id == "query": - self.action_search_query() - - def on_mount(self): - self.action_search_query() - #self.query_one(LoadingIndicator).display = False + def on_input_submitted(self, event: Input.Submitted): + if event.input.id == "query": + self.action_search_query() + + def on_mount(self): + self.action_search_query() + #self.query_one(LoadingIndicator).display = False - def compose(self) -> ComposeResult: - yield Navbar() - - with HorizontalGroup(id="search-box"): - yield Input(placeholder="Search repos...", id="query") - yield Select.from_values([ - "Repositories", - ], id="search-select", allow_blank=False) - - with ScrollableContainer(id="results"): - yield LoadingIndicator() \ No newline at end of file + def compose(self) -> ComposeResult: + yield Navbar() + + with HorizontalGroup(id="search-box"): + yield Input(placeholder="Search repos...", id="query") + yield Select.from_values([ + "Repositories", + ], id="search-select", allow_blank=False) + + with ScrollableContainer(id="results"): + yield LoadingIndicator() \ No newline at end of file diff --git a/screens/welcome_screen.py b/screens/welcome_screen.py index 72bf369..7e5cc26 100644 --- a/screens/welcome_screen.py +++ b/screens/welcome_screen.py @@ -10,38 +10,38 @@ from random import choice class WelcomeScreen(Screen): - DEFAULT_CSS = """ - Center { - padding: 2; - width: 100%; - - Static { - text-align: center; - } - - EffectLabel { - text-style: bold; - min-width: 100%; - } - - #buttons { - margin-top: 1; - align: center middle; - Button { - margin: 0 2; - } - } - } - """ + DEFAULT_CSS = """ + Center { + padding: 2; + width: 100%; + + Static { + text-align: center; + } + + EffectLabel { + text-style: bold; + min-width: 100%; + } - def compose(self) -> ComposeResult: - yield Navbar() - with Center(): - with open("banner.txt", "r") as f: - yield EffectLabel(text=f.read(), effect=choice(list(effects.keys()))) - - yield Static("[d]Gitea, in your terminal.[/]") + #buttons { + margin-top: 1; + align: center middle; + Button { + margin: 0 2; + } + } + } + """ - with HorizontalGroup(id="buttons"): - yield Button("Explore", variant="primary", flat=True) - yield Button("another button lol", flat=True) \ No newline at end of file + def compose(self) -> ComposeResult: + yield Navbar() + with Center(): + with open("banner.txt", "r") as f: + yield EffectLabel(text=f.read(), effect=choice(list(effects.keys()))) + + yield Static("[d]Gitea, in your terminal.[/]") + + with HorizontalGroup(id="buttons"): + yield Button("Explore", variant="primary", flat=True) + yield Button("another button lol", flat=True) \ No newline at end of file diff --git a/widgets/navbar.py b/widgets/navbar.py index 23d4426..af4da18 100644 --- a/widgets/navbar.py +++ b/widgets/navbar.py @@ -3,19 +3,19 @@ from textual.containers import HorizontalGroup class Navbar(HorizontalGroup): - DEFAULT_CSS = """ - Navbar { - background: $surface-darken-1; - border-bottom: hkey $surface; - height: 3; - padding: 1; - padding-bottom: 0; - - #hamburger-menu { - max-width: 1; - } - } - """ - - def compose(self): - yield Button("≡", compact=True, id="hamburger-menu") \ No newline at end of file + DEFAULT_CSS = """ + Navbar { + background: $surface-darken-1; + border-bottom: hkey $surface; + height: 3; + padding: 1; + padding-bottom: 0; + + #hamburger-menu { + max-width: 1; + } + } + """ + + def compose(self): + yield Button("≡", compact=True, id="hamburger-menu") \ No newline at end of file