search_ui 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +5 -0
- data/LICENSE +18 -0
- data/README.md +20 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/bin/search_it +28 -0
- data/lib/search_ui.rb +6 -0
- data/lib/search_ui/search.rb +90 -0
- data/lib/search_ui/version.rb +8 -0
- data/search_ui.gemspec +41 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 37d829ad8fbcc4b4e0ae9e986f10b156edea28650062f1e53d79c767fe07dbc1
|
4
|
+
data.tar.gz: 851f87e4e5731d1b515a6354cc13a95820007d179acdee7621009b318378a501
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1beb2eb6a53971c40ab62c898ef5c78fe9c59a39e5b8fa4bd61dedf2c9271b94ad8379fdbbb54a2f50a359e979e9cccc43e0585ebdb8a2103a782685e3fcc0a8
|
7
|
+
data.tar.gz: 0270c1ec8d11b71335ea880c3fc82c4b919f21b97d0e76267cb3f8766a459f130c57a73344e1697644555761145957b78e6e23b83b23a8977e8f7e87031953be
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2020 Florian Frank
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X
|
16
|
+
CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
17
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# SearchUI - Searching things in console
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
This library allows a user to search an array of objects
|
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.
|
8
|
+
|
9
|
+
## Download
|
10
|
+
|
11
|
+
The homepage of this library is located at http://github.com/flori/search\_ui
|
12
|
+
|
13
|
+
## Author
|
14
|
+
|
15
|
+
Florian Frank mailto:flori@ping.de
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
This software is licensed under the X11 (or MIT) license:
|
20
|
+
http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# vim: set filetype=ruby et sw=2 ts=2:
|
2
|
+
|
3
|
+
require 'gem_hadar'
|
4
|
+
|
5
|
+
GemHadar do
|
6
|
+
name 'search_ui'
|
7
|
+
author 'Florian Frank'
|
8
|
+
email 'flori@ping.de'
|
9
|
+
homepage "http://flori.github.com/#{name}"
|
10
|
+
summary 'Library to provide a user interface for searching in a console'
|
11
|
+
description 'This library allows a user to search an array of objects
|
12
|
+
interactively in the console by matching the pattern a user inputs to an
|
13
|
+
array of objects and pick one of the remaining objects.'
|
14
|
+
|
15
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
16
|
+
'.AppleDouble', 'tags', '.byebug_history', '.DS_Store'
|
17
|
+
readme 'README.md'
|
18
|
+
title "#{name.camelize} -- Search User Interface"
|
19
|
+
|
20
|
+
executables << 'search_it'
|
21
|
+
|
22
|
+
required_ruby_version '>= 2.0'
|
23
|
+
dependency 'tins', '~>1.0'
|
24
|
+
dependency 'term-ansicolor', '~>1.0'
|
25
|
+
dependency 'amatch', '~>0.0'
|
26
|
+
development_dependency 'simplecov', '~>0.0'
|
27
|
+
licenses << 'MIT'
|
28
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/search_it
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'search_ui'
|
4
|
+
require 'tins/terminal'
|
5
|
+
require 'amatch'
|
6
|
+
include SearchUI
|
7
|
+
|
8
|
+
|
9
|
+
choices = ARGV
|
10
|
+
exit if choices.empty?
|
11
|
+
|
12
|
+
found = Search.new(
|
13
|
+
match: -> answer {
|
14
|
+
matcher = Amatch::PairDistance.new(answer.downcase)
|
15
|
+
matches = ARGV.map { |n| [ n, -matcher.similar(n.downcase) ] }.
|
16
|
+
select { |_, s| s < 0 }.sort_by(&:last).map(&:first)
|
17
|
+
matches.empty? and matches = choices
|
18
|
+
matches.first(Tins::Terminal.lines - 1)
|
19
|
+
},
|
20
|
+
query: -> _answer, matches, selector {
|
21
|
+
matches.each_with_index.
|
22
|
+
map { |m, i| i == selector ? "→ " + Search.on_blue(m) : " " + m } * ?\n
|
23
|
+
},
|
24
|
+
found: -> _answer, matches, selector {
|
25
|
+
matches[selector]
|
26
|
+
},
|
27
|
+
output: STDOUT
|
28
|
+
).start and puts found
|
data/lib/search_ui.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'term/ansicolor'
|
2
|
+
|
3
|
+
class SearchUI::Search
|
4
|
+
include Term::ANSIColor
|
5
|
+
extend Term::ANSIColor
|
6
|
+
|
7
|
+
def initialize(
|
8
|
+
match:,
|
9
|
+
query:,
|
10
|
+
found:,
|
11
|
+
output: STDOUT,
|
12
|
+
prompt: 'Search? %s'
|
13
|
+
)
|
14
|
+
@match = match
|
15
|
+
@query = query
|
16
|
+
@found = found
|
17
|
+
@output = output
|
18
|
+
@prompt = prompt
|
19
|
+
@selector = 0
|
20
|
+
@max_selector = nil
|
21
|
+
@answer = ''
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
@output.print reset
|
26
|
+
@matches = @match.(@answer)
|
27
|
+
@selector = [ 0, [ @selector, @matches.size - 1 ].min ].max
|
28
|
+
result = @query.(@answer, @matches, @selector)
|
29
|
+
@output.print clear_screen
|
30
|
+
@output.print move_home { ?\n + result }
|
31
|
+
loop do
|
32
|
+
@output.print move_home { @prompt % @answer }
|
33
|
+
case getc
|
34
|
+
when true
|
35
|
+
@output.print clear_screen, move_home, reset
|
36
|
+
if result = @found.(@answer, @matches, @selector)
|
37
|
+
return result
|
38
|
+
else
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
when false
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
@matches = @match.(@answer)
|
45
|
+
@selector = [ 0, [ @selector, @matches.size - 1 ].min ].max
|
46
|
+
result = @query.(@answer, @matches, @selector)
|
47
|
+
@output.print clear_screen
|
48
|
+
@output.print move_home { ?\n + result }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def getc
|
55
|
+
system 'stty raw -echo'
|
56
|
+
c = STDIN.getc
|
57
|
+
system 'stty cooked echo'
|
58
|
+
case c
|
59
|
+
when "\x03"
|
60
|
+
false
|
61
|
+
when "\e"
|
62
|
+
STDIN.getc == ?[ or return nil
|
63
|
+
STDIN.getc =~ /\A([AB])\z/ or return nil
|
64
|
+
if $1 == ?A
|
65
|
+
@selector -= 1
|
66
|
+
else
|
67
|
+
@selector += 1
|
68
|
+
end
|
69
|
+
@selector = [ @selector, 0 ].max
|
70
|
+
nil
|
71
|
+
when ?\r
|
72
|
+
true
|
73
|
+
when "\x7f"
|
74
|
+
@selector = 0
|
75
|
+
@answer.chop!
|
76
|
+
nil
|
77
|
+
when "\v"
|
78
|
+
@selector = 0
|
79
|
+
@answer.clear
|
80
|
+
nil
|
81
|
+
when /\A[\x00-\x1f]\z/
|
82
|
+
nil
|
83
|
+
else
|
84
|
+
@selector = 0
|
85
|
+
@answer << c
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
data/search_ui.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: search_ui 0.0.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "search_ui".freeze
|
6
|
+
s.version = "0.0.0"
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib".freeze]
|
10
|
+
s.authors = ["Florian Frank".freeze]
|
11
|
+
s.date = "2020-02-11"
|
12
|
+
s.description = "This library allows a user to search an array of objects\n interactively in the console by matching the pattern a user inputs to an\n array of objects and pick one of the remaining objects.".freeze
|
13
|
+
s.email = "flori@ping.de".freeze
|
14
|
+
s.executables = ["search_it".freeze]
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/search_ui.rb".freeze, "lib/search_ui/search.rb".freeze, "lib/search_ui/version.rb".freeze]
|
16
|
+
s.files = [".gitignore".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/search_it".freeze, "lib/search_ui.rb".freeze, "lib/search_ui/search.rb".freeze, "lib/search_ui/version.rb".freeze, "search_ui.gemspec".freeze]
|
17
|
+
s.homepage = "http://flori.github.com/search_ui".freeze
|
18
|
+
s.licenses = ["MIT".freeze]
|
19
|
+
s.rdoc_options = ["--title".freeze, "SearchUi -- Search User Interface".freeze, "--main".freeze, "README.md".freeze]
|
20
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
|
21
|
+
s.rubygems_version = "3.1.2".freeze
|
22
|
+
s.summary = "Library to provide a user interface for searching in a console".freeze
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
s.specification_version = 4
|
26
|
+
end
|
27
|
+
|
28
|
+
if s.respond_to? :add_runtime_dependency then
|
29
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.11.0"])
|
30
|
+
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.0"])
|
31
|
+
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0"])
|
32
|
+
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.0"])
|
33
|
+
s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.0"])
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.11.0"])
|
36
|
+
s.add_dependency(%q<simplecov>.freeze, ["~> 0.0"])
|
37
|
+
s.add_dependency(%q<tins>.freeze, ["~> 1.0"])
|
38
|
+
s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.0"])
|
39
|
+
s.add_dependency(%q<amatch>.freeze, ["~> 0.0"])
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: search_ui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florian Frank
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gem_hadar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.11.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.11.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tins
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: term-ansicolor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: amatch
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.0'
|
83
|
+
description: |-
|
84
|
+
This library allows a user to search an array of objects
|
85
|
+
interactively in the console by matching the pattern a user inputs to an
|
86
|
+
array of objects and pick one of the remaining objects.
|
87
|
+
email: flori@ping.de
|
88
|
+
executables:
|
89
|
+
- search_it
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files:
|
92
|
+
- README.md
|
93
|
+
- lib/search_ui.rb
|
94
|
+
- lib/search_ui/search.rb
|
95
|
+
- lib/search_ui/version.rb
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- VERSION
|
103
|
+
- bin/search_it
|
104
|
+
- lib/search_ui.rb
|
105
|
+
- lib/search_ui/search.rb
|
106
|
+
- lib/search_ui/version.rb
|
107
|
+
- search_ui.gemspec
|
108
|
+
homepage: http://flori.github.com/search_ui
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- "--title"
|
115
|
+
- SearchUi -- Search User Interface
|
116
|
+
- "--main"
|
117
|
+
- README.md
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.1.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Library to provide a user interface for searching in a console
|
135
|
+
test_files: []
|