natty-ui 0.9.4 → 0.11.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/README.md +4 -11
- data/examples/24bit-colors.rb +8 -16
- data/examples/3bit-colors.rb +1 -1
- data/examples/8bit-colors.rb +15 -11
- data/examples/animate.rb +31 -11
- data/examples/attributes.rb +16 -14
- data/examples/attributes_list.rb +14 -0
- data/examples/demo.rb +4 -4
- data/examples/illustration.rb +52 -24
- data/examples/ls.rb +4 -4
- data/examples/message.rb +11 -9
- data/examples/progress.rb +2 -2
- data/examples/query.rb +1 -1
- data/examples/table.rb +23 -23
- data/lib/natty-ui/animation/binary.rb +37 -0
- data/lib/natty-ui/animation/default.rb +42 -0
- data/lib/natty-ui/animation/matrix.rb +55 -0
- data/lib/natty-ui/animation/rainbow.rb +28 -0
- data/lib/natty-ui/animation/type_writer.rb +44 -0
- data/lib/natty-ui/animation.rb +69 -0
- data/lib/natty-ui/ansi/constants.rb +1 -1
- data/lib/natty-ui/ansi.rb +46 -26
- data/lib/natty-ui/ansi_wrapper.rb +47 -51
- data/lib/natty-ui/key_map.rb +72 -49
- data/lib/natty-ui/preload.rb +1 -1
- data/lib/natty-ui/text.rb +75 -85
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/wrapper/animate.rb +1 -1
- data/lib/natty-ui/wrapper/ask.rb +1 -1
- data/lib/natty-ui/wrapper/element.rb +18 -10
- data/lib/natty-ui/wrapper/features.rb +0 -8
- data/lib/natty-ui/wrapper/framed.rb +7 -27
- data/lib/natty-ui/wrapper/message.rb +1 -1
- data/lib/natty-ui/wrapper/request.rb +1 -1
- data/lib/natty-ui/wrapper/section.rb +18 -18
- data/lib/natty-ui/wrapper/table.rb +432 -168
- data/lib/natty-ui/wrapper.rb +45 -48
- data/lib/natty-ui.rb +65 -2
- metadata +10 -8
- data/lib/natty-ui/line_animation/default.rb +0 -35
- data/lib/natty-ui/line_animation/matrix.rb +0 -28
- data/lib/natty-ui/line_animation/rainbow.rb +0 -30
- data/lib/natty-ui/line_animation/type_writer.rb +0 -44
- data/lib/natty-ui/line_animation.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbaeb874eda95058545f313e3b0c2ea93235681c917b35419d3d6c1d00da96b0
|
4
|
+
data.tar.gz: 8af26d5eddcfd85a61053ccde48eef9c8fd5a12a67ebd22d2a904adba29deba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3203253d6b8142f3b4bc31e4c2f3c065313bc41b3629d426d0b51bf2c1c0ca26cdb12c91c08c014b261180836cda36534cec0d43a96bf681beeac183ed010cf5
|
7
|
+
data.tar.gz: b3e2b15c64aca2aa9b7e955414e902ea103a04427487a06f64c24bd6c6173c230122fa7e65df5cf82cbf45fe1783374fa87704da17a976e3bb5bc56bf52ab254
|
data/README.md
CHANGED
@@ -10,22 +10,15 @@ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely, natty use
|
|
10
10
|
|
11
11
|
Here you find elegant, simple and beautiful tools that enhance your command line application functionally and look.
|
12
12
|
|
13
|
-
You can
|
13
|
+
You can style your text using a [BBCode](https://en.wikipedia.org/wiki/BBCode)-like syntax
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
ui.puts
|
16
|
+
ui.puts '[bold underline bright_white]Hello [ff7bfd]World!'
|
17
17
|
```
|
18
18
|
|
19
|
-
|
19
|
+
which supports all ANSI attributes, colors in 3/4-bit, 8-bit and Truecolor. There are headers, rulers, diverse message types, framed blocks and tables to layout your text. You can organize the output of tasks, use progress bars and request and handle user input. And there are text animations for fame and fun!
|
20
20
|
|
21
|
-
|
22
|
-
ui.info 'NattyUI installed'
|
23
|
-
ui.warning 'Nice gem found!'
|
24
|
-
```
|
25
|
-
|
26
|
-
and headings, framed sections, progress bars and tasks, queries, tables and much much more…
|
27
|
-
|
28
|
-
🚀 Have a look at the [features](https://rubydoc.info/gems/natty-ui/NattyUI/Features)!
|
21
|
+
🚀 Have a look at the [features](https://rubydoc.info/gems/natty-ui/NattyUI/Features) or check the code [examples](./examples/)!
|
29
22
|
|
30
23
|

|
31
24
|
|
data/examples/24bit-colors.rb
CHANGED
@@ -6,22 +6,14 @@ ui.space
|
|
6
6
|
ui.h1 'NattyUI: 24-bit Color Support'
|
7
7
|
ui.space
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#2e8b57 #66cdaa #3cb371 #20b2aa #2f4f4f #008080 #008b8b #00ffff
|
16
|
-
#00ffff #e0ffff #00ced1 #40e0d0 #48d1cc #afeeee #7fffd4 #b0e0e6
|
17
|
-
#5f9ea0 #4682b4 #6495ed #00bfff #1e90ff #add8e6 #87ceeb #87cefa
|
18
|
-
SAMPLES
|
9
|
+
ui.section do
|
10
|
+
bar = '█' * ui.available_width
|
11
|
+
rainbow =
|
12
|
+
(7..17).map do |i|
|
13
|
+
NattyUI::Ansi.rainbow(bar, seed: 3, spread: 3.25, frequence: i / 100.0)
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
ui.space
|
22
|
-
RGB_COLORS.each { ui.puts _1.map { |v| " [[on:#{v}]]#{v}[[/]] " }.join }
|
23
|
-
ui.space
|
24
|
-
RGB_COLORS.each do |code|
|
25
|
-
ui.puts code.map { |v| " [[underline ul:#{v}]]#{v}[[/]] " }.join
|
16
|
+
ui.puts(*rainbow)
|
26
17
|
end
|
18
|
+
|
27
19
|
ui.space
|
data/examples/3bit-colors.rb
CHANGED
@@ -6,7 +6,7 @@ ui.space
|
|
6
6
|
ui.h1 'NattyUI: 3/4-bit Color Support'
|
7
7
|
ui.space
|
8
8
|
|
9
|
-
color = ->(n, j) { "[
|
9
|
+
color = ->(n, j) { "[#{n}]#{n.ljust(j)}[/] [on_#{n}] sample text [/]" }
|
10
10
|
%w[black red green yellow blue magenta cyan white].each do |name|
|
11
11
|
ui.puts "#{color[name, 7]} #{color["bright_#{name}", 14]}"
|
12
12
|
end
|
data/examples/8bit-colors.rb
CHANGED
@@ -6,26 +6,30 @@ ui.space
|
|
6
6
|
ui.h1 'NattyUI: 8-bit Color Support'
|
7
7
|
ui.space
|
8
8
|
|
9
|
-
color = ->(i) { "[
|
10
|
-
ui.msg 'System Colors', glyph:
|
11
|
-
ui.puts
|
12
|
-
|
13
|
-
|
9
|
+
color = ->(i) { "[bg#{i = i.to_s(16).rjust(2, '0')}] #{i} " }
|
10
|
+
ui.msg 'System Colors', glyph: :point do
|
11
|
+
ui.puts <<~COLORS
|
12
|
+
[#ff]#{0.upto(7).map(&color).join}
|
13
|
+
[#00]#{8.upto(15).map(&color).join}
|
14
|
+
|
15
|
+
COLORS
|
14
16
|
end
|
15
17
|
|
16
|
-
ui.msg '6x6x6 Color Cube', glyph:
|
18
|
+
ui.msg '6x6x6 Color Cube', glyph: :point do
|
17
19
|
[16, 22, 28].each do |b|
|
18
20
|
b.step(b + 185, by: 36) do |i|
|
19
21
|
left = i.upto(i + 5).map(&color).join
|
20
22
|
right = (i + 18).upto(i + 23).map(&color).join
|
21
|
-
ui.puts "[
|
23
|
+
ui.puts "[#ff]#{left}[bg_default] #{right}"
|
22
24
|
end
|
23
25
|
ui.space
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
ui.msg 'Grayscale', glyph:
|
28
|
-
ui.puts
|
29
|
-
|
30
|
-
|
29
|
+
ui.msg 'Grayscale', glyph: :point do
|
30
|
+
ui.puts <<~GRAYSCALE
|
31
|
+
[#ff]#{232.upto(243).map(&color).join}
|
32
|
+
[#ff]#{244.upto(255).map(&color).join}
|
33
|
+
|
34
|
+
GRAYSCALE
|
31
35
|
end
|
data/examples/animate.rb
CHANGED
@@ -7,18 +7,38 @@ ui.h1 'NattyUI: Text Line Animation'
|
|
7
7
|
ui.space
|
8
8
|
|
9
9
|
TEXT = <<~TEXT.tr("\n", ' ')
|
10
|
-
Lorem [
|
11
|
-
do eiusmod tempor incididunt ut labore et dolore [
|
10
|
+
Lorem [yellow]ipsum[/] dolor sit amet, consectetur adipisicing elit, sed
|
11
|
+
do eiusmod tempor incididunt ut labore et dolore [red]magna[/] aliqua.
|
12
12
|
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
13
|
-
aliquip ex ea commodo [
|
13
|
+
aliquip ex ea commodo [bold]consequat[/].
|
14
14
|
TEXT
|
15
15
|
|
16
|
-
|
17
|
-
|
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
|
16
|
+
ui.message 'Default Animation', glyph: :point do
|
17
|
+
ui.animate TEXT, animation: :default
|
24
18
|
end
|
19
|
+
ui.space
|
20
|
+
|
21
|
+
ui.message 'Shiny Rainbow', glyph: :point do
|
22
|
+
ui.animate TEXT, animation: :rainbow
|
23
|
+
end
|
24
|
+
ui.space
|
25
|
+
|
26
|
+
ui.message 'Binary Encoded', glyph: :point do
|
27
|
+
ui.animate TEXT, animation: :binary, style: 'green', alt_style: :bright_green
|
28
|
+
end
|
29
|
+
ui.space
|
30
|
+
|
31
|
+
ui.message 'Matrix Style', glyph: :point do
|
32
|
+
ui.animate TEXT, animation: :matrix
|
33
|
+
end
|
34
|
+
ui.space
|
35
|
+
|
36
|
+
ui.message 'Typewriter Like', glyph: :point do
|
37
|
+
ui.animate TEXT, animation: :type_writer
|
38
|
+
end
|
39
|
+
ui.space
|
40
|
+
|
41
|
+
ui.message 'Default Styled', glyph: :point do
|
42
|
+
ui.animate TEXT, style: 'bold bright_white on_red'
|
43
|
+
end
|
44
|
+
ui.space
|
data/examples/attributes.rb
CHANGED
@@ -6,22 +6,24 @@ ui.space
|
|
6
6
|
ui.h2 'NattyUI: ANSI Attributes'
|
7
7
|
ui.space
|
8
8
|
|
9
|
-
ui.puts <<~PARA1.tr("\n", ' ')
|
10
|
-
Some attributes are widely supported, such as [
|
11
|
-
[
|
12
|
-
[
|
13
|
-
complete or correctly implemented,
|
14
|
-
[
|
15
|
-
underline[
|
16
|
-
[
|
17
|
-
[
|
18
|
-
[
|
9
|
+
ui.puts <<~PARA1.tr("\n", ' ')
|
10
|
+
Some attributes are widely supported, such as [b]bold[/b],
|
11
|
+
[i]italic[/i], [u]underline[/u], [blink]blink[/blink],
|
12
|
+
[invert]invert[/invert] and [strike]strike[/strike], while others are rarely
|
13
|
+
complete or correctly implemented, like [faint]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
19
|
PARA1
|
20
|
+
|
21
|
+
ui.puts <<~PARA2.tr("\n", ' ')
|
20
22
|
Alternative fonts are mostly completely ignored:
|
21
|
-
[
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
23
|
+
[primary_font]primary_font[/], [fraktur]fraktur[/],
|
24
|
+
[font1]font1[/], [font2]font2[/], [font3]font3[/],
|
25
|
+
[font4]font4[/], [font5]font5[/], [font6]font6[/],
|
26
|
+
[font7]font7[/], [font8]font8[/], [font9]font9[/].
|
25
27
|
PARA2
|
26
28
|
|
27
29
|
ui.space
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/natty-ui'
|
4
|
+
|
5
|
+
ui.space
|
6
|
+
ui.h2 'NattyUI: All Attribute and Defined Color Names'
|
7
|
+
ui.space
|
8
|
+
|
9
|
+
ui.ls(
|
10
|
+
(NattyUI::Ansi.attribute_names + NattyUI::Ansi.color_names)
|
11
|
+
.sort!
|
12
|
+
.map! { |name| "[#{name}]#{name}[/]" }
|
13
|
+
)
|
14
|
+
ui.space
|
data/examples/demo.rb
CHANGED
@@ -24,10 +24,10 @@ ui.page do
|
|
24
24
|
examples = {}
|
25
25
|
{
|
26
26
|
'1' => ['attributes', 'ANSI Attributes'],
|
27
|
-
'2' => ['
|
28
|
-
'3' => ['
|
29
|
-
'4' => ['
|
30
|
-
'5' => ['
|
27
|
+
'2' => ['3bit-colors', '3/4-bit Color Support'],
|
28
|
+
'3' => ['8bit-colors', '8-bit Color Support'],
|
29
|
+
'4' => ['24bit-colors', '24-bit Color Support'],
|
30
|
+
'5' => ['message', 'Message Types'],
|
31
31
|
'6' => ['ls', 'Print In Columns'],
|
32
32
|
'7' => %w[table Tables],
|
33
33
|
'8' => ['animate', 'Text Line Animation'],
|
data/examples/illustration.rb
CHANGED
@@ -2,30 +2,58 @@
|
|
2
2
|
|
3
3
|
require_relative '../lib/natty-ui'
|
4
4
|
|
5
|
-
ui.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
ui.space
|
6
|
+
|
7
|
+
ui.table(type: :undecorated) do |table|
|
8
|
+
table.add(
|
9
|
+
'Styles',
|
10
|
+
"Support of all ANSI styles like #{
|
11
|
+
%w[
|
12
|
+
bold
|
13
|
+
italic
|
14
|
+
underline
|
15
|
+
invert
|
16
|
+
strike
|
17
|
+
faint
|
18
|
+
double_underline
|
19
|
+
curly_underline
|
20
|
+
dotted_underline
|
21
|
+
dashed_underline
|
22
|
+
blink
|
23
|
+
].map { "[#{_1}]#{_1.tr('_', ' ')}[/]" }.join(', ')
|
24
|
+
}, and even rarely supported like [fraktur]fraktur[/fraktur]."
|
25
|
+
)
|
26
|
+
|
27
|
+
table.add('Colors', <<~TEXT)
|
28
|
+
✓ [green]3/4-bit color[/] ✓ [ff7f50]Truecolor (16.7 million)
|
29
|
+
✓ [1b]8-bit color[/] ✓ [bright_yellow]Dumb terminals
|
30
|
+
✓ [bright_blue]NO_COLOR convention
|
31
|
+
TEXT
|
32
|
+
|
33
|
+
table.add(
|
34
|
+
'Markup',
|
35
|
+
'[0c]You can style your text using a [i]BBCode[/i]-like syntax.'
|
36
|
+
)
|
37
|
+
|
38
|
+
table.add('Layout', <<~TEXT)
|
39
|
+
🎩 heading elements 📏 horizontal rulers
|
40
|
+
📝 messages [yellow]🄵[/] framed blocks
|
41
|
+
[blue]┼┼[/] tables
|
15
42
|
TEXT
|
16
43
|
|
17
|
-
|
18
|
-
[
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
[
|
25
|
-
[
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
FEATURES
|
44
|
+
table.add('Tools', <<~TEXT)
|
45
|
+
✅ tasks [bold green]…[/] progress bars
|
46
|
+
[bold bright_white]>[bright_red]_[/] user input 🔦 text animation
|
47
|
+
TEXT
|
48
|
+
|
49
|
+
table.add("Asian\nlanguage\nsupport", <<~TEXT)
|
50
|
+
[0a]🇨🇳 该库支持中文,日文和韩文文本!
|
51
|
+
[0a]🇯🇵 ライブラリは中国語、日本語、韓国語のテキストをサポートしています
|
52
|
+
[0a]🇰🇷 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다
|
53
|
+
TEXT
|
54
|
+
|
55
|
+
table.align_column(0, :center)
|
56
|
+
table.style_column(0, :red)
|
31
57
|
end
|
58
|
+
|
59
|
+
ui.space
|
data/examples/ls.rb
CHANGED
@@ -11,14 +11,14 @@ LOREM = <<~IPSUM.lines(chomp: true)
|
|
11
11
|
amet, consectetur adipisicing
|
12
12
|
elit, sed do eiusmod tempor
|
13
13
|
incididunt ut labore et
|
14
|
-
dolore [
|
14
|
+
dolore [red]magna[/] aliqua. Ut
|
15
15
|
enim ad minim veniam, quis
|
16
16
|
nostrud exercitation ullamco
|
17
17
|
laboris nisi ut aliquip ex
|
18
|
-
ea commodo [
|
19
|
-
aute irure [
|
18
|
+
ea commodo [b]consequat[/b]. Duis
|
19
|
+
aute irure [bold green]dolor[/fg] in[/]
|
20
20
|
reprehenderit in voluptate
|
21
|
-
velit [
|
21
|
+
velit [underline]esse cillum[/] dolore eu
|
22
22
|
fugiat nulla pariatur.
|
23
23
|
Excepteur sint occaecat
|
24
24
|
cupidatat non proident,
|
data/examples/message.rb
CHANGED
@@ -7,24 +7,26 @@ ui.h1 'NattyUI: Message Types'
|
|
7
7
|
ui.space
|
8
8
|
|
9
9
|
TEXT = <<~TEXT.tr("\n", ' ')
|
10
|
-
Lorem [
|
11
|
-
do eiusmod tempor incididunt ut labore et dolore [
|
10
|
+
Lorem [yellow]ipsum[/fg] dolor sit amet, consectetur adipisicing elit, sed
|
11
|
+
do eiusmod tempor incididunt ut labore et dolore [red]magna[/fg] aliqua.
|
12
12
|
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
13
|
-
aliquip ex ea commodo [
|
13
|
+
aliquip ex ea commodo [b]consequat[/b].
|
14
14
|
TEXT
|
15
15
|
|
16
|
-
IMPORTANT =
|
17
|
-
'[[red]]>>>[[/]] [[italic]]Here some important information[[/]] [[red]]<<<'
|
18
|
-
|
19
16
|
ui.framed do
|
20
17
|
ui.info 'Informative Message', TEXT
|
21
18
|
ui.warning 'Warning Message' do
|
22
|
-
ui.
|
23
|
-
|
19
|
+
ui.framed(type: :double) do
|
20
|
+
ui.puts(
|
21
|
+
'[red]>>>[/fg] [i]Important information maybe here[/i] [red]<<<',
|
22
|
+
align: :center
|
23
|
+
)
|
24
|
+
end
|
25
|
+
ui.puts('[italic f4]Ut enim ad minim veniam', align: :right)
|
24
26
|
end
|
25
27
|
ui.error 'Error Message', TEXT
|
26
28
|
ui.failed 'Fail Message', TEXT
|
27
|
-
ui.message '[
|
29
|
+
ui.message '[italic #fad]Custom Message', TEXT, glyph: '💡'
|
28
30
|
end
|
29
31
|
|
30
32
|
ui.space
|
data/examples/progress.rb
CHANGED
@@ -25,7 +25,7 @@ ui.info 'Tasks are sections to visualize step by step processing.' do
|
|
25
25
|
|
26
26
|
ui.task 'Compile files...' do
|
27
27
|
%w[readme.txt main.css main.html sub.html].each do |name|
|
28
|
-
ui.msg "Compile file [
|
28
|
+
ui.msg "Compile file [bright_yellow]./source/#{name}[/]..."
|
29
29
|
something
|
30
30
|
end
|
31
31
|
ui.done 'Files compiled.'
|
@@ -44,7 +44,7 @@ ui.info 'Tasks are sections to visualize step by step processing.' do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
ui.puts(
|
47
|
-
'The details are removed ([
|
47
|
+
'The details are removed ([i]in ANSI version[/i]) when the task',
|
48
48
|
'ended sucessfully.'
|
49
49
|
)
|
50
50
|
end
|
data/examples/query.rb
CHANGED
data/examples/table.rb
CHANGED
@@ -6,36 +6,36 @@ ui.space
|
|
6
6
|
ui.h1 'NattyUI: Tables'
|
7
7
|
ui.space
|
8
8
|
|
9
|
-
|
9
|
+
User = Struct.new(:id, :name, :mail, :notes)
|
10
|
+
users = [
|
11
|
+
User.new(
|
12
|
+
1,
|
13
|
+
'Henry',
|
14
|
+
'henry@some.test',
|
15
|
+
'This is fill text to generate a wide column ' \
|
16
|
+
'which maybe rendered as multi line.'
|
17
|
+
),
|
18
|
+
User.new(2, 'Sam', 'sam-sam@some.test', "enforced\nmulti-line"),
|
19
|
+
User.new(3, 'Taylor', 'taylor@some.test')
|
20
|
+
]
|
21
|
+
|
22
|
+
ui.message 'Simple Table' do
|
10
23
|
ui.space
|
11
|
-
|
12
|
-
ui.table type: :heavy do |table|
|
13
|
-
table.add 'X', 'O'
|
14
|
-
table.add 'O', 'O', 'X'
|
15
|
-
table.add nil, 'X'
|
16
|
-
end
|
24
|
+
ui.table User.members.map(&:capitalize), *users
|
17
25
|
end
|
18
26
|
|
19
27
|
ui.space
|
20
28
|
|
21
|
-
|
29
|
+
ui.message 'Styled Table' do
|
30
|
+
users[0].notes = 'Short notice'
|
22
31
|
|
23
|
-
ui.message 'Data Table' do
|
24
32
|
ui.space
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
'This is fill text to generate a wide column which maybe rendered as multi line.'
|
32
|
-
),
|
33
|
-
User.new(2, 'Sam', 'sam-sam@some.test', "enforced\nmulti-line"),
|
34
|
-
User.new(3, 'Taylor', 'taylor@some.test'),
|
35
|
-
User.new(4, 'Max', 'maxxx@some.test')
|
36
|
-
]
|
37
|
-
header = User.members.map { "[[bold green]]#{_1.capitalize}[[/]]" }
|
38
|
-
ui.table(header, *users)
|
33
|
+
ui.table(expand: true) do |table|
|
34
|
+
table.add(User.members.map(&:capitalize), style: 'bold green')
|
35
|
+
users.each { |user| table.add(user) }
|
36
|
+
table.style_column(0, 'bold green')
|
37
|
+
table.align_column(0, :center)
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
ui.space
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NattyUI
|
4
|
+
module Animation
|
5
|
+
class Binary < Base
|
6
|
+
protected
|
7
|
+
|
8
|
+
def write(stream)
|
9
|
+
@style = attribute(:style, :default)
|
10
|
+
@alt_style = attribute(:alt_style, :bright_white)
|
11
|
+
binary = @lines.map { |_, size| Array.new(size) { rand_char } }
|
12
|
+
35.times do |i|
|
13
|
+
binary.each do |chars|
|
14
|
+
rc = rand_char
|
15
|
+
rc = @style + rc if rc.size == 1
|
16
|
+
chars.pop
|
17
|
+
chars.unshift(rc)
|
18
|
+
puts(stream, chars.join)
|
19
|
+
end
|
20
|
+
(stream << @top).flush
|
21
|
+
sleep(i / 300.0)
|
22
|
+
end
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def rand_char
|
27
|
+
return "#{@alt_style}#{CHARS.sample}#{@style}" if rand < 0.2
|
28
|
+
CHARS.sample
|
29
|
+
end
|
30
|
+
|
31
|
+
CHARS = %w[0 1].freeze
|
32
|
+
end
|
33
|
+
|
34
|
+
define binary: Binary
|
35
|
+
private_constant :Binary
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NattyUI
|
4
|
+
module Animation
|
5
|
+
class Default < Base
|
6
|
+
protected
|
7
|
+
|
8
|
+
def write(stream)
|
9
|
+
num = 0
|
10
|
+
style = attribute(:style, :default)
|
11
|
+
@lines.each do |line, size|
|
12
|
+
time = 0.25 / size
|
13
|
+
stream << style
|
14
|
+
if (num += 1).odd?
|
15
|
+
stream << @pos1
|
16
|
+
Text
|
17
|
+
.plain(line)
|
18
|
+
.each_char do |char|
|
19
|
+
(stream << char).flush
|
20
|
+
sleep(time)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
stream << Ansi.cursor_column(@prefix_width + size - 1)
|
24
|
+
Text
|
25
|
+
.plain(line)
|
26
|
+
.reverse
|
27
|
+
.each_char do |char|
|
28
|
+
(stream << char << CURSOR_LEFT).flush
|
29
|
+
sleep(time)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
stream << Ansi::RESET << @pos1 << line << Ansi::LINE_NEXT
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
CURSOR_LEFT = Ansi.cursor_back(2).freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
define default: Default
|
40
|
+
private_constant :Default
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NattyUI
|
4
|
+
module Animation
|
5
|
+
class Matrix < Base
|
6
|
+
protected
|
7
|
+
|
8
|
+
def write(stream)
|
9
|
+
plains = @lines.map { |line, _| Text.plain(line) }
|
10
|
+
encs = @lines.map { Array.new(_2) { CHARS.sample }.join }
|
11
|
+
poss = @lines.map { Array.new(_2, &:itself).shuffle }
|
12
|
+
stream << attribute(:style, :default)
|
13
|
+
until poss.all?(&:empty?)
|
14
|
+
poss.each_with_index do |pos, idx|
|
15
|
+
next stream << Ansi::LINE_NEXT if pos.empty?
|
16
|
+
line = plains[idx]
|
17
|
+
if (count = (pos.size / 11.0).round) < 2
|
18
|
+
encs[idx] = enc = line
|
19
|
+
pos.clear
|
20
|
+
else
|
21
|
+
enc = encs[idx]
|
22
|
+
pos.pop(count).each { enc[_1] = line[_1] }
|
23
|
+
pos.sample(pos.size / 3).each { enc[_1] = CHARS.sample }
|
24
|
+
end
|
25
|
+
|
26
|
+
# next stream << Ansi::LINE_NEXT if pos.size < 4
|
27
|
+
# pos.shift(pos.size / 8).each { enc[_1] = line[_1] }
|
28
|
+
# pos.sample(pos.size / 2).each { enc[_1] = CHARS.sample }
|
29
|
+
puts(stream, enc)
|
30
|
+
end
|
31
|
+
(stream << @top).flush
|
32
|
+
sleep(0.1)
|
33
|
+
end
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def print2(line)
|
38
|
+
line = Text.plain(line)
|
39
|
+
str = Array.new(line.size) { CHARS.sample }.join
|
40
|
+
pos = Array.new(line.size, &:itself).shuffle
|
41
|
+
until pos.size < 4
|
42
|
+
pos.shift(pos.size / 4).each { str[_1] = line[_1] }
|
43
|
+
pos.sample(pos.size / 2).each { str[_1] = CHARS.sample }
|
44
|
+
(@stream << "#{@prefix}#{str}").flush
|
45
|
+
sleep(0.08)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
CHARS = '2598Z*):.\=+-¦|_ヲアウエオカキケコサシスセソタツテナニヌネハヒホマミムメモヤユラリワ'.chars.freeze
|
50
|
+
end
|
51
|
+
|
52
|
+
define matrix: Matrix
|
53
|
+
private_constant :Matrix
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NattyUI
|
4
|
+
module Animation
|
5
|
+
class Rainbow < Base
|
6
|
+
protected
|
7
|
+
|
8
|
+
def write(stream)
|
9
|
+
plain = @lines.map { |line, _| Text.plain(line) }
|
10
|
+
11.upto(180) do |spread|
|
11
|
+
spread /= 100.0
|
12
|
+
plain.each do |line|
|
13
|
+
puts(
|
14
|
+
stream,
|
15
|
+
Ansi.rainbow(line, spread: spread, frequence: 0.1, seed: 0)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
(stream << Ansi::RESET << @top).flush
|
19
|
+
sleep(0.01)
|
20
|
+
end
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
define rainbow: Rainbow
|
26
|
+
private_constant :Rainbow
|
27
|
+
end
|
28
|
+
end
|