natty-ui 0.8.0 → 0.9.1

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -2
  3. data/examples/24bit-colors.rb +11 -7
  4. data/examples/3bit-colors.rb +3 -2
  5. data/examples/8bit-colors.rb +2 -2
  6. data/examples/animate.rb +24 -0
  7. data/examples/attributes.rb +20 -65
  8. data/examples/demo.rb +39 -203
  9. data/examples/illustration.rb +27 -23
  10. data/examples/{list_in_columns.rb → ls.rb} +11 -11
  11. data/examples/message.rb +30 -0
  12. data/examples/progress.rb +2 -2
  13. data/examples/query.rb +6 -2
  14. data/examples/read_key.rb +13 -0
  15. data/examples/table.rb +26 -8
  16. data/lib/natty-ui/ansi.rb +364 -328
  17. data/lib/natty-ui/ansi_constants.rb +73 -0
  18. data/lib/natty-ui/ansi_wrapper.rb +68 -23
  19. data/lib/natty-ui/key_map.rb +119 -0
  20. data/lib/natty-ui/line_animation/default.rb +35 -0
  21. data/lib/natty-ui/line_animation/matrix.rb +28 -0
  22. data/lib/natty-ui/line_animation/rainbow.rb +30 -0
  23. data/lib/natty-ui/line_animation/test.rb +29 -0
  24. data/lib/natty-ui/line_animation/type_writer.rb +64 -0
  25. data/lib/natty-ui/line_animation.rb +54 -0
  26. data/lib/natty-ui/version.rb +1 -1
  27. data/lib/natty-ui/wrapper/animate.rb +17 -0
  28. data/lib/natty-ui/wrapper/ask.rb +2 -8
  29. data/lib/natty-ui/wrapper/framed.rb +26 -21
  30. data/lib/natty-ui/wrapper/heading.rb +1 -1
  31. data/lib/natty-ui/wrapper/horizontal_rule.rb +3 -3
  32. data/lib/natty-ui/wrapper/list_in_columns.rb +7 -4
  33. data/lib/natty-ui/wrapper/message.rb +4 -4
  34. data/lib/natty-ui/wrapper/progress.rb +33 -8
  35. data/lib/natty-ui/wrapper/query.rb +9 -13
  36. data/lib/natty-ui/wrapper/request.rb +2 -2
  37. data/lib/natty-ui/wrapper/section.rb +25 -11
  38. data/lib/natty-ui/wrapper/table.rb +11 -11
  39. data/lib/natty-ui/wrapper.rb +19 -14
  40. data/lib/natty-ui.rb +64 -32
  41. metadata +16 -5
  42. data/examples/illustration.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2010faafec270df6749dff93943748316c626939965e501dbe6bdb224514e2dc
4
- data.tar.gz: 0eecd3c29cc7b90cd70a6d40245b18fdbc8556232b6a3795ba2d92ffbaea5123
3
+ metadata.gz: 88f26cebef7a281c4b11df8e8accf096706d4308aa22d716bb516f9c85b51be6
4
+ data.tar.gz: 62fc6e920615b9f4536da8a9db33cc9e4261352d36a3423cdd11c64ab7b2e93c
5
5
  SHA512:
6
- metadata.gz: 6d2939a6c9bd6256a9de3e14b80ab9a67a6fa1108f20f2073e6ef0762789531016ef641bbfd451a0f3ac6c87079bd771a71853043744e481ed867616e392466e
7
- data.tar.gz: 106fc8ddca80ccf6eb8933fdf835d7373afba963df8625267f37b1a9795ac6be22671123e18baa72ec6b5ded1c3f76f98d5f4dd905de935d465a2751ce690fad
6
+ metadata.gz: 231f29c1bca8face152dbb63ed1c6137866a97941e092ed3db3f30ee2c372d71bbb10b1885100fd28691fb6093d2d4deab14fcf8d95fe05106cfc0c2d44d3b66
7
+ data.tar.gz: e39a9f14e9adfb4bfc1360cc9ee3dda19f96b3cce23afbf97da2315b184bf5b0b62f62c0f4e6fb283f22029d2902bc14623beec8cb42c45d528ea5168a5bb274
data/.yardopts CHANGED
@@ -1,10 +1,11 @@
1
- --readme README.md
2
1
  --title 'NattyUI Documentation'
3
2
  --charset utf-8
4
3
  --markup markdown
4
+ --readme README.md
5
+ --no-private
6
+ --embed-mixins
5
7
  --tag comment
6
8
  --hide-tag comment
7
- --embed-mixins
8
9
  --exclude lib/natty-ui/ansi_wrapper.rb
9
10
  lib/**/*.rb
10
11
  -
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
- RGB_COLORS = <<~RGB_COLORS.lines(chomp: true).map!(&:split)
5
+ ui.space
6
+ ui.h1 'NattyUI: 24-bit Color Support'
7
+ ui.space
8
+
9
+ RGB_COLORS = <<~SAMPLES.lines(chomp: true).map!(&:split)
6
10
  #800000 #8b0000 #a52a2a #b22222 #dc143c #ff0000 #ff6347 #ff7f50
7
11
  #cd5c5c #f08080 #e9967a #fa8072 #ffa07a #ff4500 #ff8c00 #ffa500
8
12
  #ffd700 #b8860b #daa520 #eee8aa #bdb76b #f0e68c #808000 #ffff00
@@ -11,13 +15,13 @@ RGB_COLORS = <<~RGB_COLORS.lines(chomp: true).map!(&:split)
11
15
  #2e8b57 #66cdaa #3cb371 #20b2aa #2f4f4f #008080 #008b8b #00ffff
12
16
  #00ffff #e0ffff #00ced1 #40e0d0 #48d1cc #afeeee #7fffd4 #b0e0e6
13
17
  #5f9ea0 #4682b4 #6495ed #00bfff #1e90ff #add8e6 #87ceeb #87cefa
14
- RGB_COLORS
15
-
16
- ui.space
17
- ui.h1 '24-bit Color Support'
18
- ui.space
18
+ SAMPLES
19
19
 
20
20
  RGB_COLORS.each { ui.puts _1.map { |v| " [[#{v}]]#{v}[[/]] " }.join }
21
21
  ui.space
22
22
  RGB_COLORS.each { ui.puts _1.map { |v| " [[on:#{v}]]#{v}[[/]] " }.join }
23
23
  ui.space
24
+ RGB_COLORS.each do |code|
25
+ ui.puts code.map { |v| " [[underline ul:#{v}]]#{v}[[/]] " }.join
26
+ end
27
+ ui.space
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
5
  ui.space
6
- ui.h1 '3/4-bit Color Support'
6
+ ui.h1 'NattyUI: 3/4-bit Color Support'
7
7
  ui.space
8
8
 
9
9
  color = ->(n) { "[[#{n}]]#{n.ljust(14)}[[/]] [[on_#{n}]] sample text [[/]]" }
10
10
  %w[black red green yellow blue magenta cyan white].each do |name|
11
11
  ui.puts "#{color[name]} #{color["bright_#{name}"]}"
12
12
  end
13
+
13
14
  ui.space
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
5
  ui.space
6
- ui.h1 '8-bit Color Support'
6
+ ui.h1 'NattyUI: 8-bit Color Support'
7
7
  ui.space
8
8
 
9
9
  color = ->(i) { "[[bg#{i = i.to_s(16).rjust(2, '0')}]] #{i} " }
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.space
6
+ ui.h1 'NattyUI: Text Line Animation'
7
+ ui.space
8
+
9
+ TEXT = <<~TEXT.tr("\n", ' ')
10
+ Lorem [[yellow]]ipsum[[/]] dolor sit amet, consectetur adipisicing elit, sed
11
+ do eiusmod tempor incididunt ut labore et dolore [[red]]magna[[/]] aliqua.
12
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
13
+ aliquip ex ea commodo [[bold]]consequat[[/]].
14
+ TEXT
15
+
16
+ {
17
+ default: 'Default Animation',
18
+ type_writer: 'Typewriter Like',
19
+ rainbow: 'Shiny Rainbow',
20
+ matrix: 'Matrix Style'
21
+ }.each_pair do |type, title|
22
+ ui.message(title, glyph: '[[27]]◉') { ui.animate TEXT, animation: type }
23
+ ui.space
24
+ end
@@ -1,72 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
5
  ui.space
6
- ui.h1 'NattyUI ANSI Attributes Demo'
7
- ui.puts <<~TEXT
8
-
9
- This text contains all supported ANSI attrubtes and explains the available
10
- colors.
11
-
12
- Please, keep in mind that no all terminals will support of all attributes and
13
- color types used in this text. In fact, you can use the output of this text to
14
- check the supported ANSI attributes.
15
-
16
- TEXT
17
-
18
- ui.h2 'Attributes'
19
- ui.puts <<~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
- [[fraktur]]fraktur[[/]]
30
- [[font1]]font1[[/]] [[font2]]font2[[/]] [[font3]]font3[[/]]
31
- [[font4]]font4[[/]] [[font5]]font5[[/]] [[font6]]font6[[/]]
32
- [[font7]]font7[[/]] [[font8]]font8[[/]] [[font9]]font9[[/]]
33
-
34
- TEXT
35
-
36
- ui.h2 '3-bit and 4-bit Colors'
37
- ui.space
38
- color = ->(n) { "[[#{n}]]#{n.ljust(14)}[[/]] [[on_#{n}]]sample text[[/]]" }
39
- %w[black red green yellow blue magenta cyan white].each do |name|
40
- ui.puts "#{color[name]} #{color["bright_#{name}"]}"
41
- end
6
+ ui.h2 'NattyUI: ANSI Attributes'
42
7
  ui.space
43
8
 
44
- ui.h2 '8-bit Colors'
45
- ui.space
46
- ui.puts 'There are 256 pre-defined color which can be used by their index:'
47
- ui.space
9
+ ui.puts <<~PARA1.tr("\n", ' '), <<~PARA2.tr("\n", ' ')
10
+ Some attributes are widely supported, such as [[bold]]bold[[/]],
11
+ [[italic]]italic[[/]], [[underline]]underline[[/]], [[blink]]blink[[/]],
12
+ [[invert]]invert[[/]] and [[strike]]strike[[/]], while others are rarely
13
+ complete or correctly implemented, like [[faint]]faint[[/]],
14
+ [[double_underline]]double underline[[/]], [[curly_underline]]curly
15
+ underline[[/]], [[dotted_underline]]dotted underline[[/]],
16
+ [[dashed_underline]]dashed underline[[/]], [[rapid_blink]]rapid_blink[[/]],
17
+ [[framed]]framed[[/]], [[encircled]]encircled[[/]],
18
+ [[overlined]]overlined[[/]] and [[proportional]]proportional[[/]].
19
+ PARA1
20
+ Alternative fonts are mostly completely ignored:
21
+ [[primary_font]]primary_font[[/]], [[fraktur]]fraktur[[/]],
22
+ [[font1]]font1[[/]], [[font2]]font2[[/]], [[font3]]font3[[/]],
23
+ [[font4]]font4[[/]], [[font5]]font5[[/]], [[font6]]font6[[/]],
24
+ [[font7]]font7[[/]], [[font8]]font8[[/]], [[font9]]font9[[/]].
25
+ PARA2
48
26
 
49
- color = ->(i) { "[[bg#{i.to_s(16).rjust(2, '0')}]] #{i.to_s.rjust(2)} " }
50
- ui.msg 'System Colors', glyph: '[[27]]◉' do
51
- ui.puts "[[#ff]]#{0.upto(7).map(&color).join}"
52
- ui.puts "[[#00]]#{8.upto(15).map(&color).join}"
53
- ui.space
54
- end
55
-
56
- color = ->(i) { "[[bg#{i.to_s(16)}]] #{i.to_s.rjust(3)} " }
57
- ui.msg '6x6x6 Color Cube', glyph: '[[27]]◉' do
58
- [16, 22, 28].each do |b|
59
- b.step(b + 185, by: 36) do |i|
60
- left = i.upto(i + 5).map(&color).join
61
- right = (i + 18).upto(i + 23).map(&color).join
62
- ui.puts "[[#ff]]#{left}[[bg_default]] #{right}"
63
- end
64
- ui.space
65
- end
66
-
67
- ui.msg 'Grayscale', glyph: '[[27]]◉' do
68
- ui.puts "[[#ff]]#{232.upto(243).map(&color).join}"
69
- ui.puts "[[#ff]]#{244.upto(255).map(&color).join}"
70
- ui.space
71
- end
72
- end
27
+ ui.space
data/examples/demo.rb CHANGED
@@ -1,217 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
- def attributes
6
- ui.puts <<~TEXT
7
-
8
- Some attributes are widely supported, such as [[bold]]bold[[/]], [[italic]]italic[[/]], [[underline]]underline[[/]], [[blink]]blink[[/]],
9
- [[invert]]invert[[/]] and [[strike]]strike[[/]], while others are rarely complete or correctly implemented,
10
- like [[faint]]faint[[/]], [[rapid_blink]]rapid_blink[[/]], [[double_underline]]double_underline[[/]], [[framed]]framed[[/]], [[encircled]]encircled[[/]], [[overlined]]overlined[[/]],
11
- [[proportional]]proportional[[/]] and [[spacing]]spacing[[/]].
12
-
13
- Different font types are very rarely displayed:
14
-
15
- [[primary_font]]primary_font[[/]]
16
- [[fraktur]]fraktur[[/]]
17
- [[font1]]font1[[/]] [[font2]]font2[[/]] [[font3]]font3[[/]]
18
- [[font4]]font4[[/]] [[font5]]font5[[/]] [[font6]]font6[[/]]
19
- [[font7]]font7[[/]] [[font8]]font8[[/]] [[font9]]font9[[/]]
20
-
21
- TEXT
22
- end
23
-
24
- def colors_3bit
25
- color = ->(n) { "[[#{n}]]#{n.ljust(14)}[[/]] [[on_#{n}]]sample text[[/]]" }
26
- %w[black red green yellow blue magenta cyan white].each do |name|
27
- ui.puts "#{color[name]} #{color["bright_#{name}"]}"
28
- end
29
- end
30
-
31
- def colors_8bit
32
- color = ->(i) { "[[bg#{i.to_s(16).rjust(2, '0')}]] #{i.to_s.rjust(2)} " }
33
- ui.msg 'System Colors', glyph: '[[27]]◉' do
34
- ui.puts "[[#ff]]#{0.upto(7).map(&color).join}"
35
- ui.puts "[[#00]]#{8.upto(15).map(&color).join}"
36
- ui.space
37
- end
38
-
39
- color = ->(i) { "[[bg#{i.to_s(16)}]] #{i.to_s.rjust(3)} " }
40
- ui.msg '6x6x6 Color Cube', glyph: '[[27]]◉' do
41
- [16, 22, 28].each do |b|
42
- b.step(b + 185, by: 36) do |i|
43
- left = i.upto(i + 5).map(&color).join
44
- right = (i + 18).upto(i + 23).map(&color).join
45
- ui.puts "[[#ff]]#{left}[[bg_default]] #{right}"
46
- end
47
- ui.space
48
- end
49
- end
50
-
51
- ui.msg 'Grayscale', glyph: '[[27]]◉' do
52
- ui.puts "[[#ff]]#{232.upto(243).map(&color).join}"
53
- ui.puts "[[#ff]]#{244.upto(255).map(&color).join}"
54
- ui.space
55
- end
56
- end
57
-
58
- def colors_24bit
59
- ui.puts <<~TEXT
60
- Modern terminal applications support 24-bit colors for foreground and background
61
- RGB-color values. Here are just some samples:
62
-
63
- TEXT
64
- RGB_COLORS.each { ui.puts _1.map { |v| " [[#{v}]]#{v}[[/]] " }.join }
5
+ ui.page do
6
+ ui.space
7
+ ui.h1 'NattyUI: Examples'
65
8
  ui.space
66
- RGB_COLORS.each { ui.puts _1.map { |v| " [[on:#{v}]]#{v}[[/]] " }.join }
67
- end
68
9
 
69
- def sections
70
- ui.section do
71
- ui.puts 'Sections can be stacked'
72
- ui.section do
73
- ui.puts TEXT_MID
74
- ui.framed do
75
- ui.puts TEXT_MID
76
- next unless block_given?
77
- ui.space
78
- ui.hr
79
- ui.space
80
- yield
81
- end
10
+ ruby =
11
+ ENV.fetch('RUBY') do
12
+ require('rbconfig')
13
+ File.join(
14
+ RbConfig::CONFIG['bindir'],
15
+ "#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}"
16
+ ).sub(/.*\s.*/m, '"\&"')
82
17
  end
83
- end
84
- end
85
-
86
- def heading
87
- ui.h1 'This Is A H1 Heading'
88
- ui.h2 'This Is A H2 Heading'
89
- ui.h3 'This Is A H3 Heading'
90
- ui.h4 'This Is A H4 Heading'
91
- ui.h5 'This Is A H5 Heading'
92
- end
18
+ run = ->(name) { system(ruby, File.join(__dir__, "#{name}.rb")) }
19
+ run['illustration']
93
20
 
