Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(interactive_shell.py): allow console interaction with device name #357

Open
wants to merge 1 commit into
base: boardfarm3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions boardfarm3/lib/interactive_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def add_option(
self._table.add_row(*column_data)
self._actions[column_data[0]] = (function, args, kwargs)

def _get_device_choice_and_name(self) -> dict[str, str]:
return {
choice: console[1][0].device_name
for choice, console in self._actions.items()
if choice.isdigit()
}

def show_table(self, exit_option: str, exit_option_description: str) -> None:
"""Show table and perform actions based on user input.

Expand All @@ -98,15 +105,25 @@ def show_table(self, exit_option: str, exit_option_description: str) -> None:
"""
self._table.add_row(exit_option, exit_option_description)
rich_print(self._table)
device_names = list(self._get_device_choice_and_name().values())
while (
option := Prompt.ask(
"Enter your choice:",
choices=[*list(self._actions.keys()), exit_option],
"Enter your choice or the device name to interact with:",
choices=[*list(self._actions.keys()), *device_names, exit_option],
)
) != exit_option:
self._actions[option][0](
*self._actions[option][1],
**self._actions[option][2],
if option.isdigit() or (option.isalpha() and len(option) == 1):
action_key = option
else:
action_key = next(
filter(
lambda x: self._get_device_choice_and_name()[x] == option,
self._get_device_choice_and_name(),
)
)

self._actions[action_key][0](
*self._actions[action_key][1], **self._actions[action_key][2]
)
rich_print(self._table)

Expand Down Expand Up @@ -173,7 +190,8 @@ def _get_device_console_options(
(
(
str(index),
f"{device.device_name} ({device.device_type})",
f"{device.device_type}",
f"{device.device_name}",
str(len(device.get_interactive_consoles())),
),
_start_interactive_console,
Expand Down Expand Up @@ -271,7 +289,8 @@ def get_interactive_console_options(
"""
table = OptionsTable("BOARDFARM INTERACTIVE SHELL")
table.add_column("Choice", justify="center", style="cyan")
table.add_column("Description", style="magenta")
table.add_column("Description", justify="center", style="magenta")
table.add_column("Device Name", justify="center")
table.add_column("Consoles", justify="center")
for option in _get_device_console_options(device_manager):
table.add_option(*option)
Expand Down