natty-ui 0.26.0 → 0.27.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/24bit-colors.rb +2 -2
- data/examples/3bit-colors.rb +1 -1
- data/examples/attributes.rb +1 -1
- data/examples/examples.rb +1 -0
- data/examples/info.rb +30 -0
- data/examples/sections.rb +1 -1
- data/examples/tables.rb +3 -4
- data/examples/tasks.rb +1 -1
- data/lib/natty-ui/attributes.rb +43 -54
- data/lib/natty-ui/features.rb +22 -14
- data/lib/natty-ui/progress.rb +5 -2
- data/lib/natty-ui/section.rb +1 -1
- data/lib/natty-ui/table.rb +55 -6
- data/lib/natty-ui/table_renderer.rb +18 -12
- data/lib/natty-ui/task.rb +7 -6
- data/lib/natty-ui/theme.rb +33 -2
- data/lib/natty-ui/utils.rb +26 -14
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/width_finder.rb +11 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43f1afe6be5864d4895c974783fbfcff1f4b5a23f963eb24f6a964fe09b1174c
|
4
|
+
data.tar.gz: e3a4c8e1981f0299f9927c4a3f53fa0c4eca95f792f9590c9ea191e7018adcb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9c75d24c0363076c3e0d41ac458d4f13a6552811d166028d5d758ba408d20aa63907a471ee56c4fe4b0638db1cb03e915d0b6c606e8770a9753d59eafb7c951
|
7
|
+
data.tar.gz: 77a95400ba528d57f3e1b559ac1ffa584c68a60bcc45d212341bc803031f204abac44e269db1d81903a4629b7c9c466c27acae66d84c2f802a3486bab37a929b
|
data/examples/24bit-colors.rb
CHANGED
@@ -5,8 +5,8 @@ require_relative '../lib/natty-ui'
|
|
5
5
|
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]24-bit Color Support[/]' do
|
6
6
|
bar = '█' * ui.columns
|
7
7
|
rainbow =
|
8
|
-
(7..
|
9
|
-
NattyUI::Ansi.rainbow(bar, seed: 3, spread: 3.25, frequency: i /
|
8
|
+
(7..21).map do |i|
|
9
|
+
NattyUI::Ansi.rainbow(bar, seed: 3, spread: 3.25, frequency: i / 200.0)
|
10
10
|
end
|
11
11
|
|
12
12
|
ui.space
|
data/examples/3bit-colors.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative '../lib/natty-ui'
|
|
4
4
|
|
5
5
|
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]3/4bit Color Support[/]' do
|
6
6
|
ui.space
|
7
|
-
ui.puts <<~INFO,
|
7
|
+
ui.puts <<~INFO, eol: false
|
8
8
|
Terminals may support colors. You can colorize foreground text and
|
9
9
|
background. The very basic color palette consists of eight colors and may
|
10
10
|
be extended with eight colors which are much brighter.
|
data/examples/attributes.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative '../lib/natty-ui'
|
|
4
4
|
|
5
5
|
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]ANSI Attributes[/]' do
|
6
6
|
ui.space
|
7
|
-
ui.puts <<~INFO_1, <<~INFO_2,
|
7
|
+
ui.puts <<~INFO_1, <<~INFO_2, eol: false
|
8
8
|
NattyUI supports all well known attributes like
|
9
9
|
[b]bold[/b],
|
10
10
|
[i]italic[/i],
|
data/examples/examples.rb
CHANGED
data/examples/info.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/natty-ui'
|
4
|
+
|
5
|
+
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Terminal Information[/]' do
|
6
|
+
ui.space
|
7
|
+
ui.table do |table|
|
8
|
+
table.add('Identifier', Terminal.application || 'unidentified')
|
9
|
+
table.add('ANSI support', Terminal.ansi? ? 'yes' : 'no')
|
10
|
+
table.add('Input mode', Terminal.input_mode)
|
11
|
+
table.add(
|
12
|
+
'Colors',
|
13
|
+
"#{Terminal.true_color? ? 'true color' : Terminal.colors}
|
14
|
+
[black]██[red]██[green]██[yellow]██[blue]██[magenta]██[cyan]██[white]██" \
|
15
|
+
'[bright_black]██[bright_red]██[bright_green]██[bright_yellow]██' \
|
16
|
+
'[bright_blue]██[bright_magenta]██[bright_cyan]██[bright_white]██[/]' \
|
17
|
+
"#{
|
18
|
+
if Terminal.true_color?
|
19
|
+
Terminal::Ansi.rainbow("\n████████████████████████████████")
|
20
|
+
end
|
21
|
+
}"
|
22
|
+
)
|
23
|
+
table.add('Screen size', Terminal.size.join(' x '))
|
24
|
+
fc = table.columns[0]
|
25
|
+
fc.width = 13
|
26
|
+
fc.padding_right = 1
|
27
|
+
fc.align = :right
|
28
|
+
table.columns[1].style = :bold
|
29
|
+
end
|
30
|
+
end
|
data/examples/sections.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative '../lib/natty-ui'
|
|
5
5
|
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Sections[/]' do
|
6
6
|
ui.space
|
7
7
|
ui.information 'Informative Message' do
|
8
|
-
ui.puts <<~TEXT,
|
8
|
+
ui.puts <<~TEXT, eol: false
|
9
9
|
Sections and messages are elements which support any other feature. This
|
10
10
|
means they may contain text, other sections, titles, horizontal rules,
|
11
11
|
lists, progress bars and much more!
|
data/examples/tables.rb
CHANGED
@@ -46,10 +46,9 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Print Tables[/]' do
|
|
46
46
|
ui.space
|
47
47
|
ui.table do |table|
|
48
48
|
table.add do |row|
|
49
|
-
row.add 'green', style: :on_green
|
50
|
-
row.add 'blue', style: :on_blue
|
51
|
-
row.add 'red', style: :on_red
|
52
|
-
row.width = 15
|
49
|
+
row.add 'green', style: :on_green, max_width: 0.1
|
50
|
+
row.add 'blue', style: :on_blue, max_width: 0.25
|
51
|
+
row.add 'red', style: :on_red, max_width: 0.1
|
53
52
|
row.align = :centered
|
54
53
|
end
|
55
54
|
table.add do |row|
|
data/examples/tasks.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative '../lib/natty-ui'
|
|
4
4
|
|
5
5
|
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Tasks[/]' do
|
6
6
|
ui.space
|
7
|
-
ui.puts <<~TEXT,
|
7
|
+
ui.puts <<~TEXT, eol: false
|
8
8
|
Tasks are sections that are closed either successfully or with an error message.
|
9
9
|
If successful, their content is only displayed temporarily and can consist of all
|
10
10
|
other features, in particular further (sub)tasks. As an exception to this, some
|
data/lib/natty-ui/attributes.rb
CHANGED
@@ -11,19 +11,13 @@ module NattyUI
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# @return [Attributes] itself
|
14
|
-
def merge!(**attributes)
|
15
|
-
attributes.empty? ? self : _assign(attributes)
|
16
|
-
end
|
14
|
+
def merge!(**attributes) = attributes.empty? ? self : _assign(attributes)
|
17
15
|
|
18
16
|
# @!visibility private
|
19
|
-
def to_hash
|
20
|
-
_store({})
|
21
|
-
end
|
17
|
+
def to_hash = _store({})
|
22
18
|
|
23
19
|
# @!visibility private
|
24
|
-
def to_h(&block)
|
25
|
-
block ? _store({}).to_h(&block) : _store({})
|
26
|
-
end
|
20
|
+
def to_h(&block) = block ? _store({}).to_h(&block) : _store({})
|
27
21
|
|
28
22
|
private
|
29
23
|
|
@@ -41,17 +35,22 @@ module NattyUI
|
|
41
35
|
|
42
36
|
def as_wh(value)
|
43
37
|
return unless value
|
44
|
-
return
|
45
|
-
value.is_a?(Range) ? wh_from(value.begin
|
38
|
+
return value > 0 ? value : nil if value.is_a?(Numeric)
|
39
|
+
value.is_a?(Range) ? wh_from(value.begin, value.end) : nil
|
46
40
|
end
|
47
41
|
|
48
42
|
def wh_from(min, max)
|
49
|
-
min =
|
50
|
-
max =
|
43
|
+
min = normalized(min)
|
44
|
+
max = normalized(max)
|
51
45
|
return max ? (..max) : nil unless min
|
52
|
-
return(min
|
46
|
+
return Range.new(min, nil) unless max
|
53
47
|
min == max ? min : Range.new(*[min, max].minmax)
|
54
48
|
end
|
49
|
+
|
50
|
+
def normalized(value)
|
51
|
+
return value < 0 ? nil : value if value.is_a?(Float) && value < 1
|
52
|
+
(value = value.to_i) < 1 ? nil : value
|
53
|
+
end
|
55
54
|
end
|
56
55
|
|
57
56
|
module Align
|
@@ -83,6 +82,30 @@ module NattyUI
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
85
|
+
module Position
|
86
|
+
# Horizontal element position.
|
87
|
+
#
|
88
|
+
# @return [nil, :right, :centered]
|
89
|
+
attr_reader :position
|
90
|
+
|
91
|
+
# @attribute [w] position
|
92
|
+
def position=(value)
|
93
|
+
@position = Utils.position(value)
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
|
98
|
+
def _assign(opt)
|
99
|
+
self.position = opt[:position] if opt.key?(:position)
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
def _store(opt)
|
104
|
+
opt[:position] = @position if @position
|
105
|
+
super
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
86
109
|
module Vertical
|
87
110
|
# Vertical element alignment.
|
88
111
|
#
|
@@ -129,26 +152,22 @@ module NattyUI
|
|
129
152
|
#
|
130
153
|
# @attribute [r] min_width
|
131
154
|
# @return [Integer, nil]
|
132
|
-
def min_width
|
133
|
-
width.is_a?(Range) ? @width.begin : @width
|
134
|
-
end
|
155
|
+
def min_width = width.is_a?(Range) ? @width.begin : @width
|
135
156
|
|
136
157
|
# @attribute [w] min_width
|
137
158
|
def min_width=(value)
|
138
|
-
@width = wh_from(value
|
159
|
+
@width = wh_from(value, max_width)
|
139
160
|
end
|
140
161
|
|
141
162
|
# Maximum element width.
|
142
163
|
#
|
143
164
|
# @attribute [r] max_width
|
144
165
|
# @return [Integer, nil]
|
145
|
-
def max_width
|
146
|
-
width.is_a?(Range) ? @width.end : @width
|
147
|
-
end
|
166
|
+
def max_width = width.is_a?(Range) ? @width.end : @width
|
148
167
|
|
149
168
|
# @attribute [w] max_width
|
150
169
|
def max_width=(value)
|
151
|
-
@width = wh_from(min_width
|
170
|
+
@width = wh_from(min_width, value)
|
152
171
|
end
|
153
172
|
|
154
173
|
protected
|
@@ -183,9 +202,7 @@ module NattyUI
|
|
183
202
|
#
|
184
203
|
# @attribute [r] min_height
|
185
204
|
# @return [Integer, nil]
|
186
|
-
def min_height
|
187
|
-
@height.is_a?(Range) ? @height.begin : @height
|
188
|
-
end
|
205
|
+
def min_height = @height.is_a?(Range) ? @height.begin : @height
|
189
206
|
|
190
207
|
# @attribute [w] min_height
|
191
208
|
def min_height=(value)
|
@@ -196,9 +213,7 @@ module NattyUI
|
|
196
213
|
#
|
197
214
|
# @attribute [r] max_height
|
198
215
|
# @return [Integer, nil]
|
199
|
-
def max_height
|
200
|
-
@height.is_a?(Range) ? @height.begin : @height
|
201
|
-
end
|
216
|
+
def max_height = @height.is_a?(Range) ? @height.begin : @height
|
202
217
|
|
203
218
|
# @attribute [w] max_height
|
204
219
|
def max_height=(value)
|
@@ -464,30 +479,6 @@ module NattyUI
|
|
464
479
|
end
|
465
480
|
end
|
466
481
|
|
467
|
-
module BorderAround
|
468
|
-
# Whether the border is around an element.
|
469
|
-
#
|
470
|
-
# @return [true, false]
|
471
|
-
attr_reader :border_around
|
472
|
-
|
473
|
-
# @attribute [w] border_around
|
474
|
-
def border_around=(value)
|
475
|
-
@border_around = value ? true : false
|
476
|
-
end
|
477
|
-
|
478
|
-
protected
|
479
|
-
|
480
|
-
def _assign(opt)
|
481
|
-
@border_around = opt[:border_around]
|
482
|
-
super
|
483
|
-
end
|
484
|
-
|
485
|
-
def _store(opt)
|
486
|
-
opt[:border_around] = true if @border_around
|
487
|
-
super
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
482
|
module Border
|
492
483
|
# Border type.
|
493
484
|
#
|
@@ -568,10 +559,8 @@ module NattyUI
|
|
568
559
|
attr_reader :text
|
569
560
|
|
570
561
|
def empty? = @text.empty?
|
571
|
-
|
572
562
|
alias _to_s to_s
|
573
563
|
private :_to_s
|
574
|
-
|
575
564
|
def to_str = @text.join("\n")
|
576
565
|
alias to_s to_str
|
577
566
|
|
data/lib/natty-ui/features.rb
CHANGED
@@ -31,8 +31,8 @@ module NattyUI
|
|
31
31
|
# @param options [{Symbol => Object}]
|
32
32
|
# @option options [:left, :right, :centered] :align (:left)
|
33
33
|
# text alignment
|
34
|
-
# @option options [true, false] :
|
35
|
-
# whether to
|
34
|
+
# @option options [true, false] :eol (true)
|
35
|
+
# whether to respect newline characters
|
36
36
|
#
|
37
37
|
# @return [Features]
|
38
38
|
# itself
|
@@ -84,7 +84,7 @@ module NattyUI
|
|
84
84
|
limit: max_width,
|
85
85
|
bbcode: bbcode,
|
86
86
|
ansi: Terminal.ansi?,
|
87
|
-
ignore_newline: options[:ignore_newline]
|
87
|
+
ignore_newline: options[:eol] == false || options[:ignore_newline]
|
88
88
|
)
|
89
89
|
|
90
90
|
if (align = options[:align]).nil?
|
@@ -338,13 +338,16 @@ module NattyUI
|
|
338
338
|
# attributes for the table and default attributes for table cells
|
339
339
|
# @option attributes [Symbol] :border (nil)
|
340
340
|
# kind of border,
|
341
|
-
# see {Attributes
|
342
|
-
# @option attributes [true, false] :border_around (false)
|
343
|
-
# whether the table should have a border around,
|
344
|
-
# see {Attributes::BorderAround}
|
341
|
+
# see {Table::Attributes}
|
345
342
|
# @option attributes [Enumerable<Symbol>] :border_style (nil)
|
346
343
|
# style of border,
|
347
|
-
# see {Attributes
|
344
|
+
# see {Table::Attributes}
|
345
|
+
# @option attributes [true, false] :border_around (false)
|
346
|
+
# whether the table should have a border around,
|
347
|
+
# see {Table::Attributes}
|
348
|
+
# @option attributes [:left, :right, :centered] :position (false)
|
349
|
+
# where to align the table,
|
350
|
+
# see {Table::Attributes}
|
348
351
|
#
|
349
352
|
# @yieldparam table [Table]
|
350
353
|
# helper to define the table layout
|
@@ -353,7 +356,11 @@ module NattyUI
|
|
353
356
|
def table(**attributes)
|
354
357
|
return self unless block_given?
|
355
358
|
yield(table = Table.new(**attributes))
|
356
|
-
puts(
|
359
|
+
puts(
|
360
|
+
*TableRenderer[table, columns],
|
361
|
+
align: table.attributes.position,
|
362
|
+
expand: true
|
363
|
+
)
|
357
364
|
end
|
358
365
|
|
359
366
|
# Print text in columns.
|
@@ -372,9 +379,10 @@ module NattyUI
|
|
372
379
|
#
|
373
380
|
# @return (see puts)
|
374
381
|
def cols(*columns, **attributes)
|
375
|
-
|
382
|
+
tab_att, att = Utils.split_table_attr(attributes)
|
383
|
+
table(**tab_att) do |table|
|
376
384
|
table.add do |row|
|
377
|
-
columns.each { row.add(_1, **
|
385
|
+
columns.each { row.add(_1, **att) }
|
378
386
|
yield(row) if block_given?
|
379
387
|
end
|
380
388
|
end
|
@@ -403,9 +411,9 @@ module NattyUI
|
|
403
411
|
# @return (see puts)
|
404
412
|
def div(*text, **attributes)
|
405
413
|
return self if text.empty?
|
406
|
-
|
407
|
-
|
408
|
-
|
414
|
+
tab_att, att = Utils.split_table_attr(attributes)
|
415
|
+
tab_att[:border_around] = true
|
416
|
+
table(**tab_att) { |table| table.add { _1.add(*text, **att) } }
|
409
417
|
end
|
410
418
|
|
411
419
|
# Dynamically display a task progress.
|
data/lib/natty-ui/progress.rb
CHANGED
@@ -99,6 +99,9 @@ module NattyUI
|
|
99
99
|
@pin = pin
|
100
100
|
@pin_line = NattyUI.lines_written
|
101
101
|
@style = Theme.current.task_style
|
102
|
+
cm = Theme.current.mark(:current)
|
103
|
+
@flp = "#{cm} #{@style}"
|
104
|
+
@flpw = cm.width + 1
|
102
105
|
max ? self.max = max : redraw
|
103
106
|
end
|
104
107
|
|
@@ -110,8 +113,8 @@ module NattyUI
|
|
110
113
|
@pin_line = NattyUI.back_to_line(@pin_line) if @last
|
111
114
|
@parent.puts(
|
112
115
|
*curr,
|
113
|
-
first_line_prefix:
|
114
|
-
first_line_prefix_width:
|
116
|
+
first_line_prefix: @flp,
|
117
|
+
first_line_prefix_width: @flpw
|
115
118
|
)
|
116
119
|
@last = curr
|
117
120
|
end
|
data/lib/natty-ui/section.rb
CHANGED
data/lib/natty-ui/table.rb
CHANGED
@@ -33,7 +33,7 @@ module NattyUI
|
|
33
33
|
m = cell.attributes.max_width
|
34
34
|
max = m if m && (max.nil? || max < m)
|
35
35
|
end
|
36
|
-
wh_from(min
|
36
|
+
wh_from(min, max)
|
37
37
|
end
|
38
38
|
|
39
39
|
def respond_to_missing?(name, _)
|
@@ -181,7 +181,46 @@ module NattyUI
|
|
181
181
|
class Attributes < NattyUI::Attributes::Base
|
182
182
|
prepend NattyUI::Attributes::Border
|
183
183
|
prepend NattyUI::Attributes::BorderStyle
|
184
|
-
prepend NattyUI::Attributes::
|
184
|
+
prepend NattyUI::Attributes::Position
|
185
|
+
|
186
|
+
# Whether the table has a border around.
|
187
|
+
#
|
188
|
+
# @return [true, false]
|
189
|
+
attr_reader :border_around
|
190
|
+
|
191
|
+
# @attribute [w] border_around
|
192
|
+
def border_around=(value)
|
193
|
+
@border_around = value ? true : false
|
194
|
+
end
|
195
|
+
|
196
|
+
# Maximum table width.
|
197
|
+
#
|
198
|
+
# @return [Integer, nil]
|
199
|
+
attr_reader :max_width
|
200
|
+
|
201
|
+
# @attribute [w] max_width
|
202
|
+
def max_width=(value)
|
203
|
+
if value.is_a?(Float)
|
204
|
+
return @max_width = nil if value < 0
|
205
|
+
return @max_width = value if value < 1
|
206
|
+
end
|
207
|
+
value = value.to_i
|
208
|
+
@max_width = value <= 0 ? nil : value
|
209
|
+
end
|
210
|
+
|
211
|
+
protected
|
212
|
+
|
213
|
+
def _assign(opt)
|
214
|
+
@border_around = opt[:border_around]
|
215
|
+
self.max_width = opt[:max_width]
|
216
|
+
super
|
217
|
+
end
|
218
|
+
|
219
|
+
def _store(opt)
|
220
|
+
opt[:border_around] = true if @border_around
|
221
|
+
opt[:max_width] = @max_width if @max_width
|
222
|
+
super
|
223
|
+
end
|
185
224
|
end
|
186
225
|
|
187
226
|
include Enumerable
|
@@ -207,10 +246,20 @@ module NattyUI
|
|
207
246
|
|
208
247
|
# @return [Row] created row
|
209
248
|
def add(*text, **attributes)
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
249
|
+
unless text[0].is_a?(Hash)
|
250
|
+
@rows << (nr = Row.new)
|
251
|
+
text.each { nr.add(_1, **attributes) }
|
252
|
+
return block_given? ? yield(nr) : nr
|
253
|
+
end
|
254
|
+
new_rows = []
|
255
|
+
text[0].each_pair do |key, value|
|
256
|
+
new_rows << (nr = Row.new)
|
257
|
+
@rows << nr
|
258
|
+
nr.add(key, **attributes)
|
259
|
+
nr.add(value, **attributes)
|
260
|
+
yield(nr) if block_given?
|
261
|
+
end
|
262
|
+
new_rows
|
214
263
|
end
|
215
264
|
|
216
265
|
def delete(row)
|
@@ -8,22 +8,28 @@ module NattyUI
|
|
8
8
|
def self.[](table, max_width)
|
9
9
|
columns = table.columns.map(&:width)
|
10
10
|
return [] if columns.empty?
|
11
|
-
|
12
|
-
|
11
|
+
att = table.attributes
|
12
|
+
case att.max_width
|
13
|
+
when Float
|
14
|
+
max_width *= att.max_width
|
15
|
+
when Integer
|
16
|
+
max_width = [max_width, att.max_width].min
|
17
|
+
end
|
18
|
+
unless att.border_chars.nil?
|
13
19
|
max_width -= (columns.size - 1)
|
14
|
-
max_width -= 2 if
|
20
|
+
max_width -= 2 if att.border_around
|
15
21
|
end
|
16
22
|
return [] if max_width < columns.size
|
17
|
-
new(columns, table.each.to_a,
|
23
|
+
new(columns, table.each.to_a, att, max_width).lines
|
18
24
|
end
|
19
25
|
|
20
26
|
attr_reader :lines
|
21
27
|
|
22
28
|
private
|
23
29
|
|
24
|
-
def initialize(columns, rows,
|
30
|
+
def initialize(columns, rows, att, max_width)
|
25
31
|
@max_width, @columns = WidthFinder.find(columns, max_width)
|
26
|
-
init_borders(
|
32
|
+
init_borders(att)
|
27
33
|
@columns = @columns.each.with_index
|
28
34
|
|
29
35
|
@lines = render(rows.shift)
|
@@ -50,12 +56,12 @@ module NattyUI
|
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
53
|
-
def init_borders(
|
54
|
-
chars =
|
55
|
-
style = border_style(
|
59
|
+
def init_borders(att)
|
60
|
+
chars = att.border_chars or return
|
61
|
+
style = border_style(att)
|
56
62
|
@b_inner = style[chars[9]]
|
57
63
|
return if chars[10] == ' '
|
58
|
-
return init_borders_around(chars, style) if
|
64
|
+
return init_borders_around(chars, style) if att.border_around
|
59
65
|
@b_between = chars[10] * (@max_width + @columns.size - 1)
|
60
66
|
i = -1
|
61
67
|
@columns[0..-2].each { |w| @b_between[i += w + 1] = chars[4] }
|
@@ -79,8 +85,8 @@ module NattyUI
|
|
79
85
|
@b_outer = @b_inner
|
80
86
|
end
|
81
87
|
|
82
|
-
def border_style(
|
83
|
-
style =
|
88
|
+
def border_style(att)
|
89
|
+
style = att.border_style_bbcode
|
84
90
|
style ? ->(line) { "#{style}#{line}[/]" } : lambda(&:itself)
|
85
91
|
end
|
86
92
|
|
data/lib/natty-ui/task.rb
CHANGED
@@ -30,16 +30,17 @@ module NattyUI
|
|
30
30
|
def initialize(parent, title, msg, pin)
|
31
31
|
super(parent)
|
32
32
|
@title = title
|
33
|
-
@prefix = ' '
|
34
|
-
@prefix_width = 2
|
35
33
|
@pin = pin
|
36
34
|
style = Theme.current.task_style
|
35
|
+
cm = Theme.current.mark(:current)
|
36
|
+
@prefix = ' ' * cm.width
|
37
|
+
@prefix_width = cm.width
|
37
38
|
parent.puts(
|
38
39
|
title,
|
39
|
-
first_line_prefix: "#{style}
|
40
|
-
first_line_prefix_width:
|
41
|
-
prefix: "#{style}
|
42
|
-
prefix_width:
|
40
|
+
first_line_prefix: "#{cm}#{style}",
|
41
|
+
first_line_prefix_width: cm.width,
|
42
|
+
prefix: "#{@prefix}#{style}",
|
43
|
+
prefix_width: cm.width
|
43
44
|
)
|
44
45
|
puts(*msg) unless msg.empty?
|
45
46
|
end
|
data/lib/natty-ui/theme.rb
CHANGED
@@ -53,6 +53,7 @@ module NattyUI
|
|
53
53
|
warning: '[bright_yellow]![/fg]',
|
54
54
|
error: '[red]𝙓[/fg]',
|
55
55
|
failed: '[bright_red]𝑭[/fg]',
|
56
|
+
current: '[bright_green]➔[/fg]',
|
56
57
|
choice: '[bright_white]◦[/fg]',
|
57
58
|
current_choice: '[bright_green]◉[/fg]'
|
58
59
|
)
|
@@ -66,6 +67,35 @@ module NattyUI
|
|
66
67
|
)
|
67
68
|
end
|
68
69
|
end
|
70
|
+
|
71
|
+
def emoji
|
72
|
+
create do |theme|
|
73
|
+
theme.heading_sytle = :bright_blue
|
74
|
+
theme.task_style = %i[bright_green b]
|
75
|
+
# theme.choice_style =
|
76
|
+
theme.choice_current_style = %i[bright_white on_blue b]
|
77
|
+
theme.define_marker(
|
78
|
+
bullet: '▫️',
|
79
|
+
checkmark: '✅',
|
80
|
+
quote: '[bright_blue]▍[/fg]',
|
81
|
+
information: '📌',
|
82
|
+
warning: '⚠️',
|
83
|
+
error: '❗️',
|
84
|
+
failed: '‼️',
|
85
|
+
current: '➡️',
|
86
|
+
choice: '[bright_white]•[/fg]',
|
87
|
+
current_choice: '[bright_green]●[/fg]'
|
88
|
+
)
|
89
|
+
theme.define_section(
|
90
|
+
default: :bright_blue,
|
91
|
+
message: :bright_blue,
|
92
|
+
information: :bright_blue,
|
93
|
+
warning: :bright_yellow,
|
94
|
+
error: :red,
|
95
|
+
failed: :bright_red
|
96
|
+
)
|
97
|
+
end
|
98
|
+
end
|
69
99
|
end
|
70
100
|
|
71
101
|
attr_accessor :section_border
|
@@ -206,7 +236,7 @@ module NattyUI
|
|
206
236
|
return create_styled_heading(heading, style) if style
|
207
237
|
heading.map do |left|
|
208
238
|
right = " #{left.reverse}"
|
209
|
-
[left = Str.new("#{left} ", true), Str.new(right, left.
|
239
|
+
[left = Str.new("#{left} ", true), Str.new(right, left.width)]
|
210
240
|
end
|
211
241
|
end
|
212
242
|
|
@@ -215,7 +245,7 @@ module NattyUI
|
|
215
245
|
right = Ansi.decorate(left.reverse, *style)
|
216
246
|
[
|
217
247
|
left = Str.new("#{Ansi.decorate(left, *style)} ", true),
|
218
|
-
Str.new(" #{right}", left.
|
248
|
+
Str.new(" #{right}", left.width)
|
219
249
|
]
|
220
250
|
end
|
221
251
|
end
|
@@ -278,6 +308,7 @@ module NattyUI
|
|
278
308
|
warning: '!',
|
279
309
|
error: '𝙓',
|
280
310
|
failed: '𝑭',
|
311
|
+
current: '➔',
|
281
312
|
choice: '◦',
|
282
313
|
current_choice: '◉'
|
283
314
|
}
|
data/lib/natty-ui/utils.rb
CHANGED
@@ -24,12 +24,22 @@ module NattyUI
|
|
24
24
|
|
25
25
|
# @!visibility private
|
26
26
|
def align(value)
|
27
|
-
value
|
27
|
+
POS_ALI.include?(value) ? value : :left
|
28
|
+
end
|
29
|
+
|
30
|
+
# @!visibility private
|
31
|
+
def position(value)
|
32
|
+
value if POS_ALI.include?(value)
|
28
33
|
end
|
29
34
|
|
30
35
|
# @!visibility private
|
31
36
|
def vertical(value)
|
32
|
-
value
|
37
|
+
VERT.include?(value) ? value : :top
|
38
|
+
end
|
39
|
+
|
40
|
+
# @!visibility private
|
41
|
+
def split_table_attr(values)
|
42
|
+
[values.slice(*TAB_ATTR), values.except(*TAB_ATTR)]
|
33
43
|
end
|
34
44
|
|
35
45
|
# @!visibility private
|
@@ -39,7 +49,7 @@ module NattyUI
|
|
39
49
|
when 0
|
40
50
|
[0, 0, 0, 0]
|
41
51
|
when 1
|
42
|
-
|
52
|
+
Array.new(4, value[0])
|
43
53
|
when 2
|
44
54
|
value * 2
|
45
55
|
when 3
|
@@ -50,27 +60,29 @@ module NattyUI
|
|
50
60
|
end
|
51
61
|
alias margin padding
|
52
62
|
end
|
63
|
+
|
64
|
+
POS_ALI = %i[right centered].freeze
|
65
|
+
VERT = %i[bottom middle].freeze
|
66
|
+
TAB_ATTR = %i[border_around border border_style position].freeze
|
53
67
|
end
|
54
68
|
|
55
69
|
class Str
|
56
70
|
attr_reader :to_s
|
57
|
-
|
58
71
|
alias to_str to_s
|
59
|
-
def
|
60
|
-
def
|
72
|
+
def empty? = width == 0
|
73
|
+
def inspect = @to_s.inspect
|
61
74
|
|
62
|
-
def
|
63
|
-
return @
|
64
|
-
@
|
75
|
+
def width
|
76
|
+
return @width if @width
|
77
|
+
@width = Text.width(self)
|
65
78
|
freeze
|
66
|
-
@
|
79
|
+
@width
|
67
80
|
end
|
68
|
-
alias width size
|
69
81
|
|
70
|
-
def initialize(str,
|
82
|
+
def initialize(str, width = nil)
|
71
83
|
@to_s = Ansi.bbcode(str).freeze
|
72
|
-
return unless
|
73
|
-
@
|
84
|
+
return unless width
|
85
|
+
@width = @width.is_a?(Integer) ? width : Text.width(self)
|
74
86
|
freeze
|
75
87
|
end
|
76
88
|
end
|
data/lib/natty-ui/version.rb
CHANGED
@@ -43,9 +43,9 @@ module NattyUI
|
|
43
43
|
|
44
44
|
def fit_max_width(columns, max_width, saving_by_column)
|
45
45
|
ret = max_width - columns.size + 1
|
46
|
+
columns = columns.map { normalized(_1, max_width) }
|
46
47
|
return columns, ret if ret >= 1
|
47
48
|
saving_by_column += 1
|
48
|
-
columns = columns.dup
|
49
49
|
until ret >= 1
|
50
50
|
columns.pop
|
51
51
|
ret += saving_by_column
|
@@ -53,6 +53,16 @@ module NattyUI
|
|
53
53
|
[columns, ret]
|
54
54
|
end
|
55
55
|
|
56
|
+
def normalized(value, max_width)
|
57
|
+
return (max_width * value).to_i if value.is_a?(Float)
|
58
|
+
return value unless value.is_a?(Range)
|
59
|
+
min = value.begin
|
60
|
+
max = value.end
|
61
|
+
min = (max_width * min).to_i if min.is_a?(Float)
|
62
|
+
max = (max_width * max).to_i if max.is_a?(Float)
|
63
|
+
(min..max)
|
64
|
+
end
|
65
|
+
|
56
66
|
def expand(sum)
|
57
67
|
max_width = [@columns.sum(&:max_val), @max_width].min
|
58
68
|
expandables = @columns.find_all(&:expandable?)
|
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.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- examples/elements.rb
|
46
46
|
- examples/examples.rb
|
47
47
|
- examples/illustration.rb
|
48
|
+
- examples/info.rb
|
48
49
|
- examples/key-codes.rb
|
49
50
|
- examples/ls.rb
|
50
51
|
- examples/named-colors.rb
|
@@ -77,7 +78,7 @@ metadata:
|
|
77
78
|
rubygems_mfa_required: 'true'
|
78
79
|
source_code_uri: https://github.com/mblumtritt/natty-ui
|
79
80
|
bug_tracker_uri: https://github.com/mblumtritt/natty-ui/issues
|
80
|
-
documentation_uri: https://rubydoc.info/gems/natty-ui/0.
|
81
|
+
documentation_uri: https://rubydoc.info/gems/natty-ui/0.27.0/NattyUI
|
81
82
|
rdoc_options: []
|
82
83
|
require_paths:
|
83
84
|
- lib
|