94
- def messages
95
- ui.info 'Informative Message', TEXT_MID
96
- ui.warning 'Warning Message', TEXT_MID
97
- ui.error 'Error Message', TEXT_MID
98
- ui.message '[[italic #fad]]Custom Message', TEXT_MID, glyph: '💡'
99
- ui.failed 'Fail Message', TEXT_MID
100
- end
101
-
102
- def list_in_columns
103
- ui.ls TEXT_LINES
104
- ui.hr
105
- ui.ls TEXT_LINES, compact: false
106
- end
21
+ ui.space
107
22
 
108
- def tasks
109
- ui.task('Initialize') { something }
110
- ui.task('Establish server connection') do
111
- ui.task('Open connection') { something }
112
- ui.task('Send HELO') { something }
113
- ui.task('Receive OLEH') { something }
114
- ui.task('Send credentials') { something }
115
- ui.task('Credentials accepted') { something }
23
+ choices = {}
24
+ examples = {}
25
+ {
26
+ '1' => ['attributes', 'ANSI Attributes'],
27
+ '2' => ['message', 'Message Types'],
28
+ '3' => ['3bit-colors', '3/4-bit Color Support'],
29
+ '4' => ['8bit-colors', '8-bit Color Support'],
30
+ '5' => ['24bit-colors', '24-bit Color Support'],
31
+ '6' => ['ls', 'Print In Columns'],
32
+ '7' => %w[table Tables],
33
+ '8' => ['animate', 'Text Line Animation'],
34
+ '9' => ['progress', 'Progress Indication'],
35
+ '0' => ['query', 'User Queries'],
36
+ 'ESC' => [nil, 'Exit Demo']
37
+ }.each_pair do |key, (name, descr)|
38
+ examples[key] = name
39
+ choices[key] = descr
116
40
  end
117
- ui.task 'Loading files' do
118
- %w[readme.txt main.css main.html sub.html].each do |name|
119
- ui.msg "Load file [[bright_yellow]]./source/#{name}[[/]]..."
120
- something
121
- end
122
- ui.done 'Files loaded'
123
- end
124
- progress = ui.progress('Compress files', max_value: 11)
125
- 11.times do
126
- progress.step
127
- something
128
- end
129
- progress.done 'All compressed'
130
- end
131
-
132
- def table
133
- ui.table { |tab| TEXT.each_line(chomp: true).each_slice(5) { tab.add(*_1) } }
134
- end
135
41
 
136
- # just simulate some work
137
- def something = sleep(0.5)
138
- def some = sleep(0.15)
139
-
140
- TEXT = <<~LOREM
141
- Lorem [[yellow]]ipsum[[/]] dolor sit
142
- amet, consectetur adipisicing
143
- elit, sed do eiusmod tempor
144
- incididunt ut labore et
145
- dolore [[red]]magna[[/]] aliqua. Ut
146
- enim ad minim veniam, quis
147
- nostrud exercitation ullamco
148
- laboris nisi ut aliquip ex
149
- ea commodo [[bold]]consequat[[/]]. Duis
150
- aute irure [[bold green]]dolor[[/]] in
151
- reprehenderit in voluptate
152
- velit [[underline]]esse cillum[[/]] dolore eu
153
- fugiat nulla pariatur.
154
- Excepteur sint occaecat
155
- cupidatat non proident,
156
- sunt in culpa qui officia
157
- deserunt mollit anim id
158
- est laborum.
159
- LOREM
160
- TEXT_LINES = TEXT.lines(chomp: true)
161
- TEXT_MID = TEXT_LINES.take(8).join(' ')
162
- TEXT_BIG = TEXT_LINES.join(' ')
163
- RGB_COLORS = <<~RGB_COLORS.lines(chomp: true).map!(&:split)
164
- #800000 #8b0000 #a52a2a #b22222 #dc143c #ff0000 #ff6347 #ff7f50
165
- #cd5c5c #f08080 #e9967a #fa8072 #ffa07a #ff4500 #ff8c00 #ffa500
166
- #ffd700 #b8860b #daa520 #eee8aa #bdb76b #f0e68c #808000 #ffff00
167
- #9acd32 #556b2f #6b8e23 #7cfc00 #7fff00 #adff2f #006400 #008000
168
- #228b22 #00ff00 #32cd32 #90ee90 #98fb98 #8fbc8f #00fa9a #00ff7f
169
- #2e8b57 #66cdaa #3cb371 #20b2aa #2f4f4f #008080 #008b8b #00ffff
170
- #00ffff #e0ffff #00ced1 #40e0d0 #48d1cc #afeeee #7fffd4 #b0e0e6
171
- #5f9ea0 #4682b4 #6495ed #00bfff #1e90ff #add8e6 #87ceeb #87cefa
172
- RGB_COLORS
173
-
174
- ui.page do
175
- ui.h1 'NattyUI Demo'
176
42
  loop do
177
- ui.space
178
- choice, title =
43
+ choice =
179
44
  ui.query(
180
- 'Which Demo part do you like to see?',
181
- :a => 'Attributes',
182
- '3' => '3-bit and 4-bit Colors',
183
- '8' => '8-bit Colors',
184
- '2' => '24-bit colors',
185
- 'l' => 'List in Columns',
186
- 's' => 'Sections',
187
- 'S' => 'Sections with lists',
188
- 'z' => 'Sections with table',
189
- 't' => 'Tasks',
190
- :q => 'Quit Demo',
191
- :result => :all,
192
- :display => :compact
193
- )
194
- break if choice.nil? || choice == 'q'
195
- ui.cls.h2(title).space
196
- case choice
197
- when 'a'
198
- attributes
199
- when '3'
200
- colors_3bit
201
- when '8'
202
- colors_8bit
203
- when '2'
204
- colors_24bit
205
- when 't'
206
- tasks
207
- when 'l'
208
- list_in_columns
209
- when 's'
210
- sections { messages }
211
- when 'S'
212
- sections { list_in_columns }
213
- when 'z'
214
- sections { table }
215
- end
45
+ 'Which example do you like to watch?',
46
+ display: :compact,
47
+ **choices
48
+ ) or break
49
+ example = examples[choice] or break
50
+ ui.cls
51
+ run[example]
216
52
  end
217
53
  end
@@ -1,26 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
- ui.space
6
- ui.msg('Natty UI', glyph: '⭐️') { ui.puts <<~TEXT }
7
- This is the [[c4]]beautiful[[/]], [[c5]]nice[[/]], [[c6]]nifty[[/]], [[c7]]fancy[[/]], [[c8]]neat[[/]], [[c9]]pretty[[/]], [[ca]]cool[[/]],
8
- [[cb]]lovely[[/]], [[cc]]natty[[/]] [[bold]]user interface[[/]] you like to have for your command
9
- line applications. It contains [[italic]]elegant[[/]], [[italic]]simple[[/]] and [[italic]]beautiful[[/]]
10
- tools that enhance your command line interfaces functionally and
11
- aesthetically.
12
- TEXT
13
- ui.msg('Features', glyph: '⭐️') { ui.ls(<<~FEATURES.lines(chomp: true)) }
14
- [[bold red]]T[[/]] text attributes
15
- 🌈 text coloring
16
- 🎩 heading elements
17
- 📏 horizontal rulers
18
- 📝 message blocks
19
- task blocks
20
- [[bold blue]]""[[/]] quote blocks
21
- 🖼️ framed blocks
22
- [[yellow]]┼┼[[/]] tables
23
- 💯 progress bars
24
- [[bold red]]?[[/]] ask question
25
- [[bold bright_white]]>[[bright_red]]_[[/]] user input
26
- FEATURES
5
+ ui.framed do
6
+ ui.msg('Natty UI', <<~TEXT.tr("\n", ' '), glyph: '⭐️')
7
+ This is the [[c4]]beautiful[[/]], [[c5]]nice[[/]], [[c6]]nifty[[/]],
8
+ [[c7]]fancy[[/]], [[c8]]neat[[/]], [[c9]]pretty[[/]], [[ca]]cool[[/]],
9
+ [[cb]]lovely[[/]], [[cc]]natty[[/]] [[bold]]user interface[[/]] you like to
10
+ have for your command line applications. It contains
11
+ [[curly_underline ul_c4]]elegant[[/]], [[italic]]simple[[/]] and
12
+ [[double_underline ul_cc]]beautiful[[/]] tools that enhance your command
13
+ line interfaces functionally and aesthetically.
14
+ TEXT
15
+
16
+ ui.msg('Features', glyph: '⭐️') { ui.ls(<<~FEATURES.lines(chomp: true)) }
17
+ [[bold red]]T[[/]] text attributes
18
+ 🌈 text coloring
19
+ 🔦 text animation
20
+ 🎩 heading elements
21
+ 📏 horizontal rulers
22
+ 📝 messages
23
+ [[bold blue]]""[[/]] quote blocks
24
+ [[yellow]]🄵[[/]] framed blocks
25
+ tasks
26
+ [[bold green]]…[[/]] progress bars
27
+ [[blue]]┼┼[[/]] tables
28
+ [[bold bright_white]]>[[bright_red]]_[[/]] user input
29
+ FEATURES
30
+ end
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
- LOREM = <<~LOREM
5
+ ui.space
6
+ ui.h1 'NattyUI: Print In Columns'
7
+ ui.space
8
+
9
+ LOREM = <<~IPSUM.lines(chomp: true)
6
10
  Lorem ipsum dolor sit
7
11
  amet, consectetur adipisicing
8
12
  elit, sed do eiusmod tempor
@@ -21,16 +25,12 @@ LOREM = <<~LOREM
21
25
  sunt in culpa qui officia
22
26
  deserunt mollit anim id
23
27
  est laborum.
24
- LOREM
25
-
26
- ui.space
27
- ui.h1 'Print a list in columns'
28
- ui.space
28
+ IPSUM
29
29
 
30
- ui.h2 'Lorem ipsum lines (compact)'
31
- ui.ls LOREM.lines(chomp: true), glyph: 1
30
+ ui.h2 'Compact Display'
31
+ ui.ls LOREM, glyph: 1
32
32
  ui.space
33
33
 
34
- ui.h2 'Lorem ipsum lines (row-wise)'
35
- ui.ls LOREM.lines(chomp: true), glyph: 1, compact: false
34
+ ui.h2 'Traditional Display'
35
+ ui.ls LOREM, glyph: 1, compact: false
36
36
  ui.space
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.space
6
+ ui.h1 'NattyUI: Message Types'
7
+ ui.space
8
+
9
+ TEXT = <<~TEXT.tr("\n", ' ')
10
+ Lorem [[yellow]]ipsum[[/]] dolor sit amet, consectetur adipisicing elit, sed
11
+ do eiusmod tempor incididunt ut labore et dolore [[red]]magna[[/]] aliqua.
12
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
13
+ aliquip ex ea commodo [[bold]]consequat[[/]].
14
+ TEXT
15
+
16
+ IMPORTANT =
17
+ '[[red]]>>>[[/]] [[italic]]Here some important information[[/]] [[red]]<<<'
18
+
19
+ ui.framed do
20
+ ui.info 'Informative Message', TEXT
21
+ ui.warning 'Warning Message' do
22
+ ui.puts TEXT
23
+ ui.framed { ui.puts IMPORTANT }
24
+ end
25
+ ui.error 'Error Message', TEXT
26
+ ui.failed 'Fail Message', TEXT
27
+ ui.message '[[italic #fad]]Custom Message', TEXT, glyph: '💡'
28
+ end
29
+
30
+ ui.space
data/examples/progress.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
5
  ui.space
6
- ui.h1 'NattyUI Progress Indication Demo'
6
+ ui.h1 'NattyUI: Progress Indication'
7
7
  ui.space
8
8
 
9
9
  # just simulate some work
data/examples/query.rb CHANGED
@@ -1,19 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
5
  ui.space
6
- ui.h1 'NattyUI Query Demo'
6
+ ui.h1 'NattyUI: User Queries'
7
7
  ui.space
8
8
 
9
9
  # little helper
10
10
  def abort!
11
11
  ui.failed 'aborted'
12
+ ui.space
12
13
  exit
13
14
  end
14
15
 
15
16
  unless ui.ask('Do you like to continute? (Y|n): ')
16
17
  ui.info 'ok, try later!'
18
+ ui.space
17
19
  exit
18
20
  end
19
21
 
@@ -35,3 +37,5 @@ ui.info "Your answer: #{answer.inspect}"
35
37
  answer = ui.request('What is your current password?:', password: true)
36
38
  abort! unless answer
37
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