natty-ui 0.32.0 → 0.34.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/.yardopts +0 -1
- data/README.md +4 -0
- data/examples/hbars.rb +3 -3
- data/examples/info.rb +1 -1
- data/examples/key-codes.rb +18 -23
- data/examples/named-colors.rb +8 -6
- data/examples/sh.rb +17 -0
- data/examples/tasks.rb +4 -4
- data/examples/vbars.rb +4 -4
- data/lib/natty-ui/attributes.rb +7 -3
- data/lib/natty-ui/choice.rb +6 -5
- data/lib/natty-ui/dumb_choice.rb +6 -5
- data/lib/natty-ui/dumb_options.rb +6 -5
- data/lib/natty-ui/element.rb +28 -3
- data/lib/natty-ui/features.rb +59 -74
- data/lib/natty-ui/framed.rb +4 -4
- data/lib/natty-ui/ls_renderer.rb +2 -0
- data/lib/natty-ui/options.rb +3 -2
- data/lib/natty-ui/progress.rb +9 -7
- data/lib/natty-ui/section.rb +1 -1
- data/lib/natty-ui/shell_renderer.rb +9 -10
- data/lib/natty-ui/table_renderer.rb +2 -0
- data/lib/natty-ui/temporary.rb +3 -4
- data/lib/natty-ui/theme.rb +9 -2
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/width_finder.rb +2 -0
- data/lib/natty-ui.rb +10 -21
- data/natty-ui.gemspec +34 -0
- metadata +11 -12
- data/LICENSE +0 -28
- data/lib/natty-ui/shell_command.rb +0 -132
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c61c16b1c5d1611a98f1505bb9eb86b71a0289021a9332f41e2095f7810b144
|
|
4
|
+
data.tar.gz: e8acc6fdf67bd259fd671defd80533f5de0fa9aa7b005cef9f092b7ebf097606
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a38c19bc286fff4f5776fde2bb1a1de897ea3cdc8498c774691c449de6c2614b229f50a84d6eaf3a89c90af8a99500f6fc8e9237fea9dea7c8234370d4629399
|
|
7
|
+
data.tar.gz: 9d74ccf3a7202619718e8dd67e19cf53534996738c2e04522e3ba6b67aac51323167e7989577c9ace0c793e729130e984eeffb2eae9d98b8458e5f401249b7cc
|
data/.yardopts
CHANGED
data/README.md
CHANGED
data/examples/hbars.rb
CHANGED
|
@@ -11,7 +11,7 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Print Horizontal Bars[/]' do
|
|
|
11
11
|
|
|
12
12
|
ui.space
|
|
13
13
|
ui.hbars values, style: :green, normalize: true, width: 0.5, min: 10
|
|
14
|
-
ui.puts
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
ui.puts <<~INFO, eol: false
|
|
15
|
+
These are the same values but [i]normalized[/i] and printed in half width.
|
|
16
|
+
INFO
|
|
17
17
|
end
|
data/examples/info.rb
CHANGED
|
@@ -19,8 +19,8 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Terminal Information[/]' do
|
|
|
19
19
|
table.add 'Identifier', Terminal.application || 'unidentified'
|
|
20
20
|
table.add 'ANSI support', Terminal.ansi? ? 'yes' : 'no'
|
|
21
21
|
table.add 'Input mode', Terminal.input_mode
|
|
22
|
-
table.add 'Colors', colors
|
|
23
22
|
table.add 'Screen size', Terminal.size.join(' x ')
|
|
23
|
+
table.add 'Colors', colors
|
|
24
24
|
table.columns[0].assign(width: 15, padding_right: 2, align: :right)
|
|
25
25
|
table.columns[1].style = %i[bold bright_yellow]
|
|
26
26
|
end
|
data/examples/key-codes.rb
CHANGED
|
@@ -2,29 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ui.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
#{
|
|
12
|
-
if event
|
|
13
|
-
"#{event.to_a.size < 2 ? ' Key' : 'Keys'}: [bold bright_green]#{
|
|
14
|
-
event.to_a.map { "[\\#{_1}]" }.join(' ')
|
|
15
|
-
}[/]
|
|
16
|
-
Code: [bright_blue]#{event.raw.inspect}[/]"
|
|
17
|
-
else
|
|
18
|
-
"Your terminal uses [bright_blue]#{
|
|
19
|
-
Terminal.input_mode
|
|
20
|
-
}[/] mode. Press a key!"
|
|
21
|
-
end
|
|
22
|
-
}
|
|
5
|
+
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Keyboard Key Codes[/]' do
|
|
6
|
+
ui.space
|
|
7
|
+
ui.puts(
|
|
8
|
+
"Your terminal uses [bright_blue]#{Terminal.input_mode}[/] mode. Press a key!",
|
|
9
|
+
'[dim](Exit with ESC)'
|
|
10
|
+
)
|
|
23
11
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
ui.space
|
|
13
|
+
# if you like to have mouse position changes reported then use
|
|
14
|
+
# 'mouse_move: true' in next line
|
|
15
|
+
Terminal.on_key_event(mouse: true, focus: true, mouse_move: false) do |event|
|
|
16
|
+
ui.puts(
|
|
17
|
+
"#{event.raw.inspect} [dim]→[/dim] [bold bright_green]#{
|
|
18
|
+
event.to_a.map { "[\\#{_1}]" }.join('+')
|
|
19
|
+
}#{" @ #{event.position.join(', ')}" if event.position}"
|
|
20
|
+
)
|
|
21
|
+
event.name != 'Esc'
|
|
29
22
|
end
|
|
23
|
+
|
|
24
|
+
ui.space
|
|
30
25
|
end
|
data/examples/named-colors.rb
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
5
|
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Named Colors Support[/]' do
|
|
6
|
-
ui.
|
|
7
|
-
|
|
8
|
-
NattyUI supports a series of named color values,
|
|
9
|
-
|
|
6
|
+
ui.space
|
|
7
|
+
ui.puts <<~INFO, eol: false
|
|
8
|
+
NattyUI supports a series of named color values,
|
|
9
|
+
such as those supported by Kitty.
|
|
10
10
|
INFO
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
ui.space
|
|
13
|
+
ui.information 'Note' do
|
|
14
|
+
ui.puts 'Not all terminal emulators support true-colors.'
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
ui.space
|
data/examples/sh.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/natty-ui'
|
|
4
|
+
|
|
5
|
+
ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Call Shell[/]' do
|
|
6
|
+
ui.space
|
|
7
|
+
ui.message 'Pipe this file to [i]cat[/i]; limit to five lines' do
|
|
8
|
+
File.open(__FILE__) do |file|
|
|
9
|
+
ui.run 'cat', input: file, preserve_spaces: true, max_lines: 5
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
ui.space
|
|
14
|
+
ui.message 'Call [i]cat[/i] with invalid option' do
|
|
15
|
+
ui.sh 'cat', '-?'
|
|
16
|
+
end
|
|
17
|
+
end
|
data/examples/tasks.rb
CHANGED
|
@@ -17,9 +17,9 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Tasks[/]' do
|
|
|
17
17
|
|
|
18
18
|
ui.space
|
|
19
19
|
ui.task 'Actualize Reading List' do
|
|
20
|
-
ui.puts
|
|
20
|
+
ui.puts 'This is a simple which actualizes the book reading list.'
|
|
21
21
|
|
|
22
|
-
ui.task
|
|
22
|
+
ui.task 'Connect to Library' do
|
|
23
23
|
do_something
|
|
24
24
|
ui.mark 'Server Found', mark: :checkmark
|
|
25
25
|
ui.task('Login...') { do_something_heavy }
|
|
@@ -36,14 +36,14 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Tasks[/]' do
|
|
|
36
36
|
|
|
37
37
|
ui.task('Disconnect from Library') { do_something_heavy }
|
|
38
38
|
|
|
39
|
-
ui.progress
|
|
39
|
+
ui.progress 'Read Cover Images', max: 11 do |progress|
|
|
40
40
|
while progress.value < progress.max
|
|
41
41
|
do_something
|
|
42
42
|
progress.step
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
ui.pin
|
|
46
|
+
ui.pin 'New Books Marked', mark: :checkmark
|
|
47
47
|
|
|
48
48
|
ui.task('Optimize Database') { do_something_heavy }
|
|
49
49
|
|
data/examples/vbars.rb
CHANGED
|
@@ -32,8 +32,8 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Print Vertical Bars[/]' do
|
|
|
32
32
|
|
|
33
33
|
ui.space
|
|
34
34
|
ui.vbars values, style: :green, normalize: true, bar_width: 2
|
|
35
|
-
ui.puts
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
ui.puts <<~INFO, eol: false
|
|
36
|
+
These are the same values but [i]normalized[/i]
|
|
37
|
+
and printed with a fixed bar width.
|
|
38
|
+
INFO
|
|
39
39
|
end
|
data/lib/natty-ui/attributes.rb
CHANGED
|
@@ -13,10 +13,10 @@ module NattyUI
|
|
|
13
13
|
def merge!(**attributes) = attributes.empty? ? self : _assign(attributes)
|
|
14
14
|
alias assign merge!
|
|
15
15
|
|
|
16
|
-
#
|
|
16
|
+
# @private
|
|
17
17
|
def to_hash = _store({})
|
|
18
18
|
|
|
19
|
-
#
|
|
19
|
+
# @private
|
|
20
20
|
def to_h(&block) = block ? _store({}).to_h(&block) : _store({})
|
|
21
21
|
|
|
22
22
|
private
|
|
@@ -506,7 +506,7 @@ module NattyUI
|
|
|
506
506
|
end
|
|
507
507
|
end
|
|
508
508
|
|
|
509
|
-
#
|
|
509
|
+
# @private
|
|
510
510
|
# @return [String, nil]
|
|
511
511
|
attr_reader :border_chars
|
|
512
512
|
|
|
@@ -549,11 +549,14 @@ module NattyUI
|
|
|
549
549
|
@attributes = @attributes.dup
|
|
550
550
|
end
|
|
551
551
|
end
|
|
552
|
+
|
|
552
553
|
private_constant :WithAttributes
|
|
553
554
|
|
|
554
555
|
module TextWithAttributes
|
|
555
556
|
include WithAttributes
|
|
557
|
+
|
|
556
558
|
attr_reader :text
|
|
559
|
+
|
|
557
560
|
def empty? = @text.empty?
|
|
558
561
|
alias _to_s to_s
|
|
559
562
|
private :_to_s
|
|
@@ -585,5 +588,6 @@ module NattyUI
|
|
|
585
588
|
@text = @text.map(&:dup)
|
|
586
589
|
end
|
|
587
590
|
end
|
|
591
|
+
|
|
588
592
|
private_constant :TextWithAttributes
|
|
589
593
|
end
|
data/lib/natty-ui/choice.rb
CHANGED
|
@@ -9,12 +9,12 @@ module NattyUI
|
|
|
9
9
|
pin_line = NattyUI.lines_written
|
|
10
10
|
draw
|
|
11
11
|
last = @current
|
|
12
|
-
|
|
12
|
+
Terminal.on_key_event do |event|
|
|
13
13
|
case event.name
|
|
14
14
|
when 'Esc', 'Ctrl+c'
|
|
15
|
-
|
|
15
|
+
return if @abortable
|
|
16
16
|
when 'Enter', 'Space'
|
|
17
|
-
|
|
17
|
+
return @ret[@current]
|
|
18
18
|
when 'Home'
|
|
19
19
|
@current = 0
|
|
20
20
|
when 'End'
|
|
@@ -24,11 +24,11 @@ module NattyUI
|
|
|
24
24
|
when 'Down', 'Tab', 'k', 's'
|
|
25
25
|
@current = 0 if (@current += 1) == @texts.size
|
|
26
26
|
else
|
|
27
|
-
next unless event.simple?
|
|
27
|
+
next true unless event.simple?
|
|
28
28
|
c = event.key.ord
|
|
29
29
|
@current = (c - 48).clamp(0, @texts.size - 1) if c.between?(48, 57)
|
|
30
30
|
end
|
|
31
|
-
next if last == @current
|
|
31
|
+
next true if last == @current
|
|
32
32
|
pin_line = NattyUI.back_to_line(pin_line, erase: false)
|
|
33
33
|
draw
|
|
34
34
|
last = @current
|
|
@@ -62,5 +62,6 @@ module NattyUI
|
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
|
+
|
|
65
66
|
private_constant :Choice
|
|
66
67
|
end
|
data/lib/natty-ui/dumb_choice.rb
CHANGED
|
@@ -7,15 +7,15 @@ module NattyUI
|
|
|
7
7
|
def select
|
|
8
8
|
yield(self) if block_given?
|
|
9
9
|
draw
|
|
10
|
-
|
|
10
|
+
Terminal.on_key_event do |event|
|
|
11
11
|
return if @abortable && %w[Esc Ctrl+c].include?(event.name)
|
|
12
|
-
next unless event.simple?
|
|
12
|
+
next true unless event.simple?
|
|
13
13
|
code = event.raw.upcase
|
|
14
14
|
if @ret.size <= 9
|
|
15
|
-
next unless ('1'..'9').include?(code)
|
|
16
|
-
code = @ret[code.ord - 49] and
|
|
15
|
+
next true unless ('1'..'9').include?(code)
|
|
16
|
+
code = @ret[code.ord - 49] and return code
|
|
17
17
|
elsif ('A'..'Z').include?(code)
|
|
18
|
-
code = @ret[code.ord - 65] and
|
|
18
|
+
code = @ret[code.ord - 65] and return code
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -42,5 +42,6 @@ module NattyUI
|
|
|
42
42
|
@abortable = abortable
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
+
|
|
45
46
|
private_constant :DumbChoice
|
|
46
47
|
end
|
|
@@ -7,20 +7,20 @@ module NattyUI
|
|
|
7
7
|
def select
|
|
8
8
|
yield(self) if block_given?
|
|
9
9
|
draw
|
|
10
|
-
|
|
10
|
+
Terminal.on_key_event do |event|
|
|
11
11
|
return if @abortable && %w[Esc Ctrl+c].include?(event.name)
|
|
12
12
|
return @opts.transform_values(&:last) if event.name == 'Enter'
|
|
13
|
-
next unless event.simple?
|
|
13
|
+
next true unless event.simple?
|
|
14
14
|
code = event.raw.upcase
|
|
15
15
|
if @opts.size <= 9
|
|
16
|
-
next unless ('1'..'9').include?(code)
|
|
16
|
+
next true unless ('1'..'9').include?(code)
|
|
17
17
|
offset = 49
|
|
18
18
|
elsif ('A'..'Z').include?(code)
|
|
19
19
|
offset = 65
|
|
20
20
|
else
|
|
21
|
-
next
|
|
21
|
+
next true
|
|
22
22
|
end
|
|
23
|
-
key = @opts.keys[code.ord - offset] or next
|
|
23
|
+
key = @opts.keys[code.ord - offset] or next true
|
|
24
24
|
@opts[key][-1] = !@opts[key][-1]
|
|
25
25
|
@parent.space
|
|
26
26
|
draw
|
|
@@ -59,5 +59,6 @@ module NattyUI
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
|
+
|
|
62
63
|
private_constant :DumbOptions
|
|
63
64
|
end
|
data/lib/natty-ui/element.rb
CHANGED
|
@@ -8,10 +8,10 @@ module NattyUI
|
|
|
8
8
|
class Element
|
|
9
9
|
include Features
|
|
10
10
|
|
|
11
|
-
#
|
|
11
|
+
# @private
|
|
12
12
|
def columns = @parent.columns - @prefix_width - @suffix_width
|
|
13
13
|
|
|
14
|
-
#
|
|
14
|
+
# @private
|
|
15
15
|
def puts(*objects, **options)
|
|
16
16
|
if @prefix
|
|
17
17
|
options[:prefix] = "#{@prefix}#{options[:prefix]}"
|
|
@@ -32,7 +32,7 @@ module NattyUI
|
|
|
32
32
|
self
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# @private
|
|
36
36
|
alias to_s inspect
|
|
37
37
|
|
|
38
38
|
alias _to_s to_s
|
|
@@ -46,13 +46,32 @@ module NattyUI
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
# Methods for elements with status like {ProgressHelper}, {Section}, {Task}.
|
|
50
|
+
#
|
|
49
51
|
module WithStatus
|
|
52
|
+
# @return [Symbol, nil] element's current status
|
|
50
53
|
attr_reader :status
|
|
54
|
+
|
|
55
|
+
# @attribute [r] active?
|
|
56
|
+
# @return [true, false] whether the element is still active
|
|
51
57
|
def active? = @status.nil?
|
|
58
|
+
|
|
59
|
+
# @attribute [r] closed?
|
|
60
|
+
# @return [true, false] whether the element is closed
|
|
52
61
|
def closed? = !active?
|
|
62
|
+
|
|
63
|
+
# @attribute [r] closed?
|
|
64
|
+
# @return [true, false] whether the element is completed
|
|
53
65
|
def ok? = @state == :ok
|
|
66
|
+
|
|
67
|
+
# @attribute [r] failed?
|
|
68
|
+
# @return [true, false] whether the element is completed with failure
|
|
54
69
|
def failed? = @state == :failed
|
|
55
70
|
|
|
71
|
+
# Close the element.
|
|
72
|
+
#
|
|
73
|
+
# @param [#to_s] text optional message
|
|
74
|
+
# @return [Element] itself
|
|
56
75
|
def ok(*text)
|
|
57
76
|
return self if @state
|
|
58
77
|
text = [@title] if text.empty? && @title
|
|
@@ -62,6 +81,12 @@ module NattyUI
|
|
|
62
81
|
end
|
|
63
82
|
alias done ok
|
|
64
83
|
|
|
84
|
+
# Close the element with a failure.
|
|
85
|
+
#
|
|
86
|
+
# @param text [#to_s] optional message
|
|
87
|
+
# @yield optionally, when block is given
|
|
88
|
+
# @yieldparam failed [Section] see {Features.failed}
|
|
89
|
+
# @return [Element] itself
|
|
65
90
|
def failed(*text, &block)
|
|
66
91
|
return self if @state
|
|
67
92
|
_failed
|