natty-ui 0.33.0 → 0.34.0

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
  SHA256:
3
- metadata.gz: 79e64cb2489dcf9efe4066e4f95252284f9227aafa4a77edd0d50f307b255cf2
4
- data.tar.gz: 7ec6f014b300740062e816fa9c787ff79b3fb7ce68e4b1c2d6967ae6eb58b53d
3
+ metadata.gz: 0c61c16b1c5d1611a98f1505bb9eb86b71a0289021a9332f41e2095f7810b144
4
+ data.tar.gz: e8acc6fdf67bd259fd671defd80533f5de0fa9aa7b005cef9f092b7ebf097606
5
5
  SHA512:
6
- metadata.gz: 86abb66230c52bd8863aec983435b434e7272003a12db631cb0b46af9db938ffc16f3ba1f987dad53a10f9ff4393e5f4bf403d04b813bb68b4b189c5bf0b2860
7
- data.tar.gz: 34afc008cdec26384f7f20b7be6830a5be511147cfaef831d8e6869f858219ffeaea394ec8718ceb7513cfa3aaee19a852bb70d2b2ef641bc5880ca79d8de38d
6
+ metadata.gz: a38c19bc286fff4f5776fde2bb1a1de897ea3cdc8498c774691c449de6c2614b229f50a84d6eaf3a89c90af8a99500f6fc8e9237fea9dea7c8234370d4629399
7
+ data.tar.gz: 9d74ccf3a7202619718e8dd67e19cf53534996738c2e04522e3ba6b67aac51323167e7989577c9ace0c793e729130e984eeffb2eae9d98b8458e5f401249b7cc
data/README.md CHANGED
@@ -63,3 +63,7 @@ After that you only need one line of code to have everything together
63
63
  ```ruby
64
64
  require 'natty-ui'
65
65
  ```
66
+
67
+ ## Dependencies
68
+
69
+ It uses only the fantastic [Terminal.rb](https://rubygems.org/gems/terminal_rb) gem.
data/examples/info.rb CHANGED
@@ -19,8 +19,8 @@ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Terminal Information[/]' do
19
19
  table.add 'Identifier', Terminal.application || 'unidentified'
20
20
  table.add 'ANSI support', Terminal.ansi? ? 'yes' : 'no'
21
21
  table.add 'Input mode', Terminal.input_mode
22
- table.add 'Colors', colors
23
22
  table.add 'Screen size', Terminal.size.join(' x ')
23
+ table.add 'Colors', colors
24
24
  table.columns[0].assign(width: 15, padding_right: 2, align: :right)
25
25
  table.columns[1].style = %i[bold bright_yellow]
26
26
  end
@@ -2,29 +2,24 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- event = nil
6
- while true
7
- ui.temporary do
8
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Keyboard Key Codes[/]' do
9
- ui.puts(
10
- "
11
- #{
12
- if event
13
- "#{event.to_a.size < 2 ? ' Key' : 'Keys'}: [bold bright_green]#{
14
- event.to_a.map { "[\\#{_1}]" }.join(' ')
15
- }[/]
16
- Code: [bright_blue]#{event.raw.inspect}[/]"
17
- else
18
- "Your terminal uses [bright_blue]#{
19
- Terminal.input_mode
20
- }[/] mode. Press a key!"
21
- end
22
- }
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Keyboard Key Codes[/]' do
6
+ ui.space
7
+ ui.puts(
8
+ "Your terminal uses [bright_blue]#{Terminal.input_mode}[/] mode. Press a key!",
9
+ '[dim](Exit with ESC)'
10
+ )
23
11
 
