the highlight kind of works
This commit is contained in:
parent
c57d1a9b82
commit
99e7c206af
1 changed files with 42 additions and 12 deletions
|
|
@ -60,7 +60,7 @@ class TuiCommand(SupportsCliCommand):
|
||||||
|
|
||||||
#main-container {
|
#main-container {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
border: thick $primary;
|
border: solid $primary;
|
||||||
background: $surface;
|
background: $surface;
|
||||||
padding: 1;
|
padding: 1;
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +79,12 @@ class TuiCommand(SupportsCliCommand):
|
||||||
border: solid $accent;
|
border: solid $accent;
|
||||||
margin-bottom: 2;
|
margin-bottom: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListView > ListItem {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
height: auto;
|
height: auto;
|
||||||
|
|
@ -92,19 +98,16 @@ class TuiCommand(SupportsCliCommand):
|
||||||
color: $text;
|
color: $text;
|
||||||
padding: 0 1;
|
padding: 0 1;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListItem:hover {
|
ListItem.highlighted {
|
||||||
background: $surface;
|
background: $primary-darken-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListItem.--highlight {
|
|
||||||
background: $primary;
|
|
||||||
color: $text;
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandItem {
|
CommandItem {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#footer-info {
|
#footer-info {
|
||||||
|
|
@ -121,8 +124,15 @@ class TuiCommand(SupportsCliCommand):
|
||||||
Binding("q", "quit", "Quit", priority=True),
|
Binding("q", "quit", "Quit", priority=True),
|
||||||
Binding("escape", "quit", "Quit", priority=True),
|
Binding("escape", "quit", "Quit", priority=True),
|
||||||
Binding("enter", "select", "Select", priority=True),
|
Binding("enter", "select", "Select", priority=True),
|
||||||
|
Binding("up", "nav_up", "Up", priority=True),
|
||||||
|
Binding("down", "nav_down", "Down", priority=True),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.lv = None
|
||||||
|
self.current_index = 0
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
version = get_cognee_version()
|
version = get_cognee_version()
|
||||||
yield Static(f"🧠 cognee v{version}", id="header")
|
yield Static(f"🧠 cognee v{version}", id="header")
|
||||||
|
|
@ -145,10 +155,30 @@ class TuiCommand(SupportsCliCommand):
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
"""Focus the list view on mount."""
|
"""Focus the list view on mount."""
|
||||||
self.query_one(ListView).index = 0
|
self.lv = self.query_one(ListView)
|
||||||
|
self.current_index = 0
|
||||||
|
self.set_focus(self.lv)
|
||||||
|
self._apply_highlight()
|
||||||
|
|
||||||
|
def _apply_highlight(self) -> None:
|
||||||
|
lv = self.lv
|
||||||
|
children = list(lv.children)
|
||||||
|
for idx, item in enumerate(children):
|
||||||
|
if idx == self.current_index:
|
||||||
|
item.add_class("highlighted")
|
||||||
|
else:
|
||||||
|
item.remove_class("highlighted")
|
||||||
|
|
||||||
|
def action_nav_up(self) -> None:
|
||||||
|
self.current_index = max(0, self.current_index - 1)
|
||||||
|
self._apply_highlight()
|
||||||
|
|
||||||
|
def action_nav_down(self) -> None:
|
||||||
|
children = list(self.lv.children)
|
||||||
|
self.current_index = min(len(children) - 1, self.current_index + 1)
|
||||||
|
self._apply_highlight()
|
||||||
|
|
||||||
def on_list_view_selected(self, event: ListView.Selected) -> None:
|
def on_list_view_selected(self, event: ListView.Selected) -> None:
|
||||||
"""Handle command selection."""
|
|
||||||
command_item = event.item.query_one(CommandItem)
|
command_item = event.item.query_one(CommandItem)
|
||||||
command = command_item.command
|
command = command_item.command
|
||||||
fmt.echo(f"Selected command: {command}")
|
fmt.echo(f"Selected command: {command}")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue