This is a simple CLI tool to generate a user-selectable menu.
It is based on
peco (which itself is based on
The above mentioned tools are all more feature rich than this one (and I'm sure the code is better too), but I wanted a few different features:
- A list that can be navigated using the keyboard (like
- Fuzzy filterable (like
ctrl-pin vim, etc.)
- Not take over the entire screen (like curses interfaces normally do)
- Dependency free (except for development dependencies)
Add this line to your application's Gemfile:
And then execute:
Or install it system wide for use on the command line:
$ gem install pecorb
For use on the command-line:
ls | pecorb | cat pecorb myFile.txt
For use in a ruby program:
result = Pecorb.list %w[Apples Bananas Cake Donuts] result = Pecorb.list %w[Apples Bananas Cake Donuts], prompt: "Favourite food: "
ctrl-kwill move up through the list
ctrl-jwill move down through the list
ctrl-lwill clear the screen and re-print the menu
escapewill exit (with exit code
\r) will select the item
rightdo what you would expect
Currently this seems to work well on the command line and as a ruby library.
There are some tests but not great coverage. The complex parts are mainly the paging logic (which does have tests) and the random access terminal printing that makes up the user interface (which doesn't have tests).
After checking out the repo, run
bundle install to install dependencies.
To install this gem onto your local machine, run
bundle exec rake install.
To release a new version, update the version number in
version.rb, and then
bundle install and
bundle exec rake release, which will create a git
tag for the version, push git commits and tags, and push the
.gem file to
Bug reports and pull requests are welcome on GitHub at https://github.com/stevenocchipinti/pecorb.
The gem is available as open source under the terms of the MIT License.
Inspiration and education came from these resources: