natty-ui 0.7.0 → 0.9.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 +7 -3
- data/README.md +25 -47
- data/examples/24bit-colors.rb +27 -0
- data/examples/3bit-colors.rb +14 -0
- data/examples/8bit-colors.rb +31 -0
- data/examples/animate.rb +24 -0
- data/examples/attributes.rb +25 -159
- data/examples/demo.rb +53 -0
- data/examples/illustration.png +0 -0
- data/examples/illustration.rb +29 -0
- data/examples/{list_in_columns.rb → ls.rb} +13 -20
- data/examples/message.rb +30 -0
- data/examples/progress.rb +25 -30
- data/examples/query.rb +26 -28
- data/examples/read_key.rb +13 -0
- data/examples/table.rb +36 -0
- data/lib/natty-ui/ansi.rb +351 -305
- data/lib/natty-ui/ansi_constants.rb +73 -0
- data/lib/natty-ui/ansi_wrapper.rb +136 -162
- data/lib/natty-ui/features.rb +11 -18
- data/lib/natty-ui/key_map.rb +119 -0
- data/lib/natty-ui/line_animation/default.rb +35 -0
- data/lib/natty-ui/line_animation/matrix.rb +28 -0
- data/lib/natty-ui/line_animation/rainbow.rb +30 -0
- data/lib/natty-ui/line_animation/test.rb +29 -0
- data/lib/natty-ui/line_animation/type_writer.rb +64 -0
- data/lib/natty-ui/line_animation.rb +54 -0
- data/lib/natty-ui/version.rb +2 -2
- data/lib/natty-ui/wrapper/animate.rb +17 -0
- data/lib/natty-ui/wrapper/ask.rb +21 -21
- data/lib/natty-ui/wrapper/element.rb +19 -23
- data/lib/natty-ui/wrapper/framed.rb +29 -19
- data/lib/natty-ui/wrapper/heading.rb +26 -53
- data/lib/natty-ui/wrapper/horizontal_rule.rb +37 -0
- data/lib/natty-ui/wrapper/list_in_columns.rb +71 -12
- data/lib/natty-ui/wrapper/message.rb +20 -27
- data/lib/natty-ui/wrapper/progress.rb +40 -13
- data/lib/natty-ui/wrapper/query.rb +34 -31
- data/lib/natty-ui/wrapper/quote.rb +25 -0
- data/lib/natty-ui/wrapper/request.rb +21 -10
- data/lib/natty-ui/wrapper/section.rb +55 -39
- data/lib/natty-ui/wrapper/table.rb +298 -0
- data/lib/natty-ui/wrapper/task.rb +6 -7
- data/lib/natty-ui/wrapper.rb +123 -41
- data/lib/natty-ui.rb +65 -40
- metadata +28 -9
- data/examples/basic.rb +0 -62
data/examples/progress.rb
CHANGED
@@ -1,68 +1,63 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../lib/natty-ui'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
UI.h1 'NattyUI Progress Indication Demo'
|
9
|
-
UI.space
|
5
|
+
ui.space
|
6
|
+
ui.h1 'NattyUI: Progress Indication'
|
7
|
+
ui.space
|
10
8
|
|
11
9
|
# just simulate some work
|
12
10
|
def something = sleep(0.5)
|
13
11
|
def some = sleep(0.15)
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
ui.info 'Tasks are sections to visualize step by step processing.' do
|
14
|
+
ui.task 'Assemble assets' do
|
15
|
+
ui.task('Initialize') { something }
|
18
16
|
|
19
|
-
progress =
|
17
|
+
progress = ui.progress 'Connect to server...'
|
20
18
|
20.times do
|
21
19
|
progress.step
|
22
20
|
some
|
23
21
|
end
|
24
22
|
progress.ok 'Connected'
|
25
23
|
|
26
|
-
|
24
|
+
ui.task('Collect files...') { something }
|
27
25
|
|
28
|
-
|
26
|
+
ui.task 'Compile files...' do
|
29
27
|
%w[readme.txt main.css main.html sub.html].each do |name|
|
30
|
-
|
28
|
+
ui.msg "Compile file [[bright_yellow]]./source/#{name}[[/]]..."
|
31
29
|
something
|
32
30
|
end
|
33
|
-
|
31
|
+
ui.done 'Files compiled.'
|
34
32
|
end
|
35
33
|
|
36
|
-
progress =
|
34
|
+
progress = ui.progress('Compress files', max_value: 11)
|
37
35
|
11.times do
|
38
36
|
progress.step
|
39
37
|
something
|
40
38
|
end
|
41
39
|
progress.done 'All compressed'
|
42
40
|
|
43
|
-
|
41
|
+
ui.task('Signing') { something }
|
44
42
|
|
45
|
-
|
43
|
+
ui.task('Store assembled results') { something }
|
46
44
|
end
|
47
|
-
|
45
|
+
|
46
|
+
ui.puts(
|
48
47
|
'The details are removed ([[italic]]in ANSI version[[/]]) when the task',
|
49
48
|
'ended sucessfully.'
|
50
49
|
)
|
51
50
|
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
progress.step
|
60
|
-
some
|
52
|
+
ui.info 'Details of failed tasks will not be cleaned.' do
|
53
|
+
ui.task 'Assemble assets' do
|
54
|
+
ui.task('Initialize') { something }
|
55
|
+
ui.task('Connect to Server') do
|
56
|
+
something
|
57
|
+
ui.failed 'Unable to connect to server'
|
61
58
|
end
|
62
|
-
|
63
|
-
|
64
|
-
task.error 'This code will not be reachd!'
|
59
|
+
ui.error 'This code will not be reachd!'
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
68
|
-
|
63
|
+
ui.space
|
data/examples/query.rb
CHANGED
@@ -1,43 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../lib/natty-ui'
|
4
4
|
|
5
|
-
|
5
|
+
ui.space
|
6
|
+
ui.h1 'NattyUI: User Queries'
|
7
|
+
ui.space
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
# little helper
|
10
|
+
def abort!
|
11
|
+
ui.failed 'aborted'
|
12
|
+
ui.space
|
13
|
+
exit
|
14
|
+
end
|
10
15
|
|
11
|
-
unless
|
12
|
-
|
16
|
+
unless ui.ask('Do you like to continute? (Y|n): ')
|
17
|
+
ui.info 'ok, try later!'
|
18
|
+
ui.space
|
13
19
|
exit
|
14
20
|
end
|
15
21
|
|
16
22
|
choice =
|
17
|
-
|
23
|
+
ui.query(
|
18
24
|
'Which fruits do you prefer?',
|
19
25
|
'Apples',
|
20
|
-
'Bananas',
|
26
|
+
'[[yellow]]Bananas[[/]]',
|
21
27
|
'Cherries',
|
22
|
-
x: 'No fruits'
|
23
|
-
result: :choice
|
28
|
+
x: 'No fruits'
|
24
29
|
)
|
25
|
-
unless choice
|
26
|
-
|
27
|
-
exit false
|
28
|
-
end
|
29
|
-
UI.info "Your choice: #{choice}"
|
30
|
+
abort! unless choice
|
31
|
+
ui.info "Your choice: #{choice}"
|
30
32
|
|
31
|
-
answer =
|
32
|
-
unless answer
|
33
|
-
|
34
|
-
exit false
|
35
|
-
end
|
36
|
-
UI.info "Your answer: #{answer.inspect}"
|
33
|
+
answer = ui.request 'What is your favorite verb?: '
|
34
|
+
abort! unless answer
|
35
|
+
ui.info "Your answer: #{answer.inspect}"
|
37
36
|
|
38
|
-
answer =
|
39
|
-
unless answer
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
UI.info "I'll keep your secret!"
|
37
|
+
answer = ui.request('What is your current password?:', password: true)
|
38
|
+
abort! unless answer
|
39
|
+
ui.info "I'll keep your secret!"
|
40
|
+
|
41
|
+
ui.space
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/natty-ui'
|
4
|
+
|
5
|
+
ui.puts '⌨️ Display Keyboard Input [[bright_black]](Exit with Ctrl+C)'
|
6
|
+
|
7
|
+
ui.section prefix: '[[blue]]:[[/]] ' do
|
8
|
+
while true
|
9
|
+
raw, name = NattyUI.read_key(mode: :both)
|
10
|
+
ui.puts "[[yellow]]#{raw.inspect}[[/]] [[bold bright_green]]#{name}[[/]]"
|
11
|
+
break if name == 'Ctrl+C'
|
12
|
+
end
|
13
|
+
end
|
data/examples/table.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/natty-ui'
|
4
|
+
|
5
|
+
ui.space
|
6
|
+
ui.h1 'NattyUI: Tables'
|
7
|
+
ui.space
|
8
|
+
|
9
|
+
ui.message 'Constructed Table' do
|
10
|
+
ui.table type: :heavy do |table|
|
11
|
+
table.add 'X', 'O'
|
12
|
+
table.add 'O', 'O', 'X'
|
13
|
+
table.add nil, 'X'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
ui.space
|
18
|
+
|
19
|
+
User = Struct.new(:id, :name, :mail, :notes)
|
20
|
+
USERS = [
|
21
|
+
User.new(
|
22
|
+
1,
|
23
|
+
'Henry',
|
24
|
+
'henry@some.test',
|
25
|
+
'This is fill text to generate a wide column which maybe rendered as multi line.'
|
26
|
+
),
|
27
|
+
User.new(2, 'Sam', 'sam-sam@some.test', "enforced\nmulti-line"),
|
28
|
+
User.new(3, 'Taylor', 'taylor@some.test'),
|
29
|
+
User.new(3, 'Max', 'maxxx@some.test')
|
30
|
+
].freeze
|
31
|
+
|
32
|
+
ui.message 'Data Table' do
|
33
|
+
ui.table(User.members, *USERS)
|
34
|
+
end
|
35
|
+
|
36
|
+
ui.space
|