natty-ui 0.11.1 → 0.12.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 +4 -4
- data/examples/8bit-colors.rb +3 -3
- data/examples/animate.rb +6 -6
- data/examples/progress.rb +8 -3
- data/lib/natty-ui/animation/binary.rb +1 -2
- data/lib/natty-ui/animation/default.rb +9 -13
- data/lib/natty-ui/animation/matrix.rb +0 -4
- data/lib/natty-ui/animation/type_writer.rb +5 -5
- data/lib/natty-ui/animation.rb +6 -6
- data/lib/natty-ui/ansi/constants.rb +6 -6
- data/lib/natty-ui/ansi_wrapper.rb +2 -6
- data/lib/natty-ui/frame.rb +53 -0
- data/lib/natty-ui/glyph.rb +64 -0
- data/lib/natty-ui/preload.rb +5 -2
- data/lib/natty-ui/spinner.rb +120 -0
- data/lib/natty-ui/text/east_asian_width.rb +2518 -1264
- data/lib/natty-ui/text.rb +3 -3
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/wrapper/ask.rb +1 -1
- data/lib/natty-ui/wrapper/framed.rb +3 -3
- data/lib/natty-ui/wrapper/list_in_columns.rb +1 -1
- data/lib/natty-ui/wrapper/message.rb +2 -2
- data/lib/natty-ui/wrapper/progress.rb +3 -21
- data/lib/natty-ui/wrapper/request.rb +1 -1
- data/lib/natty-ui/wrapper/table.rb +6 -9
- data/lib/natty-ui.rb +4 -64
- metadata +6 -3
data/lib/natty-ui/text.rb
CHANGED
@@ -42,8 +42,8 @@ module NattyUI
|
|
42
42
|
# works for UTF-8 chars only!
|
43
43
|
def char_width(char)
|
44
44
|
ord = char.ord
|
45
|
-
return
|
46
|
-
return 1 if ord
|
45
|
+
return WIDTH_CONTROL_CHARS[ord] || 2 if ord < 0x20
|
46
|
+
return 1 if ord < 0xa1
|
47
47
|
size = EastAsianWidth[ord]
|
48
48
|
return @ambiguous_char_width if size == -1
|
49
49
|
if size == 1 && char.size >= 2
|
@@ -158,7 +158,7 @@ module NattyUI
|
|
158
158
|
UTF_8 = Encoding::UTF_8
|
159
159
|
BBCODE = /(?:\[((?~[\[\]]))\])/
|
160
160
|
WIDTH_SCANNER = /\G(?:(\1)|(\2)|(#{Ansi::CSI})|(#{Ansi::OSC})|(\X))/
|
161
|
-
|
161
|
+
WIDTH_CONTROL_CHARS = {
|
162
162
|
0x00 => 0,
|
163
163
|
0x01 => 1,
|
164
164
|
0x02 => 1,
|
data/lib/natty-ui/version.rb
CHANGED
data/lib/natty-ui/wrapper/ask.rb
CHANGED
@@ -11,12 +11,12 @@ module NattyUI
|
|
11
11
|
# {Wrapper::Element#close}.
|
12
12
|
#
|
13
13
|
# @param [Array<#to_s>] args more objects to print
|
14
|
-
# @param [
|
14
|
+
# @param [Symbol, String] type frame type; see {NattyUI::Frame}
|
15
15
|
# @yieldparam [Wrapper::Framed] framed the created section
|
16
16
|
# @return [Object] the result of the code block
|
17
17
|
# @return [Wrapper::Framed] itself, when no code block is given
|
18
|
-
def framed(*args, type: :
|
19
|
-
_section(:Framed, args, type: NattyUI
|
18
|
+
def framed(*args, type: :default, &block)
|
19
|
+
_section(:Framed, args, type: NattyUI::Frame[type], &block)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -9,7 +9,7 @@ module NattyUI
|
|
9
9
|
#
|
10
10
|
# @param [#to_s] title object to print as section title
|
11
11
|
# @param [Array<#to_s>] args more objects to print
|
12
|
-
# @param [#to_s] glyph
|
12
|
+
# @param [Symbol, #to_s] glyph used for the title; see {NattyUI::Glyph}
|
13
13
|
# @yieldparam [Wrapper::Message] message the created section
|
14
14
|
# @return [Object] the result of the code block
|
15
15
|
# @return [Wrapper::Message] itself, when no code block is given
|
@@ -94,7 +94,7 @@ module NattyUI
|
|
94
94
|
protected
|
95
95
|
|
96
96
|
def initialize(parent, title:, glyph:)
|
97
|
-
glyph = NattyUI
|
97
|
+
glyph = NattyUI::Glyph[glyph]
|
98
98
|
prefix_width = Text.width(glyph) + 1
|
99
99
|
super(
|
100
100
|
parent,
|
@@ -18,11 +18,9 @@ module NattyUI
|
|
18
18
|
#
|
19
19
|
# @param [#to_s] title object to print as progress title
|
20
20
|
# @param [#to_f] max_value maximum value of the progress
|
21
|
-
# @param [
|
22
|
-
# :snake, :swap, :triangles, :vintage, #to_s] spinner type of spinner or
|
23
|
-
# spinner elements
|
21
|
+
# @param [Symbol, #to_a, #to_s] spinner spinner type; see {NattyUI::Spinner}
|
24
22
|
# @return [Wrapper::Progress] the created progress element
|
25
|
-
def progress(title, max_value: nil, spinner: :
|
23
|
+
def progress(title, max_value: nil, spinner: :default)
|
26
24
|
_element(:Progress, title, max_value, spinner)
|
27
25
|
end
|
28
26
|
end
|
@@ -42,26 +40,10 @@ module NattyUI
|
|
42
40
|
@final_text = [title]
|
43
41
|
@max_value = [0, max_value.to_f].max if max_value
|
44
42
|
@value = @progress = 0
|
45
|
-
draw(title,
|
43
|
+
draw(title, spinner)
|
46
44
|
self
|
47
45
|
end
|
48
46
|
|
49
|
-
SPINNER = {
|
50
|
-
bar: '▁▂▃▄▅▆▇█▇▆▅▄▃▂',
|
51
|
-
blink: '■□▪▫',
|
52
|
-
blocks: '▖▘▝▗',
|
53
|
-
braile: '⣷⣯⣟⡿⢿⣻⣽⣾',
|
54
|
-
braile_reverse: '⡿⣟⣯⣷⣾⣽⣻⢿',
|
55
|
-
circle: '◐◓◑◒',
|
56
|
-
colors: '🟨🟧🟥🟦🟪🟩',
|
57
|
-
pulse: '•✺◉●◉✺',
|
58
|
-
snake: '⠁⠉⠙⠸⢰⣠⣄⡆⠇⠃',
|
59
|
-
swap: '㊂㊀㊁',
|
60
|
-
triangles: '◢◣◤◥',
|
61
|
-
vintage: '-\\|/'
|
62
|
-
}.compare_by_identity.freeze
|
63
|
-
private_constant :SPINNER
|
64
|
-
|
65
47
|
def draw(title, _spinner)
|
66
48
|
(wrapper.stream << @parent.prefix << "➔ #{title} ").flush
|
67
49
|
end
|
@@ -7,14 +7,11 @@ module NattyUI
|
|
7
7
|
#
|
8
8
|
# Table view of data.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
# :double, :heavy, :semi, :simple
|
12
|
-
#
|
13
|
-
# @overload table(*args, type: simple, expand: false)
|
10
|
+
# @overload table(*args, type: :default, expand: false)
|
14
11
|
# Display the given arrays as rows of a table.
|
15
12
|
#
|
16
13
|
# @param [#map<#map<#to_s>>] args one or more arrays representing rows of the table
|
17
|
-
# @param [Symbol] type frame type
|
14
|
+
# @param [Symbol, String] type frame type; see {NattyUI::Frame}
|
18
15
|
# @param [false, true. :equal] expand
|
19
16
|
#
|
20
17
|
# @example
|
@@ -33,10 +30,10 @@ module NattyUI
|
|
33
30
|
# # ───────┼───────┼───────────
|
34
31
|
# # kiwi │ 1.5$ │ Newzeeland
|
35
32
|
#
|
36
|
-
# @overload table(type:
|
33
|
+
# @overload table(type: :default, expand: false)
|
37
34
|
# Construct and display a table.
|
38
35
|
#
|
39
|
-
# @param [Symbol] type frame type
|
36
|
+
# @param [Symbol, String] type frame type; see {NattyUI::Frame}
|
40
37
|
# @param [false, true. :equal] expand
|
41
38
|
#
|
42
39
|
# @example
|
@@ -58,8 +55,8 @@ module NattyUI
|
|
58
55
|
#
|
59
56
|
# @yield [Table] table construction helper
|
60
57
|
# @return [Wrapper::Section, Wrapper] it's parent object
|
61
|
-
def table(*table, type: :
|
62
|
-
type = NattyUI
|
58
|
+
def table(*table, type: :default, expand: false)
|
59
|
+
type = NattyUI::Frame[type]
|
63
60
|
table = Table.create(*table)
|
64
61
|
yield(table) if block_given?
|
65
62
|
_element(:Table, table, type, expand)
|
data/lib/natty-ui.rb
CHANGED
@@ -135,34 +135,6 @@ module NattyUI
|
|
135
135
|
nil
|
136
136
|
end
|
137
137
|
|
138
|
-
# @return [Array<Symbol>] available glyph names
|
139
|
-
def glyph_names = GLYPH.keys
|
140
|
-
|
141
|
-
# Get a pre-defined glyph.
|
142
|
-
#
|
143
|
-
# @param [Symbol] name glyph name
|
144
|
-
# @return [String] the glyph
|
145
|
-
# @return [nil] when glyph is not defined
|
146
|
-
def glyph(name) = GLYPH[name]
|
147
|
-
|
148
|
-
# @return [Array<Symbol>] available frame names
|
149
|
-
def frame_names = FRAME.keys
|
150
|
-
|
151
|
-
# Get a frame definition.
|
152
|
-
#
|
153
|
-
# @param [Symbol] name frame type name
|
154
|
-
# @return [String] the frame definition
|
155
|
-
# @raise [ArgumentError] when an invalid name is specified
|
156
|
-
def frame(name)
|
157
|
-
if name.is_a?(Symbol)
|
158
|
-
ret = FRAME[name] and return ret
|
159
|
-
elsif name.is_a?(String)
|
160
|
-
return name if name.size == 11
|
161
|
-
return name * 11 if name.size == 1
|
162
|
-
end
|
163
|
-
raise(ArgumentError, "invalid frame type - #{name.inspect}")
|
164
|
-
end
|
165
|
-
|
166
138
|
private
|
167
139
|
|
168
140
|
def wrapper_class(stream, ansi)
|
@@ -188,44 +160,12 @@ module NattyUI
|
|
188
160
|
|
189
161
|
dir = __dir__
|
190
162
|
autoload(:Animation, File.join(dir, 'natty-ui', 'animation'))
|
163
|
+
autoload(:Frame, File.join(dir, 'natty-ui', 'frame'))
|
164
|
+
autoload(:Glyph, File.join(dir, 'natty-ui', 'glyph'))
|
191
165
|
autoload(:KEY_MAP, File.join(dir, 'natty-ui', 'key_map'))
|
166
|
+
autoload(:Spinner, File.join(dir, 'natty-ui', 'spinner'))
|
192
167
|
|
193
|
-
|
194
|
-
default: "#{Ansi[:bold, 255]}•#{Ansi::RESET}",
|
195
|
-
point: "#{Ansi[0x27]}◉#{Ansi::RESET}",
|
196
|
-
information: "#{Ansi[:bold, 119]}𝒊#{Ansi::RESET}",
|
197
|
-
warning: "#{Ansi[:bold, 221]}!#{Ansi::RESET}",
|
198
|
-
error: "#{Ansi[:bold, 208]}𝙓#{Ansi::RESET}",
|
199
|
-
completed: "#{Ansi[:bold, 82]}✓#{Ansi::RESET}",
|
200
|
-
failed: "#{Ansi[:bold, 196]}𝑭#{Ansi::RESET}",
|
201
|
-
task: "#{Ansi[:bold, 39]}➔#{Ansi::RESET}",
|
202
|
-
query: "#{Ansi[:bold, 39]}▸#{Ansi::RESET}"
|
203
|
-
}.compare_by_identity.freeze
|
204
|
-
|
205
|
-
# GLYPH = {
|
206
|
-
# default: '●',
|
207
|
-
# information: '🅸 ',
|
208
|
-
# warning: '🆆 ',
|
209
|
-
# error: '🅴 ',
|
210
|
-
# completed: '✓',
|
211
|
-
# failed: '🅵 ',
|
212
|
-
# task: '➔',
|
213
|
-
# query: '🆀 '
|
214
|
-
# }.compare_by_identity.freeze
|
215
|
-
|
216
|
-
FRAME = {
|
217
|
-
rounded: '╭╮╰╯│─┼┬┴├┤',
|
218
|
-
simple: '┌┐└┘│─┼┬┴├┤',
|
219
|
-
heavy: '┏┓┗┛┃━╋┳┻┣┫',
|
220
|
-
double: '╔╗╚╝║═╬╦╩╠╣',
|
221
|
-
semi: '╒╕╘╛│═╪╤╧╞╡',
|
222
|
-
semi2: '╓╖╙╜│─╫╥╨╟╢',
|
223
|
-
rows: ' ── ',
|
224
|
-
cols: ' │ │ ',
|
225
|
-
undecorated: ' '
|
226
|
-
}.compare_by_identity.freeze
|
227
|
-
|
228
|
-
private_constant :Animation, :KEY_MAP, :GLYPH, :FRAME
|
168
|
+
private_constant :Animation, :KEY_MAP
|
229
169
|
|
230
170
|
@element = StdOut
|
231
171
|
self.in_stream = STDIN
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natty-ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
|
@@ -49,8 +49,11 @@ files:
|
|
49
49
|
- lib/natty-ui/ansi.rb
|
50
50
|
- lib/natty-ui/ansi/constants.rb
|
51
51
|
- lib/natty-ui/ansi_wrapper.rb
|
52
|
+
- lib/natty-ui/frame.rb
|
53
|
+
- lib/natty-ui/glyph.rb
|
52
54
|
- lib/natty-ui/key_map.rb
|
53
55
|
- lib/natty-ui/preload.rb
|
56
|
+
- lib/natty-ui/spinner.rb
|
54
57
|
- lib/natty-ui/text.rb
|
55
58
|
- lib/natty-ui/text/east_asian_width.rb
|
56
59
|
- lib/natty-ui/version.rb
|
@@ -96,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
99
|
- !ruby/object:Gem::Version
|
97
100
|
version: '0'
|
98
101
|
requirements: []
|
99
|
-
rubygems_version: 3.5.
|
102
|
+
rubygems_version: 3.5.17
|
100
103
|
signing_key:
|
101
104
|
specification_version: 4
|
102
105
|
summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely, natty
|