-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_table.py
More file actions
37 lines (28 loc) · 1.15 KB
/
Copy pathhello_table.py
File metadata and controls
37 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from textual.app import App, ComposeResult
from rich.table import Table
from grav import GravityList
class HelloTable(App[None]):
"""The simplest way to use GravityList with a multi-column table."""
def compose(self) -> ComposeResult:
# 1. Drop the widget onto the screen
yield GravityList(placeholder="Search systems...")
def on_mount(self) -> None:
# 2. A basic list of data (e.g., your homelab machines)
systems = [
("Ubuntu Server", "Running"),
("Nobara PC", "Updating"),
("CachyOS", "Stopped"),
]
items = []
for name, status in systems:
# 3. Build a simple, borderless table for each row
table = Table(expand=True, show_header=False, box=None)
table.add_column("System", ratio=2)
table.add_column("Status", ratio=1)
table.add_row(name, status)
# 4. Pair them up: (search key, the table visual)
items.append((name, table))
# 5. Feed it to the widget
self.query_one(GravityList).set_items(items)
if __name__ == "__main__":
HelloTable().run()