* Renders a select prompt to the console. * @param param.message string * @param param.choices any[] * @returns
({ message, choices, onCancel })
| 841 | * @returns |
| 842 | */ |
| 843 | async choose({ message, choices, onCancel }) { |
| 844 | // Stop the spinner to not collide with prompt |
| 845 | renderer.spinner.stop() |
| 846 | |
| 847 | const enquirer = new Enquirer() |
| 848 | |
| 849 | // Mapping names to values for result processing |
| 850 | const nameToValueMap = choices.reduce((map, choice) => { |
| 851 | map[choice.name] = choice.value |
| 852 | return map |
| 853 | }, {}) |
| 854 | |
| 855 | const answer = await enquirer.prompt({ |
| 856 | type: 'select', |
| 857 | name: 'select', |
| 858 | choices: choices.map((choice) => choice.name), |
| 859 | message: renderer.colors.default(message), |
| 860 | styles: { |
| 861 | danger: renderer.colors.red, // This sets the color for the error message |
| 862 | primary: renderer.colors.red, // This sets the primary color to red |
| 863 | submitted: renderer.colors.red, // Assuming 'submitted' is the correct property for the final input |
| 864 | }, |
| 865 | result(name) { |
| 866 | // Return the value corresponding to the selected name |
| 867 | return nameToValueMap[name] |
| 868 | }, |
| 869 | onCancel: () => { |
| 870 | if (onCancel) { |
| 871 | return onCancel() |
| 872 | } |
| 873 | const err = new Error('Canceled') |
| 874 | err.stack = undefined |
| 875 | throw err |
| 876 | }, |
| 877 | }) |
| 878 | |
| 879 | // Save the last selected value |
| 880 | renderer.state.lastToken = answer.select |
| 881 | |
| 882 | // Restart the spinner if it was stopped |
| 883 | renderer.spinner.start() |
| 884 | |
| 885 | return answer.select |
| 886 | } |
| 887 | |
| 888 | async checkbox({ message, choices, initial }) { |
| 889 | // Stop the spinner to not collide with prompt |
no test coverage detected