Project

search_ui

0.0
No release in over a year
This library allows a user to search an array of objects interactively in the console by matching the pattern a user inputs to an array of objects and pick one of the remaining objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
~> 0.0
~> 2.6

Runtime

~> 0.0
~> 1.0
 Project Readme

SearchUI 🔍 - Searching things in console

Description

A Ruby library for creating interactive console-based search interfaces 🎯

Documentation

Complete API documentation is available at: GitHub.io

Features

  • Interactive Navigation 🎮: Arrow key navigation through search results
  • Real-time Filtering ⚡: Instant search updates as you type
  • Flexible Configuration 🔧: Customizable matching, display, and selection logic
  • Terminal-aware 🖥️: Properly handles terminal input and display management
  • Minimal Dependencies 📦: Lightweight implementation using standard Ruby libraries

Installation

Add this gem to your Gemfile:

gem 'search_ui'

And install it using Bundler:

bundle install

Or install the gem directly:

gem install search_ui

Usage

Library Usage

For programmatic usage, create a custom search interface:

require 'search_ui'

items = ['apple', 'banana', 'cherry', 'date']

result = SearchUI::Search.new(
  match: ->(pattern) { items.select { |item| item.include?(pattern) } },
  query: ->(answer, matches, selector) {
    matches.each_with_index.map do |match, i|
      if i == selector
        "→ #{match}"
      else
        "  #{match}"
      end
    end.join("\n")
  },
  found: ->(answer, matches, selector) { matches[selector] }
).start

puts "Selected: #{result}"

Command Line Tool

The search_it binary provides a ready-to-use search interface:

# Search through command-line arguments 🚀
./bin/search_it apple banana cherry

# Search through a file 📄
./bin/search_it -f items.txt

Author

Florian Frank 👨‍💻

License

MIT License 📄