natty-ui 0.5.0 → 0.5.2

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: a4e46711be1871e4ad647f6fec2312d81473cd52d660c3a157120a6884144936
4
- data.tar.gz: a58d2ffef5ff47034d3c1582e18a6e469ac39784d10a30292ac85c4134444ea6
3
+ metadata.gz: b9531c1f73a1d9ca8f9a09f279eb3939f8ed0f37bc940d5f50aa479edc1b38ca
4
+ data.tar.gz: d380394514fb92fe411cfbfcf1c7ba6bd95c9388ecfcdb31752ea47df8efeb9b
5
5
  SHA512:
6
- metadata.gz: 9b1640b52328b2d55ba8568dfe99bca63fba659300bcd11fcc0f05e46dadfa5096cd2d01d97d8f2cd33330e67eca311722587441d60da38ac75db97ddfd32d8d
7
- data.tar.gz: 2ba0659ba2823d47c2d8b33f09ec5d0be967c0bcef7354cea2e79d9c7bd68795d0995c8faeb9c762079739332b5835c89703f360290a712120aac67afd05a097
6
+ metadata.gz: '086c5832e6c811a5fab7f2e4866018d4cd6cc898af2866283e19b71330f4d6d05a5f17089bf5ac383cb26e5006bce66ca37ba63baef4e9ff7444bb1e44ca0cc7'
7
+ data.tar.gz: 4d13067a100b10d09565fa2cf95bdd39d40c5c31e25fa5971d666e272d2e7ebbfd73b7188f12e6bc41bfc168b1a8864da6705636f70204185b8daf34ef614e00
data/README.md CHANGED
@@ -1,14 +1,10 @@
1
- # NattyUI
1
+ # NattyUI ![version](https://img.shields.io/gem/v/natty-ui?label=)
2
2
 
3
3
  This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely, natty user interface you like to have for your command line interfaces (CLI).
4
4
 
