Prompt user to select an editor when required version not installed. Args: required_version: The version required by the project. editors: List of installed editors to choose from. Returns: Selected InstalledEditor, or None if user chose to quit. Also return
(
required_version: str,
editors: list[InstalledEditor],
)
| 25 | |
| 26 | |
| 27 | def prompt_editor_selection( |
| 28 | required_version: str, |
| 29 | editors: list[InstalledEditor], |
| 30 | ) -> InstalledEditor | None: |
| 31 | """Prompt user to select an editor when required version not installed. |
| 32 | |
| 33 | Args: |
| 34 | required_version: The version required by the project. |
| 35 | editors: List of installed editors to choose from. |
| 36 | |
| 37 | Returns: |
| 38 | Selected InstalledEditor, or None if user chose to quit. |
| 39 | Also returns None if not in TTY or InquirerPy not available. |
| 40 | """ |
| 41 | if not is_tty(): |
| 42 | return None |
| 43 | |
| 44 | if not _has_inquirerpy(): |
| 45 | return None |
| 46 | |
| 47 | from InquirerPy import inquirer |
| 48 | from InquirerPy.base.control import Choice |
| 49 | |
| 50 | choices: list[Choice] = [ |
| 51 | Choice(value=None, name="Quit"), |
| 52 | ] |
| 53 | |
| 54 | for editor in editors: |
| 55 | choices.append(Choice(value=editor, name=f"Use {editor.version}")) |
| 56 | |
| 57 | selected: InstalledEditor | None = inquirer.select( |
| 58 | message=f"Unity {required_version} not installed. Choose an action:", |
| 59 | choices=choices, |
| 60 | default=None, |
| 61 | ).execute() |
| 62 | |
| 63 | return selected |
| 64 | |
| 65 | |
| 66 | def prompt_confirm(message: str, default: bool = False) -> bool: |
no test coverage detected