'Swift Command Line Tool -> Select with arrow keys and spacebar

I'm building command line tools with swift and I'd like to make them more interactive to provide a better user experience.

I was wondering if it's possible to build a select menu for a command line tool similar to the one used in the firebase cli or the angular cli in swift. I'm using the swift argument parser at the moment and it would be very nice if the user could select from different options in a menu via the arrow keys and selecting with the space bar.

Firebase CLI option selection with firebase init



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source