style: color dashboard sections

This commit is contained in:
2026-07-27 03:48:07 +08:00
parent 42b2e63a97
commit 082c8f22fe
4 changed files with 25 additions and 13 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "shusub2" name = "shusub2"
version = "0.2.6" version = "0.2.7"
description = "Terminal UI for Sub2API account quota and daily usage" description = "Terminal UI for Sub2API account quota and daily usage"
readme = "README.md" readme = "README.md"
requires-python = ">=3.11" requires-python = ">=3.11"
+20 -9
View File
@@ -19,7 +19,7 @@ from typing import Any
APP_NAME = "shusub2" APP_NAME = "shusub2"
FALLBACK_VERSION = "0.2.6" FALLBACK_VERSION = "0.2.7"
DEFAULT_API_URL = "http://127.0.0.1:18318/api/tui/accounts" DEFAULT_API_URL = "http://127.0.0.1:18318/api/tui/accounts"
DEFAULT_CONFIG_FILE = "~/.config/shusub2/api-url" DEFAULT_CONFIG_FILE = "~/.config/shusub2/api-url"
DEFAULT_STATUS_CONFIG_FILE = "~/.config/shusub2/status-url" DEFAULT_STATUS_CONFIG_FILE = "~/.config/shusub2/status-url"
@@ -1491,13 +1491,17 @@ def run_textual(
if self.key_rows: if self.key_rows:
top_key = self.key_rows[0] top_key = self.key_rows[0]
key_summary = f"keys {top_key['name']} {format_cost(top_key['cost'])}" key_summary = f"keys {top_key['name']} {format_cost(top_key['cost'])}"
summary = ( summary = Text()
f"accounts {len(self.account_rows)}/{account_total} ({usable} usable, " summary.append(
f"{format_cost(totals.get('today_cost_usd'))}) | " f"accounts {len(self.account_rows)}/{account_total} ({usable} usable, {format_cost(totals.get('today_cost_usd'))})",
f"keys {len(self.key_rows)} ({key_summary.removeprefix('keys ')}) | " style="green",
f"logs {len(self.log_rows)}/{logs_total} | "
f"errors {len(self.error_rows)}/{self.errors_total()}"
) )
summary.append(" | ", style="dim")
summary.append(f"keys {len(self.key_rows)} ({key_summary.removeprefix('keys ')})", style="yellow")
summary.append(" | ", style="dim")
summary.append(f"logs {len(self.log_rows)}/{logs_total}", style="magenta")
summary.append(" | ", style="dim")
summary.append(f"errors {len(self.error_rows)}/{self.errors_total()}", style="red")
self.query_one("#summary", Static).update(summary) self.query_one("#summary", Static).update(summary)
status_bits = [version_message] status_bits = [version_message]
@@ -1958,14 +1962,21 @@ def run_textual(
class Sub2APIQuotaApp(App[None]): class Sub2APIQuotaApp(App[None]):
CSS = """ CSS = """
#summary { height: 1; padding: 0 1; color: $accent; } #summary { height: 1; padding: 0 1; color: $foreground; }
#filter { height: 1; border: none; padding: 0 1; } #filter { height: 1; border: none; padding: 0 1; }
#filter:focus { border: none; } #filter:focus { border: none; }
#accounts { height: 1fr; min-height: 3; } #accounts { height: 1fr; min-height: 3; }
#keys { height: auto; max-height: 6; } #keys { height: auto; max-height: 6; }
.dashboard #keys { height: 1fr; min-height: 0; max-height: 100%; } .dashboard #accounts { background: $success 5%; }
.dashboard #accounts > .datatable--header { background: $success 35%; color: $foreground; }
.dashboard #keys { height: 1fr; min-height: 0; max-height: 100%; background: $warning 5%; }
.dashboard #keys > .datatable--header { background: $warning 35%; color: $foreground; }
#logs { height: 1fr; min-height: 3; } #logs { height: 1fr; min-height: 3; }
.dashboard #logs { background: $secondary 5%; }
.dashboard #logs > .datatable--header { background: $secondary 35%; color: $foreground; }
#errors { height: 1fr; min-height: 3; } #errors { height: 1fr; min-height: 3; }
.dashboard #errors { background: $error 5%; }
.dashboard #errors > .datatable--header { background: $error 35%; color: $foreground; }
#detail { height: 2; padding: 0 1; background: $surface-lighten-1; } #detail { height: 2; padding: 0 1; background: $surface-lighten-1; }
#status { height: 1; padding: 0 1; color: $text-muted; } #status { height: 1; padding: 0 1; color: $text-muted; }
""" """
+3 -2
View File
@@ -755,10 +755,11 @@ class DashboardLayoutTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(type(screen).__name__, "DashboardScreen") self.assertEqual(type(screen).__name__, "DashboardScreen")
self.assertEqual(screen.query_one("#filter").region.height, 1) self.assertEqual(screen.query_one("#filter").region.height, 1)
self.assertEqual(screen.query_one("#detail").region.height, 2) self.assertEqual(screen.query_one("#detail").region.height, 2)
for selector in ("#accounts", "#keys", "#logs", "#errors"): tables = [screen.query_one(selector) for selector in ("#accounts", "#keys", "#logs", "#errors")]
table = screen.query_one(selector) for table in tables:
self.assertGreaterEqual(table.region.height, 4) self.assertGreaterEqual(table.region.height, 4)
self.assertLessEqual(table.virtual_size.width, table.region.width) self.assertLessEqual(table.virtual_size.width, table.region.width)
self.assertEqual(len({table.styles.background for table in tables}), 4)
self.assertIn("wmy", str(screen.query_one("#summary").render())) self.assertIn("wmy", str(screen.query_one("#summary").render()))
for key, expected_id in (("k", "keys"), ("l", "logs"), ("e", "errors"), ("a", "accounts")): for key, expected_id in (("k", "keys"), ("l", "logs"), ("e", "errors"), ("a", "accounts")):
await pilot.press(key) await pilot.press(key)
Generated
+1 -1
View File
@@ -85,7 +85,7 @@ wheels = [
[[package]] [[package]]
name = "shusub2" name = "shusub2"
version = "0.2.6" version = "0.2.7"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "textual" }, { name = "textual" },