ansi-select 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ansi/selector.rb +14 -8
- data/lib/ansi/selector/impl.rb +4 -3
- data/lib/ansi/selector/multi_impl.rb +1 -1
- data/lib/ansi/selector/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e13d49ad9fbd68444bd57285be4ccf3f5e1f49ee
|
4
|
+
data.tar.gz: 19fcdc33f820048defbf9e5c0bb0dfc91f8c0e27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d529cbf8212e712a8b6cbf143e4ed871ee522068fb241a24e6e62bdb1c964263d1e86908dd09a955843a0708d5edd1761e950dc8a51957f9312227be435946cf
|
7
|
+
data.tar.gz: 06b4b56d99357bdaabb9d3abb3c26cfb666276aa8f0a34ab0c6c63a790bee6317fca537c219afcba35248b98def8ef62039a7e32fa48ec5e5a99ef4867744757
|
data/CHANGELOG.md
CHANGED
data/lib/ansi/selector.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
module Ansi
|
2
2
|
class Selector
|
3
|
-
# @param [Array
|
3
|
+
# @param [Array<Object>] options
|
4
4
|
#
|
5
|
-
# @return [
|
6
|
-
def self.select(options)
|
5
|
+
# @return [Object] option
|
6
|
+
def self.select(options, formatter = default_formatter)
|
7
7
|
require_relative "selector/single_impl"
|
8
8
|
|
9
|
-
SingleImpl.new(options).select
|
9
|
+
SingleImpl.new(options, formatter).select
|
10
10
|
end
|
11
11
|
|
12
|
-
# @param [Array
|
12
|
+
# @param [Array<Object>] options
|
13
13
|
#
|
14
|
-
# @return [Array
|
15
|
-
def self.multi_select(options)
|
14
|
+
# @return [Array<Object>] option
|
15
|
+
def self.multi_select(options, formatter = default_formatter)
|
16
16
|
require_relative "selector/multi_impl"
|
17
17
|
|
18
|
-
MultiImpl.new(options).select
|
18
|
+
MultiImpl.new(options, formatter).select
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def default_formatter
|
24
|
+
->(options) { option.name }
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
data/lib/ansi/selector/impl.rb
CHANGED
@@ -11,8 +11,9 @@ module Ansi
|
|
11
11
|
carriage_return_key: `tput cr`
|
12
12
|
}
|
13
13
|
|
14
|
-
def initialize(options)
|
14
|
+
def initialize(options, formatter)
|
15
15
|
@options = options
|
16
|
+
@formatter = formatter
|
16
17
|
|
17
18
|
@highlighted_line_index = 0
|
18
19
|
@cursor_line_index = 0
|
@@ -89,9 +90,9 @@ module Ansi
|
|
89
90
|
go_to_line(index)
|
90
91
|
|
91
92
|
if highlight
|
92
|
-
tty.print(CODES[:standout_mode] + prefix(index) + @options[index]
|
93
|
+
tty.print(CODES[:standout_mode] + prefix(index) + formatter.call(@options[index]) + CODES[:exit_standout_mode])
|
93
94
|
else
|
94
|
-
tty.print(prefix(index) + @options[index]
|
95
|
+
tty.print(prefix(index) + formatter.call(@options[index]))
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|