feat: refine menu lifecycle handling and make bottom bar optional

- Allow `bottom_bar` to be `None` in `Falyx` initialization and validation logic.
- Updated error messaging to reflect `None` as a valid bottom bar state.
- Set `FalyxMode.MENU` explicitly when entering interactive menu mode.
- Simplified `menu()` loop by removing unnecessary `asyncio.create_task` wrapping.
- Added `always_start_menu` flag to `run()` to allow returning to the menu after CLI execution.
- Prevent forced `sys.exit()` when `always_start_menu=True` is provided.
- Bumped version to 0.1.86
This commit is contained in:
2025-11-23 19:05:03 -05:00
parent 1ce1b2385b
commit 79f7bd6a60
3 changed files with 11 additions and 11 deletions

View File

@@ -174,7 +174,7 @@ class Falyx:
self.hooks: HookManager = HookManager() self.hooks: HookManager = HookManager()
self.last_run_command: Command | None = None self.last_run_command: Command | None = None
self.key_bindings: KeyBindings = key_bindings or KeyBindings() self.key_bindings: KeyBindings = key_bindings or KeyBindings()
self.bottom_bar: BottomBar | str | Callable[[], None] = bottom_bar self.bottom_bar: BottomBar | str | Callable[[], None] | None = bottom_bar
self._never_prompt: bool = never_prompt self._never_prompt: bool = never_prompt
self._force_confirm: bool = force_confirm self._force_confirm: bool = force_confirm
self.cli_args: Namespace | None = cli_args self.cli_args: Namespace | None = cli_args
@@ -606,7 +606,7 @@ class Falyx:
self._bottom_bar = bottom_bar self._bottom_bar = bottom_bar
else: else:
raise FalyxError( raise FalyxError(
"Bottom bar must be a string, callable, or BottomBar instance." "Bottom bar must be a string, callable, None, or BottomBar instance."
) )
self._invalidate_prompt_session_cache() self._invalidate_prompt_session_cache()
@@ -618,8 +618,6 @@ class Falyx:
return self.bottom_bar return self.bottom_bar
elif isinstance(self.bottom_bar, str): elif isinstance(self.bottom_bar, str):
return self.bottom_bar return self.bottom_bar
elif self.bottom_bar is None:
return None
return None return None
@cached_property @cached_property
@@ -1197,6 +1195,7 @@ class Falyx:
async def menu(self) -> None: async def menu(self) -> None:
"""Runs the menu and handles user input.""" """Runs the menu and handles user input."""
logger.info("Starting menu: %s", self.get_title()) logger.info("Starting menu: %s", self.get_title())
self.options.set("mode", FalyxMode.MENU)
self.debug_hooks() self.debug_hooks()
if self.welcome_message: if self.welcome_message:
self.print_message(self.welcome_message) self.print_message(self.welcome_message)
@@ -1208,8 +1207,7 @@ class Falyx:
else: else:
self.console.print(self.table, justify="center") self.console.print(self.table, justify="center")
try: try:
task = asyncio.create_task(self.process_command()) should_continue = await self.process_command()
should_continue = await task
if not should_continue: if not should_continue:
break break
except (EOFError, KeyboardInterrupt): except (EOFError, KeyboardInterrupt):
@@ -1233,6 +1231,7 @@ class Falyx:
root_parser: ArgumentParser | None = None, root_parser: ArgumentParser | None = None,
subparsers: _SubParsersAction | None = None, subparsers: _SubParsersAction | None = None,
callback: Callable[..., Any] | None = None, callback: Callable[..., Any] | None = None,
always_start_menu: bool = False,
) -> None: ) -> None:
""" """
Entrypoint for executing a Falyx CLI application via structured subcommands. Entrypoint for executing a Falyx CLI application via structured subcommands.
@@ -1391,7 +1390,8 @@ class Falyx:
if self.cli_args.summary: if self.cli_args.summary:
er.summary() er.summary()
sys.exit(0) if not always_start_menu:
sys.exit(0)
if self.cli_args.command == "run-all": if self.cli_args.command == "run-all":
self.options.set("mode", FalyxMode.RUN_ALL) self.options.set("mode", FalyxMode.RUN_ALL)
@@ -1444,7 +1444,7 @@ class Falyx:
if self.cli_args.summary: if self.cli_args.summary:
er.summary() er.summary()
if not always_start_menu:
sys.exit(0) sys.exit(0)
await self.menu() await self.menu()

View File

@@ -1 +1 @@
__version__ = "0.1.85" __version__ = "0.1.86"

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "falyx" name = "falyx"
version = "0.1.85" version = "0.1.86"
description = "Reliable and introspectable async CLI action framework." description = "Reliable and introspectable async CLI action framework."
authors = ["Roland Thomas Jr <roland@rtj.dev>"] authors = ["Roland Thomas Jr <roland@rtj.dev>"]
license = "MIT" license = "MIT"