Interactively select/pick a row in a table? #960
-
Hi! Is it possible to achieve something like this with rich? Or possibly extend rich somehow to achieve it? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 12 replies
-
Not currently, but maybe in the future. In the meantime you could try PyInquirer. |
Beta Was this translation helpful? Give feedback.
-
@willmcgugan Having an interactive prompt would still be very much appreciated. There seem to be many feature requests on this, for example: Other projects with this functionality:
Will this feature come? |
Beta Was this translation helpful? Give feedback.
-
Brewing this thread up again... I wrote a small PoC for an interactive selector app using textual. from textual.app import App
from textual.widget import Widget
from rich.panel import Panel
class Hover(Widget):
def __init__(self, label, *args, **kwargs):
self.label = label
self._is_active = False
super().__init__(*args, **kwargs)
def render(self) -> Panel:
return Panel(self.label, style=("on red" if self.is_active else ""))
@property
def is_active(self) -> None:
return self._is_active
@is_active.setter
def is_active(self, new_state) -> None:
self._is_active = new_state
self.refresh()
class TextualChoiceSelector(App):
def __init__(self, choices, *args, **kwargs):
self.choices = [Hover(choice) for choice in choices]
self.active_choice = 0
self.choices[self.active_choice].is_active = True
super().__init__(*args, **kwargs)
def on_key(self, event):
if event.key in ["down", "up"]:
off = 1 if event.key == "down" else -1
self.choices[self.active_choice].is_active = False
self.active_choice = (self.active_choice + off) % len(self.choices)
self.choices[self.active_choice].is_active = True
if event.key == "enter":
pass #...
async def on_mount(self) -> None:
await self.view.dock(*self.choices, edge="top")
TextualChoiceSelector.run(choices=["Select A", "Select B", "Select C", "Select D", "Select E"]) |
Beta Was this translation helpful? Give feedback.
-
@willmcgugan it is the future. I'd like to add my voice to those who would like |
Beta Was this translation helpful? Give feedback.
-
@daniel-shimon @Spenhouet @dsm-72 @ppmx I've started working on a rich_interactive package , which extends I started just a few days ago, so this is very early stage, but if anyone would be interested in such a package, I would appreciate a feedback/ideas/requests. My personal goal, is to prepare a good quality package, which would enable easy navigation with keyboard, like this: (Disclaimer: gif with animated part is in PoC stage, and it is not production ready yet) |
Beta Was this translation helpful? Give feedback.
-
I've a created a small library minifzf, a while ago, It might be useful. It also has fuzzy search capability. Use |
Beta Was this translation helpful? Give feedback.
Not currently, but maybe in the future. In the meantime you could try PyInquirer.