24
- [faint](Exit with ESC)"
25
- )
26
- end
27
- event = Terminal.read_key_event
28
- exit if event.nil? || event.name == 'Esc'
12
+ ui.space
13
+ # if you like to have mouse position changes reported then use
14
+ # 'mouse_move: true' in next line
15
+ Terminal.on_key_event(mouse: true, focus: true, mouse_move: false) do |event|
16
+ ui.puts(
17
+ "#{event.raw.inspect} [dim]→[/dim] [bold bright_green]#{
18
+ event.to_a.map { "[\\#{_1}]" }.join('+')
19
+ }#{" @ #{event.position.join(', ')}" if event.position}"
20
+ )
21
+ event.name != 'Esc'
29
22
  end
23
+
24
+ ui.space
30
25
  end
@@ -9,12 +9,12 @@ module NattyUI
9
9
  pin_line = NattyUI.lines_written
10
10
  draw
11
11
  last = @current
12
- while (event = Terminal.read_key_event)
12
+ Terminal.on_key_event do |event|
13
13
  case event.name
14
14
  when 'Esc', 'Ctrl+c'
15
- break nil if @abortable
15
+ return if @abortable
16
16
  when 'Enter', 'Space'
17
- break @ret[@current]
17
+ return @ret[@current]
18
18
  when 'Home'
19
19
  @current = 0
20
20
  when 'End'
@@ -24,11 +24,11 @@ module NattyUI
24
24
  when 'Down', 'Tab', 'k', 's'
25
25
  @current = 0 if (@current += 1) == @texts.size
26
26
  else
27
- next unless event.simple?
27
+ next true unless event.simple?
28
28
  c = event.key.ord
29
29
  @current = (c - 48).clamp(0, @texts.size - 1) if c.between?(48, 57)
30
30
  end
31
- next if last == @current
31
+ next true if last == @current
32
32
  pin_line = NattyUI.back_to_line(pin_line, erase: false)
33
33
  draw
34
34
  last = @current
@@ -7,15 +7,15 @@ module NattyUI
7
7
  def select
8
8
  yield(self) if block_given?
9
9
  draw
10
- while (event = Terminal.read_key_event)
10
+ Terminal.on_key_event do |event|
11
11
  return if @abortable && %w[Esc Ctrl+c].include?(event.name)
12
- next unless event.simple?
12
+ next true unless event.simple?
13
13
  code = event.raw.upcase
14
14
  if @ret.size <= 9
15
- next unless ('1'..'9').include?(code)
16
- code = @ret[code.ord - 49] and break code
15
+ next true unless ('1'..'9').include?(code)
16
+ code = @ret[code.ord - 49] and return code
17
17
  elsif ('A'..'Z').include?(code)
18
- code = @ret[code.ord - 65] and break code
18
+ code = @ret[code.ord - 65] and return code
19
19
  end
20
20
  end
21
21
  end
@@ -7,20 +7,20 @@ module NattyUI
7
7
  def select
8
8
  yield(self) if block_given?
9
9
  draw
10
- while (event = Terminal.read_key_event)
10
+ Terminal.on_key_event do |event|
11
11
  return if @abortable && %w[Esc Ctrl+c].include?(event.name)
12
12
  return @opts.transform_values(&:last) if event.name == 'Enter'
13
- next unless event.simple?
13
+ next true unless event.simple?
14
14
  code = event.raw.upcase
15
15
  if @opts.size <= 9
16
- next unless ('1'..'9').include?(code)
16
+ next true unless ('1'..'9').include?(code)
17
17
  offset = 49
18
18
  elsif ('A'..'Z').include?(code)
19
19
  offset = 65
20
20
  else
21
- next
21
+ next true
22
22
  end
23
- key = @opts.keys[code.ord - offset] or next
23
+ key = @opts.keys[code.ord - offset] or next true
24
24
  @opts[key][-1] = !@opts[key][-1]
25
25
  @parent.space
26
26
  draw
@@ -45,7 +45,7 @@ module NattyUI
45
45
  ignore_newline = options[:eol] == false || options[:ignore_newline]
46
46
 
47
47
  if (max_width = options[:max_width]).nil?
48
- return self if (max_width = Terminal.columns).zero?
48
+ max_width = Terminal.columns
49
49
  elsif max_width < 1
50
50
  if max_width > 0
51
51
  max_width *= Terminal.columns
@@ -56,6 +56,8 @@ module NattyUI
56
56
  end
57
57
  end
58
58
 
59
+ return self if max_width <= 0
60
+
59
61
  prefix_width =
60
62
  if (prefix = options[:prefix])
61
63
  prefix = Ansi.bbcode(prefix) if bbcode
@@ -117,8 +119,7 @@ module NattyUI
117
119
  end
118
120
 
119
121
  unless options[:expand]
120
- lines = lines.to_a
121
- max_width = lines.max_by(&:last).last
122
+ max_width = (lines = lines.to_a).max_by(&:last)[-1]
122
123
  end
123
124
 
124
125
  case align
@@ -1000,13 +1001,15 @@ module NattyUI
1000
1001
  end
1001
1002
 
1002
1003
  def __await(yes, no)
1003
- while (event = Terminal.read_key_event&.name)
1004
+ Terminal.on_key_event do |event|
1005
+ event = event.name
1004
1006
  if (no == event) || (no.is_a?(Enumerable) && no.include?(event))
1005
1007
  return false
1006
1008
  end
1007
1009
  if (yes == event) || (yes.is_a?(Enumerable) && yes.include?(event))
1008
1010
  return true
1009
1011
  end
1012
+ true
1010
1013
  end
1011
1014
  end
1012
1015
  end
@@ -9,7 +9,7 @@ module NattyUI
9
9
  pin_line = NattyUI.lines_written
10
10
  draw
11
11
  last = @current
12
- while (event = Terminal.read_key_event)
12
+ Terminal.on_key_event do |event|
13
13
  case event.name
14
14
  when 'Esc', 'Ctrl+c'
15
15
  return if @abortable
@@ -34,7 +34,7 @@ module NattyUI
34
34
  keys = @opts.keys
35
35
  @current = keys[keys.index(@current) + 1] || keys[0]
36
36
  end
37
- next if last == @current
37
+ next true if last == @current
38
38
  pin_line = NattyUI.back_to_line(pin_line, erase: false)
39
39
  draw
40
40
  last = @current
@@ -82,7 +82,6 @@ module NattyUI
82
82
 
83
83
  def _done(text)
84
84
  NattyUI.back_to_line(@pin_line)
85
- @pin_line = nil
86
85
  cm = Theme.current.mark(:checkmark)
