natty-ui 0.7.0 β 0.8.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 +4 -1
- data/README.md +25 -47
- data/examples/24bit-colors.rb +23 -0
- data/examples/3bit-colors.rb +13 -0
- data/examples/8bit-colors.rb +31 -0
- data/examples/attributes.rb +41 -130
- data/examples/demo.rb +217 -0
- data/examples/illustration.png +0 -0
- data/examples/illustration.rb +26 -0
- data/examples/list_in_columns.rb +10 -17
- data/examples/progress.rb +24 -29
- data/examples/query.rb +21 -27
- data/examples/table.rb +18 -0
- data/lib/natty-ui/ansi.rb +81 -61
- data/lib/natty-ui/ansi_wrapper.rb +92 -163
- data/lib/natty-ui/features.rb +11 -18
- data/lib/natty-ui/version.rb +2 -2
- data/lib/natty-ui/wrapper/ask.rb +26 -20
- data/lib/natty-ui/wrapper/element.rb +19 -23
- data/lib/natty-ui/wrapper/framed.rb +23 -18
- 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 +66 -10
- data/lib/natty-ui/wrapper/message.rb +20 -27
- data/lib/natty-ui/wrapper/progress.rb +10 -8
- data/lib/natty-ui/wrapper/query.rb +37 -30
- 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 +43 -41
- data/lib/natty-ui/wrapper/table.rb +298 -0
- data/lib/natty-ui/wrapper/task.rb +6 -7
- data/lib/natty-ui/wrapper.rb +118 -41
- data/lib/natty-ui.rb +43 -39
- metadata +15 -8
- data/examples/basic.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2010faafec270df6749dff93943748316c626939965e501dbe6bdb224514e2dc
|
4
|
+
data.tar.gz: 0eecd3c29cc7b90cd70a6d40245b18fdbc8556232b6a3795ba2d92ffbaea5123
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d2939a6c9bd6256a9de3e14b80ab9a67a6fa1108f20f2073e6ef0762789531016ef641bbfd451a0f3ac6c87079bd771a71853043744e481ed867616e392466e
|
7
|
+
data.tar.gz: 106fc8ddca80ccf6eb8933fdf835d7373afba963df8625267f37b1a9795ac6be22671123e18baa72ec6b5ded1c3f76f98d5f4dd905de935d465a2751ce690fad
|
data/.yardopts
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# NattyUI 
|
2
2
|
|
3
|
-
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely, natty user interface you like to have for your command line interfaces
|
3
|
+
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely, natty user interface you like to have for your command line applications. It contains elegant, simple and beautiful tools that enhance your command line interfaces functionally and aesthetically.
|
4
4
|
|
5
5
|
- Gem: [rubygems.org](https://rubygems.org/gems/natty-ui)
|
6
6
|
- Source: [github.com](https://github.com/mblumtritt/natty-ui)
|
@@ -13,40 +13,43 @@ Here you find elegant, simple and beautiful tools that enhance your command line
|
|
13
13
|
You can simply decorate your text with named ANSI attributes and colors
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
|
17
|
-
|
18
|
-
UI.puts "[[bold]]Hello [[ff7bfd]]World[[/]]!"
|
16
|
+
ui.puts "[[bold]]Hello [[ff7bfd]]World[[/]]!"
|
19
17
|
```
|
20
18
|
|
21
19
|
or use different types of messages
|
22
20
|
|
23
21
|
```ruby
|
24
|
-
|
25
|
-
|
22
|
+
ui.info 'NattyUI installed'
|
23
|
+
ui.warning 'Nice gem found!'
|
26
24
|
```
|
27
25
|
|
28
|
-
and headings
|
26
|
+
and headings, framed sections, progress bars and tasks, queries, tables and much much moreβ¦
|
29
27
|
|
30
|
-
|
31
|
-
UI.h1 'The Main Title (TMT)'
|
32
|
-
UI.h2 'A Subtitle'
|
33
|
-
```
|
28
|
+
π Have a look at the [features](https://rubydoc.info/gems/natty-ui/NattyUI/Features)!
|
34
29
|
|
35
|
-
|
30
|
+

|
36
31
|
|
37
|
-
|
38
|
-
UI.framed 'Text Below In Frame' do |framed|
|
39
|
-
framed.puts 'This is the text'
|
40
|
-
end
|
41
|
-
```
|
32
|
+
## NO_COLOR Convention
|
42
33
|
|
43
|
-
|
34
|
+
NattyUI follows the [NO_COLOR convention](https://no-color.org).
|
44
35
|
|
45
|
-
|
36
|
+
## Help
|
46
37
|
|
47
|
-
π See the [online help](https://rubydoc.info/gems/natty-ui/NattyUI)
|
38
|
+
π See the [online help](https://rubydoc.info/gems/natty-ui/NattyUI) and have a look at the [examples](./examples/) directory to learn from code.
|
48
39
|
|
49
|
-
|
40
|
+
### Run Examples
|
41
|
+
|
42
|
+
You can execute the examples by
|
43
|
+
|
44
|
+
```sh
|
45
|
+
ruby ./examples/demo.rb
|
46
|
+
```
|
47
|
+
|
48
|
+
or see the non-ANSI version
|
49
|
+
|
50
|
+
```sh
|
51
|
+
NO_COLOR=1 ruby ./examples/demo.rb
|
52
|
+
```
|
50
53
|
|
51
54
|
## Installation
|
52
55
|
|
@@ -59,7 +62,7 @@ gem install natty-ui
|
|
59
62
|
or you can use [Bundler](http://gembundler.com/) to add NattyUI to your own project:
|
60
63
|
|
61
64
|
```shell
|
62
|
-
bundle add
|
65
|
+
bundle add natty-ui
|
63
66
|
```
|
64
67
|
|
65
68
|
After that you only need one line of code to have everything together
|
@@ -67,28 +70,3 @@ After that you only need one line of code to have everything together
|
|
67
70
|
```ruby
|
68
71
|
require 'natty-ui'
|
69
72
|
```
|
70
|
-
|
71
|
-
## Run Examples
|
72
|
-
|
73
|
-
You can execute the examples by
|
74
|
-
|
75
|
-
```sh
|
76
|
-
bundle exec ruby ./examples/basic.rb
|
77
|
-
```
|
78
|
-
|
79
|
-
or see the non-ANSI version
|
80
|
-
|
81
|
-
```sh
|
82
|
-
NO_COLOR=1 bundle exec ruby ./examples/basic.rb
|
83
|
-
```
|
84
|
-
|
85
|
-
## NO_COLOR Convention
|
86
|
-
|
87
|
-
NattyUI follows the [NO_COLOR convention](https://no-color.org).
|
88
|
-
|
89
|
-
## TODO
|
90
|
-
|
91
|
-
Since I did not complete the tests and not all my ideas are already implemented I have this Todo list:
|
92
|
-
|
93
|
-
- add more samples to help
|
94
|
-
- add more tests
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
4
|
+
|
5
|
+
RGB_COLORS = <<~RGB_COLORS.lines(chomp: true).map!(&:split)
|
6
|
+
#800000 #8b0000 #a52a2a #b22222 #dc143c #ff0000 #ff6347 #ff7f50
|
7
|
+
#cd5c5c #f08080 #e9967a #fa8072 #ffa07a #ff4500 #ff8c00 #ffa500
|
8
|
+
#ffd700 #b8860b #daa520 #eee8aa #bdb76b #f0e68c #808000 #ffff00
|
9
|
+
#9acd32 #556b2f #6b8e23 #7cfc00 #7fff00 #adff2f #006400 #008000
|
10
|
+
#228b22 #00ff00 #32cd32 #90ee90 #98fb98 #8fbc8f #00fa9a #00ff7f
|
11
|
+
#2e8b57 #66cdaa #3cb371 #20b2aa #2f4f4f #008080 #008b8b #00ffff
|
12
|
+
#00ffff #e0ffff #00ced1 #40e0d0 #48d1cc #afeeee #7fffd4 #b0e0e6
|
13
|
+
#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
|
19
|
+
|
20
|
+
RGB_COLORS.each { ui.puts _1.map { |v| " [[#{v}]]#{v}[[/]] " }.join }
|
21
|
+
ui.space
|
22
|
+
RGB_COLORS.each { ui.puts _1.map { |v| " [[on:#{v}]]#{v}[[/]] " }.join }
|
23
|
+
ui.space
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
4
|
+
|
5
|
+
ui.space
|
6
|
+
ui.h1 '3/4-bit Color Support'
|
7
|
+
ui.space
|
8
|
+
|
9
|
+
color = ->(n) { "[[#{n}]]#{n.ljust(14)}[[/]] [[on_#{n}]] sample text [[/]]" }
|
10
|
+
%w[black red green yellow blue magenta cyan white].each do |name|
|
11
|
+
ui.puts "#{color[name]} #{color["bright_#{name}"]}"
|
12
|
+
end
|
13
|
+
ui.space
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
4
|
+
|
5
|
+
ui.space
|
6
|
+
ui.h1 '8-bit Color Support'
|
7
|
+
ui.space
|
8
|
+
|
9
|
+
color = ->(i) { "[[bg#{i = i.to_s(16).rjust(2, '0')}]] #{i} " }
|
10
|
+
ui.msg 'System Colors', glyph: '[[27]]β' do
|
11
|
+
ui.puts "[[#ff]]#{0.upto(7).map(&color).join}"
|
12
|
+
ui.puts "[[#00]]#{8.upto(15).map(&color).join}"
|
13
|
+
ui.space
|
14
|
+
end
|
15
|
+
|
16
|
+
ui.msg '6x6x6 Color Cube', glyph: '[[27]]β' do
|
17
|
+
[16, 22, 28].each do |b|
|
18
|
+
b.step(b + 185, by: 36) do |i|
|
19
|
+
left = i.upto(i + 5).map(&color).join
|
20
|
+
right = (i + 18).upto(i + 23).map(&color).join
|
21
|
+
ui.puts "[[#ff]]#{left}[[bg_default]] #{right}"
|
22
|
+
end
|
23
|
+
ui.space
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ui.msg 'Grayscale', glyph: '[[27]]β' do
|
28
|
+
ui.puts "[[#ff]]#{232.upto(243).map(&color).join}"
|
29
|
+
ui.puts "[[#ff]]#{244.upto(255).map(&color).join}"
|
30
|
+
ui.space
|
31
|
+
end
|
data/examples/attributes.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'natty-ui'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
UI.h1 'NattyUI ANSI Attributes Demo', <<~TEXT
|
5
|
+
ui.space
|
6
|
+
ui.h1 'NattyUI ANSI Attributes Demo'
|
7
|
+
ui.puts <<~TEXT
|
9
8
|
|
10
9
|
This text contains all supported ANSI attrubtes and explains the available
|
11
10
|
colors.
|
@@ -16,7 +15,8 @@ UI.h1 'NattyUI ANSI Attributes Demo', <<~TEXT
|
|
16
15
|
|
17
16
|
TEXT
|
18
17
|
|
19
|
-
|
18
|
+
ui.h2 'Attributes'
|
19
|
+
ui.puts <<~TEXT
|
20
20
|
|
21
21
|
Some attributes are widely supported, such as [[bold]]bold[[/]], [[italic]]italic[[/]], [[underline]]underline[[/]], [[blink]]blink[[/]],
|
22
22
|
[[invert]]invert[[/]] and [[strike]]strike[[/]], while others are rarely complete or correctly implemented,
|
@@ -25,137 +25,48 @@ UI.h2 'Attributes', <<~TEXT
|
|
25
25
|
|
26
26
|
Different font types are very rarely displayed:
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
β’ [[font5]]font5[[/]]
|
34
|
-
β’ [[font6]]font6[[/]]
|
35
|
-
β’ [[font7]]font7[[/]]
|
36
|
-
β’ [[font8]]font8[[/]]
|
37
|
-
β’ [[font9]]font9[[/]]
|
38
|
-
β’ [[fraktur]]fraktur[[/]]
|
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[[/]]
|
39
33
|
|
40
34
|
TEXT
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
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}"]}"
|
48
41
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
42
|
+
ui.space
|
43
|
+
|
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
|
48
|
+
|
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
|
74
54
|
end
|
75
55
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
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
|
89
65
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
93
71
|
end
|
94
72
|
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/demo.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
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 }
|
65
|
+
ui.space
|
66
|
+
RGB_COLORS.each { ui.puts _1.map { |v| " [[on:#{v}]]#{v}[[/]] " }.join }
|
67
|
+
end
|
68
|
+
|
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
|
82
|
+
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
|
93
|
+
|
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
|
107
|
+
|
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 }
|
116
|
+
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
|
+
|
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
|
+
loop do
|
177
|
+
ui.space
|
178
|
+
choice, title =
|
179
|
+
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
|
216
|
+
end
|
217
|
+
end
|
data/examples/illustration.png
CHANGED
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'natty-ui'
|
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
|