diff --git a/CHANGELOG.md b/CHANGELOG.md index df04f60..7facd8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Added the `Run Stored Program` option to the `--stay-connected` menu. + ([pybricksdev#125]) - Added the `Change Target File` option to the `--stay-connected` menu. ([pybricksdev#123]) [pybricksdev#123]: https://github.com/pybricks/pybricksdev/pull/123 +### Changed +- Changed the default option in the `--stay-connected` menu to be the last + used option. ([pybricksdev#125]) + +[pybricksdev#125]: https://github.com/pybricks/pybricksdev/pull/125 + ## [2.1.1] - 2025-09-13 ### Fixed diff --git a/pybricksdev/cli/__init__.py b/pybricksdev/cli/__init__.py index 0abe13b..d2d08fc 100644 --- a/pybricksdev/cli/__init__.py +++ b/pybricksdev/cli/__init__.py @@ -18,6 +18,7 @@ import argcomplete import questionary from argcomplete.completers import FilesCompleter +from packaging.version import Version from pybricksdev import __name__ as MODULE_NAME from pybricksdev import __version__ as MODULE_VERSION @@ -243,8 +244,9 @@ def is_pybricks_usb(dev): class ResponseOptions(IntEnum): RECOMPILE_RUN = 0 RECOMPILE_DOWNLOAD = 1 - CHANGE_TARGET_FILE = 2 - EXIT = 3 + RUN_STORED = 2 + CHANGE_TARGET_FILE = 3 + EXIT = 4 async def reconnect_hub(): if not await questionary.confirm( @@ -271,9 +273,19 @@ async def reconnect_hub(): response_options = [ "Recompile and Run", "Recompile and Download", + "Run Stored Program", "Change Target File", "Exit", ] + # the entry that is selected by default when the menu opens + # this is overridden after the user picks an option + # so that the default option is always the one that was last chosen + default_response_option = ( + ResponseOptions.RECOMPILE_RUN + if args.start + else ResponseOptions.RECOMPILE_DOWNLOAD + ) + while True: try: if args.file is sys.stdin: @@ -290,17 +302,13 @@ async def reconnect_hub(): questionary.select( f"Would you like to re-compile {os.path.basename(args.file.name)}?", response_options, - default=( - response_options[ResponseOptions.RECOMPILE_RUN] - if args.start - else response_options[ - ResponseOptions.RECOMPILE_DOWNLOAD - ] - ), + default=(response_options[default_response_option]), ).ask_async() ) ) + default_response_option = response_options.index(response) + match response_options.index(response): case ResponseOptions.RECOMPILE_RUN: @@ -311,6 +319,15 @@ async def reconnect_hub(): with _get_script_path(args.file) as script_path: await hub.download(script_path) + case ResponseOptions.RUN_STORED: + if hub.fw_version < Version("3.2.0-beta.4"): + print( + "Running a stored program remotely is only supported in the hub firmware version >= v3.2.0." + ) + else: + await hub.start_user_program() + await hub._wait_for_user_program_stop() + case ResponseOptions.CHANGE_TARGET_FILE: args.file.close() while True: