natty-ui 0.5.3 → 0.7.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 +9 -0
- data/README.md +3 -5
- data/examples/attributes.rb +161 -0
- data/examples/basic.rb +8 -9
- data/examples/illustration.png +0 -0
- data/examples/list_in_columns.rb +43 -0
- data/examples/progress.rb +45 -61
- data/examples/query.rb +34 -23
- data/lib/natty-ui/ansi.rb +69 -60
- data/lib/natty-ui/ansi_wrapper.rb +68 -32
- data/lib/natty-ui/features.rb +36 -0
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/wrapper/ask.rb +4 -4
- data/lib/natty-ui/wrapper/element.rb +6 -3
- data/lib/natty-ui/wrapper/list_in_columns.rb +81 -0
- data/lib/natty-ui/wrapper/mixins.rb +3 -3
- data/lib/natty-ui/wrapper/progress.rb +13 -8
- data/lib/natty-ui/wrapper/query.rb +7 -7
- data/lib/natty-ui/wrapper/request.rb +43 -0
- data/lib/natty-ui/wrapper/section.rb +4 -4
- data/lib/natty-ui/wrapper/task.rb +3 -5
- data/lib/natty-ui/wrapper.rb +12 -7
- data/lib/natty-ui.rb +22 -18
- data/lib/natty_ui.rb +3 -0
- metadata +11 -6
- data/examples/colors.rb +0 -7
- data/examples/illustration.svg +0 -1
- data/lib/natty-ui/wrapper/features.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 955176038d4388a0b55468997a267434bede767869071193c3fc45526ebbc3e5
|
4
|
+
data.tar.gz: 6fdcd1f82ae1ee09bbd5650050edd3493eedbe584263921e1e6d5abf30900b5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5104516012022478512ad583b12e5110941013849f074ac3156ef34076654ad86ebd2a723b598c595984f3a5799c831106ec17add1a17da26b7839f19746b957
|
7
|
+
data.tar.gz: 6f55cc25b480284da8f77e284b13768b9b84b3dbf1efef15dcec7999227d1fb04f1b9addc570a0ae536d44111b94c685238319c6605a425d42eac8f7613c4e23
|
data/.yardopts
ADDED
data/README.md
CHANGED
@@ -46,7 +46,7 @@ or use progression displays like progress bars.
|
|
46
46
|
|
47
47
|
📕 See the [online help](https://rubydoc.info/gems/natty-ui/NattyUI) for more details or have a look at the [examples](./examples/) directory to get an impression of the current feature set.
|
48
48
|
|
49
|
-

|
50
50
|
|
51
51
|
## Installation
|
52
52
|
|
@@ -73,13 +73,13 @@ require 'natty-ui'
|
|
73
73
|
You can execute the examples by
|
74
74
|
|
75
75
|
```sh
|
76
|
-
ruby ./examples/basic.rb
|
76
|
+
bundle exec ruby ./examples/basic.rb
|
77
77
|
```
|
78
78
|
|
79
79
|
or see the non-ANSI version
|
80
80
|
|
81
81
|
```sh
|
82
|
-
NO_COLOR=1 ruby ./examples/basic.rb
|
82
|
+
NO_COLOR=1 bundle exec ruby ./examples/basic.rb
|
83
83
|
```
|
84
84
|
|
85
85
|
## NO_COLOR Convention
|
@@ -92,5 +92,3 @@ Since I did not complete the tests and not all my ideas are already implemented
|
|
92
92
|
|
93
93
|
- add more samples to help
|
94
94
|
- add more tests
|
95
|
-
- simple prompt
|
96
|
-
- password prompt
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
4
|
+
|
5
|
+
UI = NattyUI::StdOut
|
6
|
+
|
7
|
+
UI.space
|
8
|
+
UI.h1 'NattyUI ANSI Attributes Demo', <<~TEXT
|
9
|
+
|
10
|
+
This text contains all supported ANSI attrubtes and explains the available
|
11
|
+
colors.
|
12
|
+
|
13
|
+
Please, keep in mind that no all terminals will support of all attributes and
|
14
|
+
color types used in this text. In fact, you can use the output of this text to
|
15
|
+
check the supported ANSI attributes.
|
16
|
+
|
17
|
+
TEXT
|
18
|
+
|
19
|
+
UI.h2 'Attributes', <<~TEXT
|
20
|
+
|
21
|
+
Some attributes are widely supported, such as [[bold]]bold[[/]], [[italic]]italic[[/]], [[underline]]underline[[/]], [[blink]]blink[[/]],
|
22
|
+
[[invert]]invert[[/]] and [[strike]]strike[[/]], while others are rarely complete or correctly implemented,
|
23
|
+
like [[faint]]faint[[/]], [[rapid_blink]]rapid_blink[[/]], [[double_underline]]double_underline[[/]], [[framed]]framed[[/]], [[encircled]]encircled[[/]], [[overlined]]overlined[[/]],
|
24
|
+
[[proportional]]proportional[[/]] and [[spacing]]spacing[[/]].
|
25
|
+
|
26
|
+
Different font types are very rarely displayed:
|
27
|
+
|
28
|
+
• [[primary_font]]primary_font[[/]]
|
29
|
+
• [[font1]]font1[[/]]
|
30
|
+
• [[font2]]font2[[/]]
|
31
|
+
• [[font3]]font3[[/]]
|
32
|
+
• [[font4]]font4[[/]]
|
33
|
+
• [[font5]]font5[[/]]
|
34
|
+
• [[font6]]font6[[/]]
|
35
|
+
• [[font7]]font7[[/]]
|
36
|
+
• [[font8]]font8[[/]]
|
37
|
+
• [[font9]]font9[[/]]
|
38
|
+
• [[fraktur]]fraktur[[/]]
|
39
|
+
|
40
|
+
TEXT
|
41
|
+
|
42
|
+
UI.h2 '3-bit and 4-bit Colors' do |sec|
|
43
|
+
sec.space
|
44
|
+
colors = %w[black red green yellow blue magenta cyan white].freeze
|
45
|
+
(colors + colors.map { |name| "bright_#{name}" }).each do |name|
|
46
|
+
sec.puts " [[#{name}]]#{name.ljust(14)}[[/]] [[on_#{name}]]sample text"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
UI.space
|
50
|
+
|
51
|
+
UI.h2 '8-bit Colors' do |sec|
|
52
|
+
sec.space
|
53
|
+
sec.puts 'There are 256 pre-defined color which can be used by their index:'
|
54
|
+
sec.space
|
55
|
+
|
56
|
+
# helper:
|
57
|
+
colors_std = 0.upto(15)
|
58
|
+
colors216 = 16.upto(231).lazy
|
59
|
+
colors_gray1 = 232.upto(243)
|
60
|
+
colors_gray2 = 244.upto(255)
|
61
|
+
as_color = ->(i) { "[[#{i = i.to_s(16).rjust(2, '0')}]] #{i} [[/]]" }
|
62
|
+
as_bgcolor = ->(i) { "[[on:#{i.to_s(16).rjust(2, '0')}]] #{i} [[/]]" }
|
63
|
+
|
64
|
+
sec.puts colors_std.map(&as_color).join
|
65
|
+
colors216.each_slice(18) { |slice| sec.puts slice.map(&as_color).join }
|
66
|
+
sec.puts colors_gray1.map(&as_color).join
|
67
|
+
sec.puts colors_gray2.map(&as_color).join
|
68
|
+
|
69
|
+
sec.space
|
70
|
+
sec.puts colors_std.map(&as_bgcolor).join
|
71
|
+
colors216.each_slice(18) { |slice| sec.puts slice.map(&as_bgcolor).join }
|
72
|
+
sec.puts colors_gray1.map(&as_bgcolor).join
|
73
|
+
sec.puts colors_gray2.map(&as_bgcolor).join
|
74
|
+
end
|
75
|
+
|
76
|
+
UI.space
|
77
|
+
UI.h2 '24-bit colors' do |sec|
|
78
|
+
sec.puts <<~TEXT
|
79
|
+
|
80
|
+
Modern terminal applications support 24-bit colors for foreground and background
|
81
|
+
RGB-color values. Here are just some samples:
|
82
|
+
|
83
|
+
TEXT
|
84
|
+
|
85
|
+
some_rgb = DATA.readlines(chomp: true).lazy.each_slice(8)
|
86
|
+
|
87
|
+
some_rgb.each do |slice|
|
88
|
+
sec.puts slice.map { |v| " [[#{v}]]#{v}[[/]] " }.join
|
89
|
+
end
|
90
|
+
sec.space
|
91
|
+
some_rgb.each do |slice|
|
92
|
+
sec.puts slice.map { |v| " [[on:#{v}]]#{v}[[/]] " }.join
|
93
|
+
end
|
94
|
+
end
|
95
|
+
UI.space
|
96
|
+
|
97
|
+
__END__
|
98
|
+
#800000
|
99
|
+
#8b0000
|
100
|
+
#a52a2a
|
101
|
+
#b22222
|
102
|
+
#dc143c
|
103
|
+
#ff0000
|
104
|
+
#ff6347
|
105
|
+
#ff7f50
|
106
|
+
#cd5c5c
|
107
|
+
#f08080
|
108
|
+
#e9967a
|
109
|
+
#fa8072
|
110
|
+
#ffa07a
|
111
|
+
#ff4500
|
112
|
+
#ff8c00
|
113
|
+
#ffa500
|
114
|
+
#ffd700
|
115
|
+
#b8860b
|
116
|
+
#daa520
|
117
|
+
#eee8aa
|
118
|
+
#bdb76b
|
119
|
+
#f0e68c
|
120
|
+
#808000
|
121
|
+
#ffff00
|
122
|
+
#9acd32
|
123
|
+
#556b2f
|
124
|
+
#6b8e23
|
125
|
+
#7cfc00
|
126
|
+
#7fff00
|
127
|
+
#adff2f
|
128
|
+
#006400
|
129
|
+
#008000
|
130
|
+
#228b22
|
131
|
+
#00ff00
|
132
|
+
#32cd32
|
133
|
+
#90ee90
|
134
|
+
#98fb98
|
135
|
+
#8fbc8f
|
136
|
+
#00fa9a
|
137
|
+
#00ff7f
|
138
|
+
#2e8b57
|
139
|
+
#66cdaa
|
140
|
+
#3cb371
|
141
|
+
#20b2aa
|
142
|
+
#2f4f4f
|
143
|
+
#008080
|
144
|
+
#008b8b
|
145
|
+
#00ffff
|
146
|
+
#00ffff
|
147
|
+
#e0ffff
|
148
|
+
#00ced1
|
149
|
+
#40e0d0
|
150
|
+
#48d1cc
|
151
|
+
#afeeee
|
152
|
+
#7fffd4
|
153
|
+
#b0e0e6
|
154
|
+
#5f9ea0
|
155
|
+
#4682b4
|
156
|
+
#6495ed
|
157
|
+
#00bfff
|
158
|
+
#1e90ff
|
159
|
+
#add8e6
|
160
|
+
#87ceeb
|
161
|
+
#87cefa
|
data/examples/basic.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../lib/natty-ui'
|
3
|
+
require 'natty-ui'
|
5
4
|
|
6
5
|
UI = NattyUI::StdOut
|
7
6
|
|
@@ -9,15 +8,15 @@ UI.space
|
|
9
8
|
|
10
9
|
UI.h1 'NattyUI Basic Feature Demo', <<~TEXT
|
11
10
|
|
12
|
-
This is a short demo of the basic features of [[
|
11
|
+
This is a short demo of the basic features of [[75 bold]]NattyUI[[/]].
|
13
12
|
|
14
13
|
TEXT
|
15
14
|
|
16
15
|
UI.h2 'Feature: ANSI Colors and Attributes', <<~TEXT
|
17
16
|
|
18
|
-
Like you might noticed you can [[
|
17
|
+
Like you might noticed you can [[57]]color [[d7]]text[[/]] for terminals supporting this
|
19
18
|
feature. You can enforece the non-ANSI version by setting the environment
|
20
|
-
variable [[
|
19
|
+
variable [[75 italic]]NO_COLOR[[/]] to '[[75]]1[[/]]'. (see also [[underline]]https://no-color.org[[/]])
|
21
20
|
|
22
21
|
You can not only color your text but also [[italic]]modify[[/]], [[underline]]decorate[[/]] and [[strike]]manipulate[[/]]
|
23
22
|
it. The attributes are direct embedded into the text like '[[/bold red]]'
|
@@ -40,14 +39,14 @@ UI.h2 'Feature: Sections' do |sec|
|
|
40
39
|
sec.error 'Error Message'
|
41
40
|
sec.completed 'Completion Message'
|
42
41
|
sec.failed 'Failure Message'
|
43
|
-
sec.msg '[[
|
42
|
+
sec.msg '[[d5]]Customized Message', symbol: '◉'
|
44
43
|
sec.space
|
45
44
|
|
46
45
|
sec.puts 'You can stack all kinds of sections together:'
|
47
46
|
sec.space
|
48
|
-
sec.framed('
|
49
|
-
f1.framed('Heavy Framed
|
50
|
-
f2.framed('
|
47
|
+
sec.framed('Rouned Frame') do |f1|
|
48
|
+
f1.framed('Heavy Framed', type: :heavy) do |f2|
|
49
|
+
f2.framed('Simple Frame', type: :simple) do |f3|
|
51
50
|
f3.framed('Double Framed Section', type: :double) do |f4|
|
52
51
|
f4.message(
|
53
52
|
'[[fff400]]Frames are nice',
|
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
4
|
+
|
5
|
+
UI = NattyUI::StdOut
|
6
|
+
|
7
|
+
LOREM = <<~LOREM
|
8
|
+
Lorem ipsum dolor sit
|
9
|
+
amet, consectetur adipisicing
|
10
|
+
elit, sed do eiusmod tempor
|
11
|
+
incididunt ut labore et
|
12
|
+
dolore [[red]]magna[[/]] aliqua. Ut
|
13
|
+
enim ad minim veniam, quis
|
14
|
+
nostrud exercitation ullamco
|
15
|
+
laboris nisi ut aliquip ex
|
16
|
+
ea commodo [[bold]]consequat[[/]]. Duis
|
17
|
+
aute irure dolor in
|
18
|
+
reprehenderit in voluptate
|
19
|
+
velit [[underline]]esse cillum[[/]] dolore eu
|
20
|
+
fugiat nulla pariatur.
|
21
|
+
Excepteur sint occaecat
|
22
|
+
cupidatat non proident,
|
23
|
+
sunt in culpa qui officia
|
24
|
+
deserunt mollit anim id
|
25
|
+
est laborum.
|
26
|
+
LOREM
|
27
|
+
WORDS = LOREM.split(/\W+/).uniq.sort!.freeze
|
28
|
+
|
29
|
+
UI.space
|
30
|
+
UI.h2 'Print a list in columns'
|
31
|
+
UI.space
|
32
|
+
|
33
|
+
UI.h3 'Lorem ipsum lines'
|
34
|
+
UI.ls LOREM.lines(chomp: true)
|
35
|
+
UI.space
|
36
|
+
|
37
|
+
UI.h3 'Lorem ipsum word list (compact)'
|
38
|
+
UI.ls WORDS
|
39
|
+
UI.space
|
40
|
+
|
41
|
+
UI.h3 'Lorem ipsum word list (row-wise)'
|
42
|
+
UI.ls WORDS, compact: false
|
43
|
+
UI.space
|
data/examples/progress.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../lib/natty-ui'
|
3
|
+
require 'natty-ui'
|
5
4
|
|
6
5
|
UI = NattyUI::StdOut
|
7
6
|
|
@@ -10,75 +9,60 @@ UI.h1 'NattyUI Progress Indication Demo'
|
|
10
9
|
UI.space
|
11
10
|
|
12
11
|
# just simulate some work
|
13
|
-
def something = sleep(0.
|
12
|
+
def something = sleep(0.5)
|
14
13
|
def some = sleep(0.15)
|
15
14
|
|
16
|
-
UI.
|
17
|
-
|
18
|
-
|
19
|
-
progress.step
|
20
|
-
something
|
21
|
-
end
|
22
|
-
progress.done 'Progress ok'
|
23
|
-
|
24
|
-
progress = sec.progress('Simple progress')
|
25
|
-
20.times do
|
26
|
-
progress.step
|
27
|
-
some
|
28
|
-
end
|
29
|
-
progress.done 'All fine'
|
30
|
-
end
|
15
|
+
UI.info 'Tasks are sections to visualize step by step processing.' do |info|
|
16
|
+
info.task 'Assemble assets' do |task|
|
17
|
+
task.task('Initialize') { something }
|
31
18
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
task.task 'Compile files...' do |subtask|
|
37
|
-
%w[readme.txt main.css main.html sub.html].each do |name|
|
38
|
-
subtask.msg "Compile file [[bright_yellow]]./source/#{name}[[/]]..."
|
39
|
-
something
|
19
|
+
progress = task.progress 'Connect to server...'
|
20
|
+
20.times do
|
21
|
+
progress.step
|
22
|
+
some
|
40
23
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
task.msg 'Compressing...'
|
45
|
-
something
|
46
|
-
task.msg 'Signing...'
|
47
|
-
something
|
48
|
-
task.msg 'Store assembled results...'
|
49
|
-
something
|
50
|
-
end
|
24
|
+
progress.ok 'Connected'
|
25
|
+
|
26
|
+
task.task('Collect files...') { something }
|
51
27
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
28
|
+
task.task 'Compile files...' do |subtask|
|
29
|
+
%w[readme.txt main.css main.html sub.html].each do |name|
|
30
|
+
subtask.msg "Compile file [[bright_yellow]]./source/#{name}[[/]]..."
|
31
|
+
something
|
32
|
+
end
|
33
|
+
subtask.done 'Files compiled.'
|
34
|
+
end
|
56
35
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
36
|
+
progress = task.progress('Compress files', max_value: 11)
|
37
|
+
11.times do
|
38
|
+
progress.step
|
39
|
+
something
|
40
|
+
end
|
41
|
+
progress.done 'All compressed'
|
62
42
|
|
63
|
-
|
64
|
-
sec.task('Assemble assets') do |task|
|
65
|
-
assemble(task)
|
66
|
-
task.failed('Unable to store results', <<~ERROR)
|
67
|
-
Server reported Invalid credentials
|
68
|
-
Check your credentials and try again...
|
69
|
-
ERROR
|
43
|
+
task.task('Signing') { something }
|
70
44
|
|
71
|
-
|
45
|
+
task.task('Store assembled results') { something }
|
72
46
|
end
|
73
|
-
|
47
|
+
info.puts(
|
48
|
+
'The details are removed ([[italic]]in ANSI version[[/]]) when the task',
|
49
|
+
'ended sucessfully.'
|
50
|
+
)
|
51
|
+
end
|
74
52
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
task.done('Assets assembled', <<~INFO)
|
79
|
-
Your assets are ready on server now.
|
80
|
-
INFO
|
53
|
+
UI.info 'Details of failed tasks will not be cleaned.' do |info|
|
54
|
+
info.task 'Assemble assets' do |task|
|
55
|
+
task.task('Initialize') { something }
|
81
56
|
|
82
|
-
|
57
|
+
progress = task.progress 'Connect to server...'
|
58
|
+
20.times do
|
59
|
+
progress.step
|
60
|
+
some
|
61
|
+
end
|
62
|
+
progress.failed 'Unable to connect to server'
|
63
|
+
|
64
|
+
task.error 'This code will not be reachd!'
|
83
65
|
end
|
84
66
|
end
|
67
|
+
|
68
|
+
UI.space
|
data/examples/query.rb
CHANGED
@@ -1,32 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative '../lib/natty-ui'
|
3
|
+
require 'natty-ui'
|
5
4
|
|
6
5
|
UI = NattyUI::StdOut
|
7
6
|
|
8
7
|
UI.space
|
8
|
+
UI.h1 'NattyUI Query Demo'
|
9
|
+
UI.space
|
10
|
+
|
11
|
+
unless UI.ask('Do you like to continute? (Y|n)')
|
12
|
+
UI.failed 'aborted'
|
13
|
+
exit
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
choice =
|
17
|
+
UI.query(
|
18
|
+
'Which fruits do you prefer?',
|
19
|
+
'Apples',
|
20
|
+
'Bananas',
|
21
|
+
'Cherries',
|
22
|
+
x: 'No fruits',
|
23
|
+
result: :choice
|
24
|
+
)
|
25
|
+
unless choice
|
26
|
+
UI.failed 'aborted'
|
27
|
+
exit false
|
28
|
+
end
|
29
|
+
UI.info "Your choice: #{choice}"
|
30
|
+
|
31
|
+
answer = UI.request 'Are you okay?'
|
32
|
+
unless answer
|
33
|
+
UI.failed 'aborted'
|
34
|
+
exit false
|
35
|
+
end
|
36
|
+
UI.info "Your answer: #{answer.inspect}"
|
16
37
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
'Bananas',
|
22
|
-
'Cherries',
|
23
|
-
x: 'No fruits',
|
24
|
-
result: :choice
|
25
|
-
)
|
26
|
-
unless choice
|
27
|
-
sec.failed('aborted')
|
28
|
-
sec.close
|
29
|
-
exit(false)
|
30
|
-
end
|
31
|
-
sec.info("Your choice: #{choice}")
|
38
|
+
answer = UI.request('What is your current password?', password: true)
|
39
|
+
unless answer
|
40
|
+
UI.failed 'aborted'
|
41
|
+
exit false
|
32
42
|
end
|
43
|
+
UI.info "I'll keep your secret!"
|