5
- <!-- TODO: ![version](https://img.shields.io/gem/v/natty-ui?label=) -->
6
-
7
- <!-- TODO:
8
5
  - Gem: [rubygems.org](https://rubygems.org/gems/natty-ui)
9
6
  - Source: [github.com](https://github.com/mblumtritt/natty-ui)
10
7
  - Help: [rubydoc.info](https://rubydoc.info/gems/natty-ui/NattyUI)
11
- -->
12
8
 
13
9
  ## Description
14
10
 
@@ -44,31 +40,13 @@ UI.framed 'Text Below In Frame' do |framed|
44
40
  end
45
41
  ```
46
42
 
47
- or use progression displays like progress bars and much much more!
48
-
49
- ![illustration](https://raw.githubusercontent.com/mblumtritt/natty-ui/main/examples/illustration.svg)
50
-
51
- ### But there is more!
52
-
53
- Have a look at the [examples](./examples/) directory to get an impression of the current feature set.
54
-
55
- ```sh
56
- ruby ./examples/basic.rb
57
- ```
58
-
59
- or see the non-ANSI version
43
+ or use progression displays like progress bars.
60
44
 
61
- ```sh
62
- NO_COLOR=1 ruby ./examples/basic.rb
63
- ```
45
+ 🚀 There are much more [features](https://rubydoc.info/gems/natty-ui/NattyUI/Features)!
64
46
 
65
- <!-- TODO:
66
- link to NattyUI Features for more features!
67
- -->
47
+ 📕 See the [online help](https://rubydoc.info/gems/natty-ui/NattyUI) for more details or have a look at the [examples](./examples/) directory to get an impression of the current feature set (see also XXX).
68
48
 
69
- ### NO_COLOR Convention
70
-
71
- NattyUI follows the [NO_COLOR convention](https://no-color.org).
49
+ ![illustration](https://raw.githubusercontent.com/mblumtritt/natty-ui/main/examples/illustration.svg)
72
50
 
73
51
  ## Installation
74
52
 
@@ -90,32 +68,28 @@ After that you only need one line of code to have everything together
90
68
  require 'natty-ui'
91
69
  ```
92
70
 
93
- ## Unicode Support
94
-
95
- Unicode is generally supported. This means that for the calculation of screen outputs the different width of characters is considered. For this the wonderful Gem [unicode/display_width](https://github.com/janlelis/unicode-display_width) is used.
71
+ ## Run Examples
96
72
 
97
- To be able to use Unicode characters that consist of multiple combinations (like some emoji), you have to explicitly load the Gem unicode/emoji _before_ NattyUI. It is not included automatically, because in most cases it is not needed (and we can save the overhead most of the time).
73
+ You can execute the examples by
98
74
 
99
- If you need the full beauty of Unicode just load it in that order:
100
-
101
- ```ruby
102
- require 'unicode/emoji'
103
- require 'natty-ui'
75
+ ```sh
76
+ ruby ./examples/basic.rb
104
77
  ```
105
78
 
106
- **Hint**: The compromise of not automatically supporting emojis results from the fact that not all terminals can output all emojis correctly. You can easily check this yourself by
79
+ or see the non-ANSI version
107
80
 
108
81
  ```sh
109
- echo "👨‍👩‍👦 👩‍❤️‍👨"
82
+ NO_COLOR=1 ruby ./examples/basic.rb
110
83
  ```
111
84
 
112
- in your terminal window.
85
+ ## NO_COLOR Convention
86
+
87
+ NattyUI follows the [NO_COLOR convention](https://no-color.org).
113
88
 
114
89
  ## TODO
115
90
 
116
91
  Since I did not complete the tests and not all my ideas are already implemented I have this Todo list:
117
92
 
118
- - add samples to README
119
93
  - add more samples to help
120
94
  - add more tests
121
95
  - simple prompt
data/examples/basic.rb CHANGED
@@ -5,6 +5,8 @@ require_relative '../lib/natty-ui'
5
5
 
6
6
  UI = NattyUI::StdOut
7
7
 
8
+ UI.space
9
+
8
10
  UI.h1 'NattyUI Basic Feature Demo', <<~TEXT
9
11
 
10
12
  This is a short demo of the basic features of [[i117 bold]]NattyUI[[/]].
data/examples/colors.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # require 'natty-ui'
2
4
  require_relative '../lib/natty-ui'
3
5
 
@@ -46,16 +46,16 @@ module NattyUI
46
46
 
47
47
  def title_attr(str, symbol)
48
48
  color = COLORS[symbol]
49
- if color
50
- {
51
- prefix:
49
+ {
50
+ prefix:
51
+ if color
52
52
  "#{Ansi[:bold, :italic, color]}#{str}" \
53
- "#{Ansi[:reset, :bold, color]} ",
54
- suffix: Ansi.reset
55
- }
56
- else
57
- { prefix: "#{Ansi[:bold, 231]}#{str} ", suffix: Ansi.reset }
58
- end
53
+ "#{Ansi[:reset, :bold, color]} "
54
+ else
55
+ "#{Ansi[:bold, 231]}#{str} "
56
+ end,
57
+ suffix: Ansi.reset
58
+ }
59
59
  end
60
60
 
61
61
  COLORS = {
@@ -167,12 +167,6 @@ module NattyUI
167
167
  end
168
168
  end
169
169
 
170
- TITLE_PREFIX = "#{Ansi[:bold, :italic, 117]}➔#{Ansi[:reset, 117]} ".freeze
171
- INDICATOR_ATTRIBUTE = Ansi[:bold, 220].freeze
172
- BAR_COLOR = Ansi[39, 295].freeze
173
- BAR_BACK = Ansi[236, 492].freeze
174
- BAR_INK = Ansi[:bold, 255, :on_default].freeze
175
-
176
170
  def draw_final = (wrapper.stream << Ansi.line_clear).flush
177
171
 
178
172
  def redraw
@@ -194,6 +188,12 @@ module NattyUI
194
188
  )
195
189
  }"
196
190
  end
191
+
192
+ TITLE_PREFIX = "#{Ansi[:bold, :italic, 117]}➔#{Ansi[:reset, 117]} ".freeze
193
+ INDICATOR_ATTRIBUTE = Ansi[:bold, 220].freeze
194
+ BAR_COLOR = Ansi[39, 295].freeze
195
+ BAR_BACK = Ansi[236, 492].freeze
196
+ BAR_INK = Ansi[:bold, 255, :on_default].freeze
197
197
  end
198
198
 
199
199
  PAGE_BEGIN =
@@ -2,5 +2,5 @@
2
2
 
3
3
  module NattyUI
4
4
  # @return [String] the version number of the gem
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.2'
6
6
  end
@@ -32,9 +32,7 @@ module NattyUI
32
32
  private :_to_s
33
33
 
34
34
  # @!visibility private
35
- def inspect
36
- "#{_to_s[..-2]} status=#{@status}}}>"
37
- end
35
+ def inspect = "#{_to_s[..-2]} status=#{@status}}}>"
38
36
 
39
37
  protected
40
38
 
@@ -49,9 +47,7 @@ module NattyUI
49
47
  @wrapper
50
48
  end
51
49
 
52
- def initialize(parent)
53
- @parent = parent
54
- end
50
+ def initialize(parent) = (@parent = parent)
55
51
 
56
52
  def _close(state)
57
53
  return self if @status
@@ -11,11 +11,7 @@ module NattyUI
11
11
  wrapper.class.const_get(type).__send__(:new, self).__send__(:_call, *args)
12
12
  end
13
13
 
14
- def _section(type, args, **opts, &block)
15
- __section(self, type, args, **opts, &block)
16
- end
17
-
18
- def __section(owner, type, args, **opts, &block)
14
+ def _section(owner, type, args, **opts, &block)
19
15
  sec = wrapper.class.const_get(type).__send__(:new, owner, **opts)
20
16
  sec.puts(*args) if args && !args.empty?
21
17
  block ? sec.__send__(:_call, &block) : sec
@@ -7,7 +7,8 @@ module NattyUI
7
7
  # Creates frame-enclosed section with a highlighted `title` and
8
8
  # prints given additional arguments as lines into the section.
9
9
  #
10
- # When no block is given, the section must be closed, see {Section#close}.
10
+ # When no block is given, the section must be closed, see
11
+ # {Wrapper::Element#close}.
11
12
  #
12
13
  # @param [#to_s] title object to print as section title
13
14
  # @param [Array<#to_s>] args more objects to print
@@ -17,7 +18,7 @@ module NattyUI
17
18
  # @return [Object] the result of the code block
18
19
  # @return [Wrapper::Framed] itself, when no code block is given
19
20
  def framed(title, *args, type: :rounded, &block)
20
- _section(:Framed, args, title: title, type: type, &block)
21
+ _section(self, :Framed, args, title: title, type: type, &block)
21
22
  end
22
23
  end
23
24
 
@@ -11,7 +11,7 @@ module NattyUI
11
11
  # @return [Object] the result of the code block
12
12
  # @return [Wrapper::Heading] itself, when no code block is given
13
13
  def h1(title, *args, &block)
14
- _section(:Heading, args, title: title, weight: 1, &block)
14
+ _section(self, :Heading, args, title: title, weight: 1, &block)
15
15
  end
16
16
 
17
17
  # Creates section with a H2 title.
@@ -20,7 +20,7 @@ module NattyUI
20
20
  # @yieldparam (see #h1)
21
21
  # @return (see #h1)
22
22
  def h2(title, *args, &block)
23
- _section(:Heading, args, title: title, weight: 2, &block)
23
+ _section(self, :Heading, args, title: title, weight: 2, &block)
24
24
  end
25
25
 
26
26
  # Creates section with a H3 title.
@@ -29,7 +29,7 @@ module NattyUI
29
29
  # @yieldparam (see #h1)
30
30
  # @return (see #h1)
31
31
  def h3(title, *args, &block)
32
- _section(:Heading, args, title: title, weight: 3, &block)
32
+ _section(self, :Heading, args, title: title, weight: 3, &block)
33
33
  end
34
34
 
35
35
  # Creates section with a H4 title.
@@ -38,7 +38,7 @@ module NattyUI
38
38
  # @yieldparam (see #h1)
39
39
  # @return (see #h1)
40
40
  def h4(title, *args, &block)
41
- _section(:Heading, args, title: title, weight: 4, &block)
41
+ _section(self, :Heading, args, title: title, weight: 4, &block)
42
42
  end
43
43
 
44
44
  # Creates section with a H5 title.
@@ -47,7 +47,7 @@ module NattyUI
47
47
  # @yieldparam (see #h1)
48
48
  # @return (see #h1)
49
49
  def h5(title, *args, &block)
50
- _section(:Heading, args, title: title, weight: 5, &block)
50
+ _section(self, :Heading, args, title: title, weight: 5, &block)
51
51
  end
52
52
  end
53
53
 
@@ -14,7 +14,7 @@ module NattyUI
14
14
  # @return [Object] the result of the code block
15
15
  # @return [Wrapper::Message] itself, when no code block is given
16
16
  def message(title, *args, symbol: :default, &block)
17
- _section(:Message, args, title: title, symbol: symbol, &block)
17
+ _section(self, :Message, args, title: title, symbol: symbol, &block)
18
18
  end
19
19
  alias msg message
20
20
 
@@ -26,7 +26,7 @@ module NattyUI
26
26
  # @yieldparam (see #message)
27
27
  # @return (see #message)
28
28
  def information(title, *args, &block)
29
- _section(:Message, args, title: title, symbol: :information, &block)
29
+ _section(self, :Message, args, title: title, symbol: :information, &block)
30
30
  end
31
31
  alias info information
32
32
 
@@ -37,7 +37,7 @@ module NattyUI
37
37
  # @yieldparam (see #message)
38
38
  # @return (see #message)
39
39
  def warning(title, *args, &block)
40
- _section(:Message, args, title: title, symbol: :warning, &block)
40
+ _section(self, :Message, args, title: title, symbol: :warning, &block)
41
41
  end
42
42
  alias warn warning
43
43
 
@@ -48,7 +48,7 @@ module NattyUI
48
48
  # @yieldparam (see #message)
49
49
  # @return (see #message)
50
50
  def error(title, *args, &block)
51
- _section(:Message, args, title: title, symbol: :error, &block)
51
+ _section(self, :Message, args, title: title, symbol: :error, &block)
52
52
  end
53
53
  alias err error
54
54
 
@@ -61,7 +61,7 @@ module NattyUI
61
61
  # @yieldparam (see #message)
62
62
  # @return (see #message)
63
63
  def completed(title, *args, &block)
64
- _section(:Message, args, title: title, symbol: :completed, &block)
64
+ _section(self, :Message, args, title: title, symbol: :completed, &block)
65
65
  end
66
66
  alias done completed
67
67
  alias ok completed
@@ -76,7 +76,7 @@ module NattyUI
76
76
  # @yieldparam (see #message)
77
77
  # @return (see #message)
78
78
  def failed(title, *args, &block)
79
- _section(:Message, args, title: title, symbol: :failed, &block)
79
+ _section(self, :Message, args, title: title, symbol: :failed, &block)
80
80
  end
81
81
  end
82
82
 
@@ -14,7 +14,7 @@ module NattyUI
14
14
  # @param [##to_f] max_value maximum value of the progress
15
15
  # @return [Wrapper::Progress] the created progress element
16
16
  def progress(title, max_value: nil)
17
- _section(:Progress, nil, title: title, max_value: max_value)
17
+ _section(self, :Progress, nil, title: title, max_value: max_value)
18
18
  end
19
19
  end
20
20
 
@@ -49,7 +49,7 @@ module NattyUI
49
49
  choices = grab(choices, kw_choices)
50
50
  return if choices.empty?
51
51
  wrapper.temporary do
52
- __section(
52
+ _section(
53
53
  @parent,
54
54
  :Message,
55
55
  choices.map { |k, v| "#{k} #{v}" },
@@ -12,7 +12,7 @@ module NattyUI
12
12
  # @return [Object] the result of the code block
13
13
  # @return [Wrapper::Section] itself, when no code block is given
14
14
  def section(*args, &block)
15
- _section(:Section, args, prefix: ' ', suffix: ' ', &block)
15
+ _section(self, :Section, args, prefix: ' ', suffix: ' ', &block)
16
16
  end
17
17
  alias sec section
18
18
 
@@ -23,7 +23,7 @@ module NattyUI
23
23
  # @yieldparam (see #section)
24
24
  # @return (see #section)
25
25
  def quote(*args, &block)
26
- _section(:Section, args, prefix: '▍ ', prefix_attr: 39, &block)
26
+ _section(self, :Section, args, prefix: '▍ ', prefix_attr: 39, &block)
27
27
  end
28
28
  end
29
29
 
@@ -66,7 +66,7 @@ module NattyUI
66
66
  # @return [Section] itself
67
67
  def space(lines = 1)
68
68
  @parent.puts(
69
- *Array.new([lines.to_i, 1].max),
69
+ "\n" * ([lines.to_i, 1].max - 1),
70
70
  prefix: @prefix,
71
71
  suffix: @suffix
72
72
  )
@@ -86,9 +86,7 @@ module NattyUI
86
86
  #
87
87
  # @yield [Section] itself
88
88
  # @return [Object] block result
89
- def temporary
90
- block_given? ? yield(self) : self
91
- end
89
+ def temporary = block_given? ? yield(self) : self
92
90
 
93
91
  protected
94
92
 
@@ -15,7 +15,7 @@ module NattyUI
15
15
  # @return [Object] the result of the code block
16
16
  # @return [Wrapper::Task] itself, when no code block is given
17
17
  def task(title, *args, &block)
18
- _section(:Task, args, title: title, &block)
18
+ _section(self, :Task, args, title: title, &block)
19
19
  end
20
20
  end
21
21
 
@@ -34,7 +34,7 @@ module NattyUI
34
34
  @status = :completed if @status == :closed
35
35
  @temp.call
36
36
  end
37
- __section(
37
+ _section(
38
38
  @parent,
39
39
  :Message,
40
40
  @final_text,
@@ -77,7 +77,7 @@ module NattyUI
77
77
  # @return [Wrapper] itself
78
78
  def space(lines = 1)
79
79
  lines = [lines.to_i, 1].max
80
- @stream.puts(*Array.new(lines))
80
+ @stream << ("\n" * lines)
81
81
  @lines_written += lines
82
82
  @stream.flush
83
83
  self
data/lib/natty-ui.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'unicode/display_width'
3
+ require 'reline'
4
4
  require_relative 'natty-ui/wrapper'
5
5
  require_relative 'natty-ui/ansi_wrapper'
6
6
 
@@ -71,7 +71,7 @@ module NattyUI
71
71
  # @return ]String] edited string
72
72
  def embellish(str)
73
73
  str = str.to_s
74
- return '' if str.empty?
74
+ return +'' if str.empty?
75
75
  reset = false
76
76
  ret =
77
77
  str.gsub(/(\[\[((?~\]\]))\]\])/) do
@@ -111,10 +111,7 @@ module NattyUI
111
111
  # @return [Integer] the display size
112
112
  def display_width(str)
113
113
  str = str.to_s
114
- return 0 if str.empty?
115
- ret = Unicode::DisplayWidth.of(str, 1)
116
- ret -= emoji_extra_width_of(str) if defined?(Unicode::Emoji)
117
- [ret, 0].max
114
+ str.empty? ? 0 : Reline::Unicode.calculate_width(str)
118
115
  end
119
116
 
120
117
  private
@@ -125,17 +122,6 @@ module NattyUI
125
122
  stream.tty? ? AnsiWrapper : Wrapper
126
123
  end
127
124
 
128
- def emoji_extra_width_of(string)
129
- ret = 0
130
- string.scan(Unicode::Emoji::REGEX) do |emoji|
131
- ret += 2 * emoji.scan(EMOJI_MODIFIER_REGEX).size
132
- emoji.scan(EMOKI_ZWJ_REGEX) do |zwj_succ|
133
- ret += Unicode::DisplayWidth.of(zwj_succ, 1, {})
134
- end
135
- end
136
- ret
137
- end
138
-
139
125
  def stderr_is_stdout?
140
126
  STDOUT.tty? && STDERR.tty? && STDOUT.pos == STDERR.pos
141
127
  rescue IOError, SystemCallError
@@ -143,12 +129,6 @@ module NattyUI
143
129
  end
144
130
  end
145
131
 
146
- if defined?(Unicode::Emoji)
147
- EMOJI_MODIFIER_REGEX = /[#{Unicode::Emoji::EMOJI_MODIFIERS.pack('U*')}]/
148
- EMOKI_ZWJ_REGEX = /(?<=#{[Unicode::Emoji::ZWJ].pack('U')})./
149
- private_constant :EMOJI_MODIFIER_REGEX, :EMOKI_ZWJ_REGEX
150
- end
151
-
152
132
  # Instance for standard output.
153
133
  StdOut = new(STDOUT)
154
134
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natty-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-09 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: unicode-display_width
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '2.5'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '2.5'
11
+ date: 2023-11-10 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: |
28
14
  This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
29
15
  natty user interface you like to have for your command line interfaces