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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c56f7576f128137af467047313b06291bfeb55f0
4
- data.tar.gz: ebec5d1e147709d3ca99b52150f180a3ce0437f9
3
+ metadata.gz: e13d49ad9fbd68444bd57285be4ccf3f5e1f49ee
4
+ data.tar.gz: 19fcdc33f820048defbf9e5c0bb0dfc91f8c0e27
5
5
  SHA512:
6
- metadata.gz: cb07f1c7398f1b1e86987ef1a0ca96b49f3b4f8148c2ea82393b4ab6546cac3f77e90bd5a182c280c213c462d33e3b7061a600d9bb3fd8f4ca5562747c4f16e5
7
- data.tar.gz: db5ad003478555319c6821f617f231891c792e5d55b6f53401be3914c37138e22815dbde10f0e86d4863df56b34b2332806519130ee902c5a4cdfe0589c0271a
6
+ metadata.gz: d529cbf8212e712a8b6cbf143e4ed871ee522068fb241a24e6e62bdb1c964263d1e86908dd09a955843a0708d5edd1761e950dc8a51957f9312227be435946cf
7
+ data.tar.gz: 06b4b56d99357bdaabb9d3abb3c26cfb666276aa8f0a34ab0c6c63a790bee6317fca537c219afcba35248b98def8ef62039a7e32fa48ec5e5a99ef4867744757
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.2.2
2
+
3
+ * Ability to pass a custom formatter.
4
+
1
5
  ### 0.2.1
2
6
 
3
7
  * Prefix options with spaces.
data/lib/ansi/selector.rb CHANGED
@@ -1,21 +1,27 @@
1
1
  module Ansi
2
2
  class Selector
3
- # @param [Array<#to_s>] options
3
+ # @param [Array<Object>] options
4
4
  #
5
- # @return [#to_s] option
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<#to_s>] options
12
+ # @param [Array<Object>] options
13
13
  #
14
- # @return [Array<#to_s>] option
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
@@ -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].to_s + CODES[:exit_standout_mode])
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].to_s)
95
+ tty.print(prefix(index) + formatter.call(@options[index]))
95
96
  end
96
97
  end
97
98
 
@@ -3,7 +3,7 @@ require_relative 'impl'
3
3
  module Ansi
4
4
  class Selector
5
5
  class MultiImpl < Impl
6
- def initialize(options)
6
+ def initialize(options, formatter)
7
7
  super
8
8
 
9
9
  # @type [Array<Boolean>]
@@ -1,5 +1,5 @@
1
1
  module Ansi
2
2
  class Selector
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansi-select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodymyr Shatskyi