search_ui 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -9
- data/VERSION +1 -1
- data/lib/search_ui/search.rb +2 -2
- data/lib/search_ui/version.rb +1 -1
- data/search_ui.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1bf8a8f5b6d093cff6036196558bfbe4a476be367d1b3af6f724affc6b90db0
|
4
|
+
data.tar.gz: 87813d2915c78f6b7a3f67090264e41ceec84eb0ecf0c80260dd78f22b8c81a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 866af2546d78cd716c13e79340a7a1c66ffaa57a4eb379e527adcc77ef3907b00870f0bda7044d96cd4b7dab392b01670d2abe8294eb9376a6bb37302e5fd2bb
|
7
|
+
data.tar.gz: 84e92c9c5815d5b232133d15dedb84e6b69a8577fc49ae2d0b459a5276b09ea32c33ad619d917f546c67ccb049fd954f56282c52ab8a5a4911d649b4b31a1353
|
data/README.md
CHANGED
@@ -1,20 +1,81 @@
|
|
1
|
-
# SearchUI - Searching things in console
|
1
|
+
# SearchUI 🔍 - Searching things in console
|
2
2
|
|
3
3
|
## Description
|
4
4
|
|
5
|
-
|
6
|
-
interactively in the console by matching the pattern a user inputs to an
|
7
|
-
array of objects and pick one of the remaining objects.
|
5
|
+
A Ruby library for creating interactive console-based search interfaces 🎯
|
8
6
|
|
9
|
-
##
|
7
|
+
## Features
|
10
8
|
|
11
|
-
|
9
|
+
- **Interactive Navigation** 🎮: Arrow key navigation through search results
|
10
|
+
- **Real-time Filtering** ⚡: Instant search updates as you type
|
11
|
+
- **Flexible Configuration** 🔧: Customizable matching, display, and selection logic
|
12
|
+
- **Terminal-aware** 🖥️: Properly handles terminal input and display management
|
13
|
+
- **Minimal Dependencies** 📦: Lightweight implementation using standard Ruby libraries
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this gem to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'search_ui'
|
21
|
+
```
|
22
|
+
|
23
|
+
And install it using Bundler:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
Or install the gem directly:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
gem install search_ui
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### Library Usage
|
38
|
+
|
39
|
+
For programmatic usage, create a custom search interface:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'search_ui'
|
43
|
+
|
44
|
+
items = ['apple', 'banana', 'cherry', 'date']
|
45
|
+
|
46
|
+
result = SearchUI::Search.new(
|
47
|
+
match: ->(pattern) { items.select { |item| item.include?(pattern) } },
|
48
|
+
query: ->(answer, matches, selector) {
|
49
|
+
matches.each_with_index.map do |match, i|
|
50
|
+
if i == selector
|
51
|
+
"→ #{match}"
|
52
|
+
else
|
53
|
+
" #{match}"
|
54
|
+
end
|
55
|
+
end.join("\n")
|
56
|
+
},
|
57
|
+
found: ->(answer, matches, selector) { matches[selector] }
|
58
|
+
).start
|
59
|
+
|
60
|
+
puts "Selected: #{result}"
|
61
|
+
```
|
62
|
+
|
63
|
+
### Command Line Tool
|
64
|
+
|
65
|
+
The `search_it` binary provides a ready-to-use search interface:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
# Search through command-line arguments 🚀
|
69
|
+
./bin/search_it apple banana cherry
|
70
|
+
|
71
|
+
# Search through a file 📄
|
72
|
+
./bin/search_it -f items.txt
|
73
|
+
```
|
12
74
|
|
13
75
|
## Author
|
14
76
|
|
15
|
-
Florian Frank
|
77
|
+
[Florian Frank](mailto:flori@ping.de) 👨💻
|
16
78
|
|
17
79
|
## License
|
18
80
|
|
19
|
-
|
20
|
-
http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3
|
81
|
+
[MIT License](./LICENSE) 📄
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/search_ui/search.rb
CHANGED
@@ -55,7 +55,7 @@ class SearchUI::Search
|
|
55
55
|
def start
|
56
56
|
@output.print reset
|
57
57
|
@matches = @match.(@answer)
|
58
|
-
@selector =
|
58
|
+
@selector = @selector.clamp(0, [ @matches.size - 1, 0 ].max)
|
59
59
|
result = @query.(@answer, @matches, @selector)
|
60
60
|
loop do
|
61
61
|
@output.print clear_screen
|
@@ -72,7 +72,7 @@ class SearchUI::Search
|
|
72
72
|
return nil
|
73
73
|
end
|
74
74
|
@matches = @match.(@answer)
|
75
|
-
@selector = @selector.clamp(0, @matches.size - 1)
|
75
|
+
@selector = @selector.clamp(0, [ @matches.size - 1, 0 ].max)
|
76
76
|
result = @query.(@answer, @matches, @selector)
|
77
77
|
end
|
78
78
|
end
|
data/lib/search_ui/version.rb
CHANGED
data/search_ui.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: search_ui 0.0.
|
2
|
+
# stub: search_ui 0.0.7 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "search_ui".freeze
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.7".freeze
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|