When developing command-line interfaces (CLIs) using React and Ink, an essential component is often a menu or select feature. Although Ink’s ecosystem offers several excellent components out of the box, such as ink-select-input
, I noticed a significant missing feature: genuine support for a horizontal orientation. For games and other visually intricate terminal applications, a horizontal list of options can conserve crucial vertical space and provide a more intuitive user experience.
During the development of my text-based RPG, Potion Wars, managing screen space emerged as a significant challenge. The game extensively utilizes menus and selectors for user input, which can quickly dominate the vertical space when arranged in lists. By transitioning to a horizontal layout, I was able to align the menus side-by-side, thereby preserving vertical space and enhancing the UI’s overall appearance and functionality.
I dug into the existing solutions and discovered an older issue in the ink-select-input
repository calling for horizontal orientation support. Another developer, H3RSKO, created a fork called ink-select-input-horizontal
, but my testing revealed limitations and a few lingering bugs that made it less than ideal for my needs.
To address these issues, I decided to build my own component: ink-enhanced-select-input. This component extends the original idea of ink-select-input
but adds native support for an orientation
prop. With this prop, you can easily switch between a vertical list (the classic style) and a horizontal layout, opening the door to more creative CLI interfaces.
In addition, I’ve added various features and properties over time, as required by Potion Wars’ evolving mechanics:
vertical
or horizontal
for your layout.By creating this component in tandem with my game, I had the opportunity to test it in a real-world setting. This ensured that it not only functioned as intended but also felt intuitive and robust.
Ink Enhanced Select Input is now published on NPM and available for anyone to integrate into their Ink-based CLIs. It works well, but I’m not stopping there. Here are a few things I’d love to explore in the future:
Getting started with Ink Enhanced Select Input is simple and can be done using your preferred package manager.
# npm
npm install ink-enhanced-select-input
# yarn
yarn add ink-enhanced-select-input
# pnpm
pnpm add ink-enhanced-select-input
This project exists because of the challenges I faced and the feedback I gathered from existing solutions. Now that it’s open-source, I’d love to hear from other developers using Ink. Whether you’re building a game, a tool, or a productivity CLI, your feedback can guide future improvements.
You can find the repository here: https://github.com/gfargo/ink-enhanced-select-input.
Feel free to open issues, suggest enhancements, or submit pull requests. Together, we can make the Ink ecosystem even richer and more versatile for terminal-based UIs.
Thanks for reading! If you’re working on something similar or have ideas on how to push this component further, I’m all ears. Let’s keep building better CLI experiences, one component at a time.