87
86
  @parent.puts(
88
87
  *text,
@@ -94,7 +93,6 @@ module NattyUI
94
93
 
95
94
  def _failed
96
95
  NattyUI.back_to_line(NattyUI.lines_written - 1) if @last&.size == 2
97
- @pin_line = nil
98
96
  end
99
97
 
100
98
  def initialize(parent, title, max, pin)
@@ -106,8 +104,8 @@ module NattyUI
106
104
  @style = Theme.current.task_style
107
105
  cm = Theme.current.mark(:current)
108
106
  @redraw_opts = {
109
- first_line_prefix: "#{cm} #{@style}",
110
- first_line_prefix_width: cm.width + 1
107
+ first_line_prefix: "#{cm}#{@style}",
108
+ first_line_prefix_width: cm.width
111
109
  }
112
110
  max ? self.max = max : redraw
113
111
  end
@@ -130,7 +128,6 @@ module NattyUI
130
128
  size = [@parent.columns, 72].min - 11
131
129
  percent = format('%5.2f', 100.0 * diff)
132
130
  return percent if size < 10
133
- return if percent == '100.00'
134
131
  fill = '█' * (size * diff)
135
132
  "#{percent}% [bright_black]┃#{@style}#{fill}[bright_black]#{
136
133
  '░' * (size - fill.size)
@@ -5,7 +5,7 @@ require_relative 'theme'
5
5
  module NattyUI
6
6
  module ShellRenderer
7
7
  def self.sh(parent, cmd, options, space)
8
- opts_out, opts_err = opts_fom(Theme.current)
8
+ opts_out, opts_err = opts_from(Theme.current)
9
9
  Terminal.sh(*cmd, **options) do |line, kind|
10
10
  parent.puts(
11
11
  space ? line.gsub("\t", '    ').gsub(/[[:space:]]/, ' ') : line,
@@ -15,7 +15,7 @@ module NattyUI
15
15
  end
16
16
 
17
17
  if Terminal.ansi?
18
- def self.opts_fom(theme)
18
+ def self.opts_from(theme)
19
19
  out = theme.mark(:sh_out)
20
20
  err = theme.mark(:sh_err)
21
21
  [
@@ -56,7 +56,7 @@ module NattyUI
56
56
  ]
57
57
  end
58
58
  else
59
- def self.opts_fom(theme)
59
+ def self.opts_from(theme)
60
60
  out = theme.mark(:sh_out)
61
61
  err = theme.mark(:sh_err)
62
62
  [
@@ -163,6 +163,8 @@ module NattyUI
163
163
  current: '➔',
164
164
  choice: '◦',
165
165
  current_choice: '◉',
166
+ option: '[ ]',
167
+ option_selected: '[X]',
166
168
  sh_out: ':',
167
169
  sh_err: '𝙓'
168
170
  }
@@ -243,8 +245,8 @@ module NattyUI
243
245
  # [current?][selected?]
244
246
  c = @mark[:current_choice]
245
247
  n = @mark[:none]
246
- sel = @mark[:checkmark]
247
- uns = @mark[:choice]
248
+ uns = @mark[:option]
249
+ sel = @mark[:option_selected]
248
250
  {
249
251
  false => { false => n + uns, true => n + sel }.compare_by_identity,
250
252
  true => { false => c + uns, true => c + sel }.compare_by_identity
@@ -348,6 +350,8 @@ module NattyUI
348
350
  current: '[bright_green]➔[/fg]',
349
351
  choice: '[bright_white]◦[/fg]',
350
352
  current_choice: '[bright_green]➔[/fg]',
353
+ option: '[dim][ ][/dim]',
354
+ option_selected: '[dim][[/dim][green]X[/fg][dim]][/dim]',
351
355
  sh_out: '[bright_white]:[/fg]',
352
356
  sh_err: '[red]𝙓[/fg]'
353
357
  )
@@ -379,6 +383,8 @@ module NattyUI
379
383
  current: '➡️',
380
384
  choice: '[bright_white]•[/fg]',
381
385
  current_choice: '[bright_green]●[/fg]',
386
+ option: '[dim][ ][/dim] ',
387
+ option_selected: '[dim][[/dim][green]X[/fg][dim]][/dim]',
382
388
  sh_out: '[white b]:[/]',
383
389
  sh_err: '❗️'
384
390
  )
@@ -2,5 +2,5 @@
2
2
 
3
3
  module NattyUI
4
4
  # The version number of the gem.
5
- VERSION = '0.33.0'
5
+ VERSION = '0.34.0'
6
6
  end
data/lib/natty-ui.rb CHANGED
@@ -50,7 +50,7 @@ module NattyUI
50
50
  # configured title
51
51
  # @return [nil]
52
52
  # when no title was set
53
- def title = @title_stack.last
53
+ def title = @title_stack[-1]
54
54
 
55
55
  # @attribute [w] title
56
56
  def title=(value)
@@ -85,17 +85,6 @@ module NattyUI
85
85
  @lines_written = number
86
86
  end
87
87
 
88
- # @private
89
- def alternate_screen
90
- return yield unless Terminal.ansi?
91
- begin
92
- Terminal.raw_write(Ansi::SCREEN_ALTERNATE)
93
- yield
94
- ensure
95
- Terminal.raw_write(Ansi::SCREEN_ALTERNATE_OFF)
96
- end
97
- end
98
-
99
88
  private
100
89
 
101
90
  def with(element)
@@ -111,6 +100,8 @@ module NattyUI
111
100
  @element = self
112
101
  @lines_written = 0
113
102
  @title_stack = []
103
+
104
+ autoload :VERSION, "#{__dir__}/natty-ui/version.rb"
114
105
  end
115
106
 
116
107
  unless defined?(Kernel.ui)
data/natty-ui.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/natty-ui/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'natty-ui'
7
+ spec.version = NattyUI::VERSION
8
+ spec.summary = <<~SUMMARY.tr("\n", ' ')
9
+ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich,
10
+ lovely, natty user interface you like to have for your CLI.
11
+ SUMMARY
12
+ spec.description = <<~DESCRIPTION.tr("\n", ' ')
13
+ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
14
+ natty user interface tool you like to have for your command line
15
+ applications. It contains elegant, simple and beautiful features that
16
+ enhance your command line interfaces functionally and aesthetically.
17
+ DESCRIPTION
18
+
19
+ spec.author = 'Mike Blumtritt'
20
+ spec.licenses = %w[MIT Ruby]
21
+ spec.homepage = 'https://codeberg.org/mblumtritt/natty-ui'
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
24
+ spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/natty-ui'
25
+ spec.metadata['rubygems_mfa_required'] = 'true'
26
+ spec.metadata['yard.run'] = 'yard'
27
+
28
+ spec.required_ruby_version = '>= 3.0'
29
+ spec.add_dependency 'terminal_rb', '>= 0.17.0'
30
+
31
+ spec.files = Dir['lib/**/*.rb'] + Dir['examples/*.rb']
32
+ spec.files << 'natty-ui.gemspec' << '.yardopts'
33
+ spec.extra_rdoc_files = %w[README.md]
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natty-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -15,27 +15,24 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.14.0
18
+ version: 0.17.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.14.0
26
- description: |
27
- This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
28
- natty user interface tool you like to have for your command line applications.
29
- It contains elegant, simple and beautiful features that enhance your
30
- command line interfaces functionally and aesthetically.
25
+ version: 0.17.0
26
+ description: 'This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich,
27
+ lovely, natty user interface tool you like to have for your command line applications.
28
+ It contains elegant, simple and beautiful features that enhance your command line
29
+ interfaces functionally and aesthetically. '
31
30
  executables: []
32
31
  extensions: []
33
32
  extra_rdoc_files:
34
- - LICENSE
35
33
  - README.md
36
34
  files:
37
35
  - ".yardopts"
38
- - LICENSE
39
36
  - README.md
40
37
  - examples/24bit-colors.rb
41
38
  - examples/3bit-colors.rb
@@ -81,9 +78,11 @@ files:
81
78
  - lib/natty-ui/version.rb
82
79
  - lib/natty-ui/width_finder.rb
83
80
  - lib/natty_ui.rb
81
+ - natty-ui.gemspec
84
82
  homepage: https://codeberg.org/mblumtritt/natty-ui
85
83
  licenses:
86
- - BSD-3-Clause
84
+ - MIT
85
+ - Ruby
87
86
  metadata:
88
87
  source_code_uri: https://codeberg.org/mblumtritt/natty-ui
89
88
  bug_tracker_uri: https://codeberg.org/mblumtritt/natty-ui/issues
@@ -104,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
103
  - !ruby/object:Gem::Version
105
104
  version: '0'
106
105
  requirements: []
107
- rubygems_version: 3.6.9
106
+ rubygems_version: 3.7.2
108
107
  specification_version: 4
109
108
  summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
110
109
  natty user interface you like to have for your CLI.
data/LICENSE DELETED
@@ -1,28 +0,0 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2017-2025, Mike Blumtritt. All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.