diff --git a/README.md b/README2.md similarity index 100% rename from README.md rename to README2.md diff --git a/assets/repo_view_screen.tcss b/assets/repo_view_screen.tcss index 8f1b8a2..5753f08 100644 --- a/assets/repo_view_screen.tcss +++ b/assets/repo_view_screen.tcss @@ -6,12 +6,13 @@ content-align: left middle; width: auto; } + + #buttons { layout: horizontal; Button { margin-left: 1; - max-width: 13; } } @@ -56,6 +57,10 @@ Static { width: 1fr; text-align: center; + link-style: bold; + link-style-hover: underline bold; + link-background-hover: transparent; + pointer: pointer; } } @@ -79,4 +84,9 @@ LoadingIndicator { height: 1; +} + +#readme { + border: panel $surface; + margin: 1 0 0 1; } \ No newline at end of file diff --git a/screens/repo_view_screen.py b/screens/repo_view_screen.py index c3e9102..a9a81f4 100644 --- a/screens/repo_view_screen.py +++ b/screens/repo_view_screen.py @@ -1,6 +1,6 @@ from textual.screen import Screen from textual.app import ComposeResult -from textual.widgets import Input, Select, LoadingIndicator, Static, DataTable, ContentSwitcher, Tabs, Tab, Button +from textual.widgets import Input, Select, LoadingIndicator, Static, DataTable, ContentSwitcher, Tabs, Tab, Button, Markdown from textual.containers import VerticalGroup, Vertical, HorizontalGroup, Right from textual import work @@ -9,7 +9,7 @@ from widgets import Navbar from datetime import datetime from human_readable import time_delta -import requests +import requests, asyncio class RepoViewScreen(Screen): @@ -114,7 +114,7 @@ class RepoViewScreen(Screen): most_recent_commit = commits_response.json()[0] files.add_columns( - f"[b]{most_recent_commit["author"]["login"]}[/]", + f"[b]{most_recent_commit["commit"]["author"]["name"]}[/]", f"[r]{most_recent_commit["sha"][:10]}[/]", f"[d]{most_recent_commit["commit"]["message"]}" ) @@ -126,6 +126,7 @@ class RepoViewScreen(Screen): page_size = 50 commit_data = {} + # loop over all the root commits until we get em' all while True: commits = requests.get( self.app.GITEA_HOST + f"api/v1/repos/{self.owner_name}/{self.repo_name}/commits", @@ -146,6 +147,9 @@ class RepoViewScreen(Screen): else: break + found_readme = False + readme: Markdown = self.query_one("#readme") + for file in files_response.json(): commit = commit_data[file["last_commit_sha"]] @@ -156,8 +160,21 @@ class RepoViewScreen(Screen): f"[d]{commit["commit"]["message"]}", f"[d]Updated {time_delta(datetime.now() - commit_created_at)} ago" )) + + if file["name"].lower() == "readme.md": + found_readme = True + readme.border_title = file["name"] + + readme_content = requests.get( + self.app.GITEA_HOST + f"api/v1/repos/{self.owner_name}/{self.repo_name}/raw/{file["name"]}" + ).text + self.app.call_from_thread(readme.update, readme_content or "Empty README") + files.add_rows(rows) + if not found_readme: + readme.update("This repository has no `README.md` file.") + loading.display = False files.display = True @@ -180,8 +197,9 @@ class RepoViewScreen(Screen): with HorizontalGroup(): yield Static(f" {self.owner_name}/[b]{self.repo_name}[/]", id="title") with Right(id="buttons"): - yield Button("Star [d](0)", variant="warning", flat=True) - yield Button("Watch [d](0)", flat=True) + yield Button(f"\uf005 Star [d]({data["stars_count"]})", variant="warning", flat=True) + yield Button(f"\uf418 Fork [d]({data["forks_count"]})", variant="primary", flat=True) + yield Button(f"\uea70 Watch [d]({data["watchers_count"]})", flat=True) yield Tabs( "\uf44f Code", "\uebf8 Issues", @@ -198,9 +216,9 @@ class RepoViewScreen(Screen): with HorizontalGroup(id="Code"): with VerticalGroup(id="commits"): with HorizontalGroup(id="branch-info"): - yield Static("\uf4b6 1 Commits") - yield Static("\uf418 1 Branch") - yield Static("\uf02b 0 Tags") + yield Static(f"[@click='']\uf4b6 1 Commits[/]") + yield Static(f"[@click='']\uf418 1 Branch[/]") + yield Static(f"[@click='']\uf02b 0 Tags[/]") with HorizontalGroup(id="branch-options"): yield Select.from_values([ @@ -215,9 +233,13 @@ class RepoViewScreen(Screen): yield table yield LoadingIndicator() + + readme = Markdown(markdown="Loading...", id="readme") + readme.border_title = "\uf405 README.md" + yield readme with Vertical(id="repo-info"): with HorizontalGroup(): - yield Input("Search code...", id="search-query") + yield Input(placeholder="Search code...", id="search-query") yield Button("\uf002", flat=True, id="search-btn") yield Static("\n[b] Description") yield Static("[d]" + data["description"], id="description") \ No newline at end of file diff --git a/screens/search_screen.py b/screens/search_screen.py index 7ed16b4..431fe89 100644 --- a/screens/search_screen.py +++ b/screens/search_screen.py @@ -58,7 +58,7 @@ class SearchScreen(Screen): width: 1fr; } - #search-select { + Select { width: 25; } } @@ -100,6 +100,7 @@ class SearchScreen(Screen): # self explanitory query_input.clear() + query_input.focus() def on_input_submitted(self, event: Input.Submitted): if event.input.id == "query": @@ -114,9 +115,21 @@ class SearchScreen(Screen): with HorizontalGroup(id="search-box"): yield Input(placeholder="Search repos...", id="query") + yield Select.from_values([ + "Alphabetical", + "Creation date", + "Last updated", + "Size", + "ID" + ], id="sort-select", allow_blank=False, value="Last updated") + yield Select.from_values([ + "Ascending", + "Descending" + ], id="order-select", allow_blank=False, value="Ascending") yield Select.from_values([ "Repositories", - ], id="search-select", allow_blank=False) + "Users", + ], id="search-select", allow_blank=False, value="Repositories") with ScrollableContainer(id="results"): yield LoadingIndicator() \ No newline at end of file