Simple gem for CLI UIs

Posted . Visible to the public.

If you want to build a small CLI application, that supports more advanced inputs than gets, I recommend using the cli-ui Show archive.org snapshot gem. It's a small dependency-free library that provides basic building blocks, like an interactive prompt:

require "cli/ui"

CLI::UI::StdoutRouter.enable

puts CLI::UI.fmt "a small {{red:demo}}"

# supports h, j, k, l, arrows and even filtering
CLI::UI::Prompt.ask("Choose a plan:", options: ["small", "medium", "large"])

or a simple progress bar for long running scripts:

# script/some_long_running_script.rb
tick_percentage = 1.0 / Record.count

CLI::UI::Progress.progress("Huge Migration") do |bar|
  Record.find_each do |record|
    record.migrate
    
    bar.tick(percent: tick_percentage)
  end
end
Profile picture of Niklas Hä.
Niklas Hä.
Last edit
Niklas Hä.
License
Source code in this card is licensed under the MIT License.
Posted by Niklas Hä. to makandra dev (2025-06-25 15:26)