cli-ui 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 367667f90cce34fe2ac10fffbd13a24a8b7a90e3
4
- data.tar.gz: fdc151c1343bc037c8f03c3308ec3646795e9dbd
3
+ metadata.gz: e859c2ecb4ac2b2b43b843c664284e8ee95e7a43
4
+ data.tar.gz: 102c74d7762e602e87fafba4eee93ba85f8e20cf
5
5
  SHA512:
6
- metadata.gz: 51e249672f6214028aebf3ab31b2d90cde511da996118b50607522318528c57ae0bfe40edc4b447593fb5faf2712b964fdfafdc26e1b092ce96e8ee92366e759
7
- data.tar.gz: 58e27c5790e1bb0f35581953467a8c5a38d7ca647f3cca7042e42d347c9708dc44e9007cb326fa563b241daaaaa480662de7dfdaa2ad5a3084ecf68dc4158cf6
6
+ metadata.gz: 59ff9f79be424133981a6eb878b3a7b8818c200a9f24f545f9c036765dcd9b0bd13a4b313121bc603282b2aeeb9dc516ac0d788fac44c5e50888cd6f8c566e50
7
+ data.tar.gz: b9a1b36d13f0c9779f481e18cbabfbd42e62735e5de9705005bc3affaaffa2113be8aa3c1804d154352c2a699da13e17217e7fb1947cd9e55fe8d69fafba4857
data/README.md CHANGED
@@ -52,7 +52,7 @@ CLI::UI.ask('What language/framework do you use?', options: %w(rails go ruby pyt
52
52
  Can also assign callbacks to each option
53
53
 
54
54
  ```ruby
55
- CLI::UI.ask('What language/framework do you use?') do |handler|
55
+ CLI::UI::Prompt.ask('What language/framework do you use?') do |handler|
56
56
  handler.option('rails') { |selection| selection }
57
57
  handler.option('go') { |selection| selection }
58
58
  handler.option('ruby') { |selection| selection }
@@ -76,8 +76,8 @@ module CLI
76
76
  def to_s
77
77
  suffix = " #{(@percent_done * 100).round(2)}%"
78
78
  workable_width = @max_width - Frame.prefix_width - suffix.size
79
- filled = (@percent_done * workable_width.to_f).ceil
80
- unfilled = workable_width - filled
79
+ filled = [(@percent_done * workable_width.to_f).ceil, 0].max
80
+ unfilled = [workable_width - filled, 0].max
81
81
 
82
82
  CLI::UI.resolve_text [
83
83
  FILLED_BAR + ' ' * filled,
@@ -76,8 +76,13 @@ module CLI
76
76
  def num_lines
77
77
  # @options will be an array of questions but each option can be multi-line
78
78
  # so to get the # of lines, you need to join then split
79
+
80
+ # empty_option_count is needed since empty option titles are omitted
81
+ # from the line count when reject(&:empty?) is called
82
+
83
+ empty_option_count = @options.count(&:empty?)
79
84
  joined_options = @options.join("\n")
80
- joined_options.split("\n").reject(&:empty?).size
85
+ joined_options.split("\n").reject(&:empty?).size + empty_option_count
81
86
  end
82
87
 
83
88
  ESC = "\e"
@@ -15,13 +15,15 @@ module CLI
15
15
  end
16
16
 
17
17
  def write(*args)
18
- if auto_frame_inset?
19
- str = args[0].dup # unfreeze
20
- str = str.force_encoding(Encoding::UTF_8)
21
- str = apply_line_prefix(str, CLI::UI::Frame.prefix)
22
- args[0] = str
23
- else
24
- @pending_newline = false
18
+ args = args.map do |str|
19
+ if auto_frame_inset?
20
+ str = str.dup # unfreeze
21
+ str = str.force_encoding(Encoding::UTF_8)
22
+ apply_line_prefix(str, CLI::UI::Frame.prefix)
23
+ else
24
+ @pending_newline = false
25
+ str
26
+ end
25
27
  end
26
28
 
27
29
  hook = Thread.current[:cliui_output_hook]
@@ -4,17 +4,20 @@ require 'io/console'
4
4
  module CLI
5
5
  module UI
6
6
  module Terminal
7
+ DEFAULT_WIDTH = 80
8
+
7
9
  # Returns the width of the terminal, if possible
8
10
  # Otherwise will return 80
9
11
  #
10
12
  def self.width
11
13
  if console = IO.respond_to?(:console) && IO.console
12
- console.winsize[1]
14
+ width = console.winsize[1]
15
+ width.zero? ? DEFAULT_WIDTH : width
13
16
  else
14
- 80
17
+ DEFAULT_WIDTH
15
18
  end
16
19
  rescue Errno::EIO
17
- 80
20
+ DEFAULT_WIDTH
18
21
  end
19
22
  end
20
23
  end
@@ -1,5 +1,5 @@
1
1
  module CLI
2
2
  module UI
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-02-23 00:00:00.000000000 Z
13
+ date: 2018-04-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler