utils 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/discover +4 -4
- data/lib/utils/search_ui.rb +17 -3
- data/lib/utils/version.rb +1 -1
- data/utils.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: 4d96c7cf970c92753376fda93b80ddaacaddc369e6b76016b32f1ba4dca4e481
|
4
|
+
data.tar.gz: 734f6d3bb32ca8c8afaef530d6634be5672cd30569c728a62bf9dd3282e9b143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f40d11fbdb46906ca04c51dea3c326ea74a4fdd2fcc1f7900d57c3cafb6c98565e444c5ba2e1aeca35f02c882d3ffe67f0827b671eadaddecbe8926394f90c95
|
7
|
+
data.tar.gz: a734f2ac070ad39bffa1428855ec64cc09e76e6149c710b9e7876a180a72a1df274d5fb51994087ec8388ff803900be6f5ea3fd240dba9443621f0721a420a72
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.19.0
|
data/bin/discover
CHANGED
@@ -84,13 +84,13 @@ when args[?s]
|
|
84
84
|
args[?n] = Term::ANSIColor.terminal_lines - 1
|
85
85
|
path = nil
|
86
86
|
found = Utils::SearchUI.new(
|
87
|
-
query: -> answer {
|
87
|
+
query: -> answer, selector {
|
88
88
|
pattern.replace answer
|
89
89
|
f = finder.()
|
90
|
-
f.search.output.join(?\n)
|
90
|
+
f.search.output.each_with_index.map { |l, i| (i == selector ? '> ' : ' ') + l }.join(?\n)
|
91
91
|
},
|
92
|
-
found: -> answer {
|
93
|
-
f and path = f.paths
|
92
|
+
found: -> answer, selector {
|
93
|
+
f and path = f.paths[selector]
|
94
94
|
},
|
95
95
|
output: STDERR
|
96
96
|
).start
|
data/lib/utils/search_ui.rb
CHANGED
@@ -4,6 +4,7 @@ class Utils::SearchUI
|
|
4
4
|
include Term::ANSIColor
|
5
5
|
|
6
6
|
def initialize(query:, found:, output: STDOUT, prompt: 'Search? %s')
|
7
|
+
@selector = 0
|
7
8
|
@query = query
|
8
9
|
@found = found
|
9
10
|
@output = output
|
@@ -18,7 +19,7 @@ class Utils::SearchUI
|
|
18
19
|
case getc
|
19
20
|
when true
|
20
21
|
@output.print clear_screen, move_home, reset
|
21
|
-
if result = @found.(@answer)
|
22
|
+
if result = @found.(@answer, @selector)
|
22
23
|
return result
|
23
24
|
else
|
24
25
|
return nil
|
@@ -26,7 +27,7 @@ class Utils::SearchUI
|
|
26
27
|
when false
|
27
28
|
return nil
|
28
29
|
end
|
29
|
-
result = @query.(@answer)
|
30
|
+
result = @query.(@answer, @selector)
|
30
31
|
@output.print clear_screen
|
31
32
|
unless @answer.empty?
|
32
33
|
@output.print move_home { ?\n + result }
|
@@ -41,19 +42,32 @@ class Utils::SearchUI
|
|
41
42
|
c = STDIN.getc
|
42
43
|
system 'stty cooked echo'
|
43
44
|
case c
|
44
|
-
when "\x03"
|
45
|
+
when "\x03"
|
45
46
|
false
|
47
|
+
when "\e"
|
48
|
+
STDIN.getc == ?[ or return nil
|
49
|
+
STDIN.getc =~ /\A([AB])\z/ or return nil
|
50
|
+
if $1 == ?A
|
51
|
+
@selector -= 1
|
52
|
+
else
|
53
|
+
@selector += 1
|
54
|
+
end
|
55
|
+
@selector = [ @selector, 0 ].max
|
56
|
+
nil
|
46
57
|
when ?\r
|
47
58
|
true
|
48
59
|
when "\x7f"
|
60
|
+
@selector = 0
|
49
61
|
@answer.chop!
|
50
62
|
nil
|
51
63
|
when "\v"
|
64
|
+
@selector = 0
|
52
65
|
@answer.clear
|
53
66
|
nil
|
54
67
|
when /\A[\x00-\x1f]\z/
|
55
68
|
nil
|
56
69
|
else
|
70
|
+
@selector = 0
|
57
71
|
@answer << c
|
58
72
|
nil
|
59
73
|
end
|
data/lib/utils/version.rb
CHANGED
data/utils.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: utils 0.
|
2
|
+
# stub: utils 0.19.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "utils".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.19.0"
|
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]
|