natty-ui 0.5.1 → 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 +4 -4
- data/README.md +13 -33
- data/examples/basic.rb +2 -0
- data/examples/colors.rb +2 -0
- data/lib/natty-ui/ansi_wrapper.rb +15 -15
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/wrapper/element.rb +2 -6
- data/lib/natty-ui/wrapper/features.rb +1 -5
- data/lib/natty-ui/wrapper/framed.rb +3 -2
- data/lib/natty-ui/wrapper/heading.rb +5 -5
- data/lib/natty-ui/wrapper/message.rb +6 -6
- data/lib/natty-ui/wrapper/progress.rb +1 -1
- data/lib/natty-ui/wrapper/query.rb +1 -1
- data/lib/natty-ui/wrapper/section.rb +4 -6
- data/lib/natty-ui/wrapper/task.rb +2 -2
- data/lib/natty-ui/wrapper.rb +1 -1
- data/lib/natty-ui.rb +3 -23
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9531c1f73a1d9ca8f9a09f279eb3939f8ed0f37bc940d5f50aa479edc1b38ca
|
4
|
+
data.tar.gz: d380394514fb92fe411cfbfcf1c7ba6bd95c9388ecfcdb31752ea47df8efeb9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '086c5832e6c811a5fab7f2e4866018d4cd6cc898af2866283e19b71330f4d6d05a5f17089bf5ac383cb26e5006bce66ca37ba63baef4e9ff7444bb1e44ca0cc7'
|
7
|
+
data.tar.gz: 4d13067a100b10d09565fa2cf95bdd39d40c5c31e25fa5971d666e272d2e7ebbfd73b7188f12e6bc41bfc168b1a8864da6705636f70204185b8daf34ef614e00
|
data/README.md
CHANGED
@@ -40,29 +40,13 @@ UI.framed 'Text Below In Frame' do |framed|
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
-
or use progression displays like progress bars
|
43
|
+
or use progression displays like progress bars.
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
### But there is more!
|
48
|
-
|
49
|
-
Have a look at the [examples](./examples/) directory to get an impression of the current feature set.
|
50
|
-
|
51
|
-
```sh
|
52
|
-
ruby ./examples/basic.rb
|
53
|
-
```
|
54
|
-
|
55
|
-
or see the non-ANSI version
|
56
|
-
|
57
|
-
```sh
|
58
|
-
NO_COLOR=1 ruby ./examples/basic.rb
|
59
|
-
```
|
45
|
+
🚀 There are much more [features](https://rubydoc.info/gems/natty-ui/NattyUI/Features)!
|
60
46
|
|
61
|
-
|
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).
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
NattyUI follows the [NO_COLOR convention](https://no-color.org).
|
49
|
+

|
66
50
|
|
67
51
|
## Installation
|
68
52
|
|
@@ -84,32 +68,28 @@ After that you only need one line of code to have everything together
|
|
84
68
|
require 'natty-ui'
|
85
69
|
```
|
86
70
|
|
87
|
-
##
|
88
|
-
|
89
|
-
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
|
90
72
|
|
91
|
-
|
73
|
+
You can execute the examples by
|
92
74
|
|
93
|
-
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
require 'unicode/emoji'
|
97
|
-
require 'natty-ui'
|
75
|
+
```sh
|
76
|
+
ruby ./examples/basic.rb
|
98
77
|
```
|
99
78
|
|
100
|
-
|
79
|
+
or see the non-ANSI version
|
101
80
|
|
102
81
|
```sh
|
103
|
-
|
82
|
+
NO_COLOR=1 ruby ./examples/basic.rb
|
104
83
|
```
|
105
84
|
|
106
|
-
|
85
|
+
## NO_COLOR Convention
|
86
|
+
|
87
|
+
NattyUI follows the [NO_COLOR convention](https://no-color.org).
|
107
88
|
|
108
89
|
## TODO
|
109
90
|
|
110
91
|
Since I did not complete the tests and not all my ideas are already implemented I have this Todo list:
|
111
92
|
|
112
|
-
- add samples to README
|
113
93
|
- add more samples to help
|
114
94
|
- add more tests
|
115
95
|
- simple prompt
|
data/examples/basic.rb
CHANGED
data/examples/colors.rb
CHANGED
@@ -46,16 +46,16 @@ module NattyUI
|
|
46
46
|
|
47
47
|
def title_attr(str, symbol)
|
48
48
|
color = COLORS[symbol]
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
{
|
50
|
+
prefix:
|
51
|
+
if color
|
52
52
|
"#{Ansi[:bold, :italic, color]}#{str}" \
|
53
|
-
"#{Ansi[:reset, :bold, color]} "
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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 =
|
data/lib/natty-ui/version.rb
CHANGED
@@ -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
|
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
|
|
@@ -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
|
-
*
|
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
|
-
|
37
|
+
_section(
|
38
38
|
@parent,
|
39
39
|
:Message,
|
40
40
|
@final_text,
|
data/lib/natty-ui/wrapper.rb
CHANGED
data/lib/natty-ui.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
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
|
-
|
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.
|
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-
|
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
|