natty-ui 0.27.0 → 0.29.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 +2 -2
- data/examples/elements.rb +6 -6
- data/examples/examples.rb +7 -6
- data/examples/hbars.rb +18 -0
- data/examples/illustration.rb +1 -1
- data/examples/info.rb +20 -19
- data/examples/key-codes.rb +17 -15
- data/examples/options.rb +28 -0
- data/examples/tasks.rb +1 -1
- data/examples/vbars.rb +39 -0
- data/lib/natty-ui/attributes.rb +0 -3
- data/lib/natty-ui/choice.rb +27 -17
- data/lib/natty-ui/dumb_choice.rb +6 -5
- data/lib/natty-ui/dumb_options.rb +63 -0
- data/lib/natty-ui/element.rb +3 -4
- data/lib/natty-ui/features.rb +237 -56
- data/lib/natty-ui/hbars_renderer.rb +58 -0
- data/lib/natty-ui/ls_renderer.rb +0 -1
- data/lib/natty-ui/options.rb +77 -0
- data/lib/natty-ui/table_renderer.rb +1 -0
- data/lib/natty-ui/task.rb +1 -1
- data/lib/natty-ui/temporary.rb +5 -6
- data/lib/natty-ui/theme.rb +22 -4
- data/lib/natty-ui/utils.rb +31 -11
- data/lib/natty-ui/vbars_renderer.rb +48 -0
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui.rb +1 -3
- metadata +13 -5
data/lib/natty-ui/theme.rb
CHANGED
@@ -55,7 +55,7 @@ module NattyUI
|
|
55
55
|
failed: '[bright_red]𝑭[/fg]',
|
56
56
|
current: '[bright_green]➔[/fg]',
|
57
57
|
choice: '[bright_white]◦[/fg]',
|
58
|
-
current_choice: '[bright_green]
|
58
|
+
current_choice: '[bright_green]➔[/fg]'
|
59
59
|
)
|
60
60
|
theme.define_section(
|
61
61
|
default: :bright_blue,
|
@@ -166,11 +166,13 @@ module NattyUI
|
|
166
166
|
end
|
167
167
|
|
168
168
|
class Compiled
|
169
|
-
attr_reader :task_style,
|
169
|
+
attr_reader :task_style,
|
170
|
+
:choice_current_style,
|
171
|
+
:choice_style,
|
172
|
+
:option_states
|
170
173
|
|
171
174
|
def defined_marks = @mark.keys.sort!
|
172
175
|
def defined_borders = @border.keys.sort!
|
173
|
-
|
174
176
|
def heading(index) = @heading[index.to_i.clamp(1, 6) - 1]
|
175
177
|
|
176
178
|
def mark(value)
|
@@ -208,12 +210,25 @@ module NattyUI
|
|
208
210
|
SectionBorder.create(border(theme.section_border)),
|
209
211
|
theme.section_styles.dup.compare_by_identity
|
210
212
|
)
|
213
|
+
@option_states = create_option_states
|
211
214
|
end
|
212
215
|
|
213
216
|
private
|
214
217
|
|
215
218
|
def as_style(value) = (Ansi[*value].freeze if value)
|
216
219
|
|
220
|
+
def create_option_states
|
221
|
+
# [current?][selected?]
|
222
|
+
c = @mark[:current_choice]
|
223
|
+
n = @mark[:none]
|
224
|
+
sel = @mark[:checkmark]
|
225
|
+
uns = @mark[:choice]
|
226
|
+
{
|
227
|
+
false => { false => n + uns, true => n + sel }.compare_by_identity,
|
228
|
+
true => { false => c + uns, true => c + sel }.compare_by_identity
|
229
|
+
}.compare_by_identity.freeze
|
230
|
+
end
|
231
|
+
|
217
232
|
def create_sections(template, styles)
|
218
233
|
Hash
|
219
234
|
.new do |h, kind|
|
@@ -224,7 +239,9 @@ module NattyUI
|
|
224
239
|
|
225
240
|
def create_mark(mark)
|
226
241
|
return {} if mark.empty?
|
227
|
-
|
242
|
+
mark = mark.to_h { |n, e| [n.to_sym, Str.new("#{e} ")] }
|
243
|
+
mark[:none] ||= Str.new(' ', 2)
|
244
|
+
with_default(mark)
|
228
245
|
end
|
229
246
|
|
230
247
|
def create_border(border)
|
@@ -294,6 +311,7 @@ module NattyUI
|
|
294
311
|
|
295
312
|
private_constant :SectionBorder
|
296
313
|
end
|
314
|
+
# private_constant :Compiled
|
297
315
|
|
298
316
|
private
|
299
317
|
|
data/lib/natty-ui/utils.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
module NattyUI
|
4
4
|
module Utils
|
5
5
|
class << self
|
6
|
-
# @!visibility private
|
7
6
|
def style(value)
|
8
7
|
value =
|
9
8
|
case value
|
@@ -22,27 +21,22 @@ module NattyUI
|
|
22
21
|
value.keep_if { Ansi.valid?(_1) }.empty? ? nil : value
|
23
22
|
end
|
24
23
|
|
25
|
-
# @!visibility private
|
26
24
|
def align(value)
|
27
25
|
POS_ALI.include?(value) ? value : :left
|
28
26
|
end
|
29
27
|
|
30
|
-
# @!visibility private
|
31
28
|
def position(value)
|
32
29
|
value if POS_ALI.include?(value)
|
33
30
|
end
|
34
31
|
|
35
|
-
# @!visibility private
|
36
32
|
def vertical(value)
|
37
33
|
VERT.include?(value) ? value : :top
|
38
34
|
end
|
39
35
|
|
40
|
-
# @!visibility private
|
41
36
|
def split_table_attr(values)
|
42
37
|
[values.slice(*TAB_ATTR), values.except(*TAB_ATTR)]
|
43
38
|
end
|
44
39
|
|
45
|
-
# @!visibility private
|
46
40
|
def padding(*value)
|
47
41
|
value = value.flatten.take(4).map! { [0, _1.to_i].max }
|
48
42
|
case value.size
|
@@ -59,6 +53,18 @@ module NattyUI
|
|
59
53
|
end
|
60
54
|
end
|
61
55
|
alias margin padding
|
56
|
+
|
57
|
+
def as_size(range, value)
|
58
|
+
return range.begin if value == :min
|
59
|
+
return range.end if value.nil? || value.is_a?(Symbol)
|
60
|
+
(
|
61
|
+
if value.is_a?(Numeric)
|
62
|
+
(value > 0 && value < 1 ? (range.end * value) : value).round
|
63
|
+
else
|
64
|
+
value.to_i
|
65
|
+
end
|
66
|
+
).clamp(range)
|
67
|
+
end
|
62
68
|
end
|
63
69
|
|
64
70
|
POS_ALI = %i[right centered].freeze
|
@@ -79,11 +85,25 @@ module NattyUI
|
|
79
85
|
@width
|
80
86
|
end
|
81
87
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
88
|
+
def +(other)
|
89
|
+
other = Str.new(other) unless other.is_a?(Str)
|
90
|
+
Str.new(@to_s + other.to_s, width + other.width)
|
91
|
+
end
|
92
|
+
|
93
|
+
if Terminal.ansi?
|
94
|
+
def initialize(str, width = nil)
|
95
|
+
@to_s = Ansi.bbcode(str).freeze
|
96
|
+
return unless width
|
97
|
+
@width = @width.is_a?(Integer) ? width : Text.width(self)
|
98
|
+
freeze
|
99
|
+
end
|
100
|
+
else
|
101
|
+
def initialize(str, width = nil)
|
102
|
+
@to_s = Ansi.plain(str).freeze
|
103
|
+
return unless width
|
104
|
+
@width = @width.is_a?(Integer) ? width : Text.width(self)
|
105
|
+
freeze
|
106
|
+
end
|
87
107
|
end
|
88
108
|
end
|
89
109
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NattyUI
|
4
|
+
module VBarsRenderer
|
5
|
+
class << self
|
6
|
+
def lines(vals, width, height, normalize, bar_width, style)
|
7
|
+
if style
|
8
|
+
bos = Ansi[*style]
|
9
|
+
eos = Ansi::RESET
|
10
|
+
end
|
11
|
+
if ((bar_width != :auto) && bar_width <= 1) || (vals.size * 2 > width)
|
12
|
+
db = '▉'
|
13
|
+
ds = ' '
|
14
|
+
el = "#{bos}#{'▔' * vals.size}#{eos}"
|
15
|
+
vals = vals.take(width) if vals.size > width
|
16
|
+
else
|
17
|
+
bw = (width - vals.size) / vals.size
|
18
|
+
bw = [bw, bar_width].min if bar_width != :auto
|
19
|
+
db = "#{'█' * bw} "
|
20
|
+
bw += 1
|
21
|
+
ds = ' ' * bw
|
22
|
+
el = "#{bos}#{'▔' * ((bw * vals.size) - 1)}#{eos}"
|
23
|
+
end
|
24
|
+
height -= 1
|
25
|
+
vals = normalize ? normalize!(vals, height) : adjust!(vals, height)
|
26
|
+
height
|
27
|
+
.downto(1)
|
28
|
+
.map { |i| "#{bos}#{vals.map { _1 < i ? ds : db }.join}#{eos}" } << el
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def adjust!(vals, height)
|
34
|
+
max = vals.max.to_f
|
35
|
+
vals.map { ((_1 / max) * height).round }
|
36
|
+
end
|
37
|
+
|
38
|
+
def normalize!(vals, height)
|
39
|
+
min, max = vals.minmax
|
40
|
+
return Array.new(vals.size, height) if min == max
|
41
|
+
max = (max - min).to_f
|
42
|
+
vals.map { (((_1 - min) / max) * height).round }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private_constant :VBarsRenderer
|
48
|
+
end
|
data/lib/natty-ui/version.rb
CHANGED
data/lib/natty-ui.rb
CHANGED
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.
|
4
|
+
version: 0.29.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.
|
18
|
+
version: 0.12.1
|
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.
|
25
|
+
version: 0.12.1
|
26
26
|
description: |
|
27
27
|
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
|
28
28
|
natty user interface tool you like to have for your command line applications.
|
@@ -44,22 +44,28 @@ files:
|
|
44
44
|
- examples/cols.rb
|
45
45
|
- examples/elements.rb
|
46
46
|
- examples/examples.rb
|
47
|
+
- examples/hbars.rb
|
47
48
|
- examples/illustration.rb
|
48
49
|
- examples/info.rb
|
49
50
|
- examples/key-codes.rb
|
50
51
|
- examples/ls.rb
|
51
52
|
- examples/named-colors.rb
|
53
|
+
- examples/options.rb
|
52
54
|
- examples/sections.rb
|
53
55
|
- examples/tables.rb
|
54
56
|
- examples/tasks.rb
|
57
|
+
- examples/vbars.rb
|
55
58
|
- lib/natty-ui.rb
|
56
59
|
- lib/natty-ui/attributes.rb
|
57
60
|
- lib/natty-ui/choice.rb
|
58
61
|
- lib/natty-ui/dumb_choice.rb
|
62
|
+
- lib/natty-ui/dumb_options.rb
|
59
63
|
- lib/natty-ui/element.rb
|
60
64
|
- lib/natty-ui/features.rb
|
61
65
|
- lib/natty-ui/framed.rb
|
66
|
+
- lib/natty-ui/hbars_renderer.rb
|
62
67
|
- lib/natty-ui/ls_renderer.rb
|
68
|
+
- lib/natty-ui/options.rb
|
63
69
|
- lib/natty-ui/progress.rb
|
64
70
|
- lib/natty-ui/section.rb
|
65
71
|
- lib/natty-ui/table.rb
|
@@ -68,6 +74,7 @@ files:
|
|
68
74
|
- lib/natty-ui/temporary.rb
|
69
75
|
- lib/natty-ui/theme.rb
|
70
76
|
- lib/natty-ui/utils.rb
|
77
|
+
- lib/natty-ui/vbars_renderer.rb
|
71
78
|
- lib/natty-ui/version.rb
|
72
79
|
- lib/natty-ui/width_finder.rb
|
73
80
|
- lib/natty_ui.rb
|
@@ -75,10 +82,11 @@ homepage: https://github.com/mblumtritt/natty-ui
|
|
75
82
|
licenses:
|
76
83
|
- BSD-3-Clause
|
77
84
|
metadata:
|
78
|
-
rubygems_mfa_required: 'true'
|
79
85
|
source_code_uri: https://github.com/mblumtritt/natty-ui
|
80
86
|
bug_tracker_uri: https://github.com/mblumtritt/natty-ui/issues
|
81
|
-
documentation_uri: https://rubydoc.info/gems/natty-ui
|
87
|
+
documentation_uri: https://rubydoc.info/gems/natty-ui
|
88
|
+
rubygems_mfa_required: 'true'
|
89
|
+
yard.run: yard
|
82
90
|
rdoc_options: []
|
83
91
|
require_paths:
|
84
92
|
- lib
|