natty-ui 0.10.0 → 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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -11
  3. data/examples/24bit-colors.rb +8 -16
  4. data/examples/3bit-colors.rb +1 -1
  5. data/examples/8bit-colors.rb +15 -11
  6. data/examples/animate.rb +31 -11
  7. data/examples/attributes.rb +16 -14
  8. data/examples/attributes_list.rb +14 -0
  9. data/examples/demo.rb +4 -4
  10. data/examples/illustration.rb +52 -24
  11. data/examples/ls.rb +4 -4
  12. data/examples/message.rb +11 -9
  13. data/examples/progress.rb +2 -2
  14. data/examples/query.rb +1 -1
  15. data/examples/table.rb +23 -23
  16. data/lib/natty-ui/animation/binary.rb +37 -0
  17. data/lib/natty-ui/animation/default.rb +42 -0
  18. data/lib/natty-ui/animation/matrix.rb +55 -0
  19. data/lib/natty-ui/animation/rainbow.rb +28 -0
  20. data/lib/natty-ui/animation/type_writer.rb +44 -0
  21. data/lib/natty-ui/animation.rb +69 -0
  22. data/lib/natty-ui/ansi/constants.rb +1 -1
  23. data/lib/natty-ui/ansi.rb +46 -26
  24. data/lib/natty-ui/ansi_wrapper.rb +44 -51
  25. data/lib/natty-ui/key_map.rb +72 -49
  26. data/lib/natty-ui/preload.rb +1 -1
  27. data/lib/natty-ui/text.rb +76 -103
  28. data/lib/natty-ui/version.rb +1 -1
  29. data/lib/natty-ui/wrapper/animate.rb +1 -1
  30. data/lib/natty-ui/wrapper/element.rb +18 -10
  31. data/lib/natty-ui/wrapper/features.rb +0 -8
  32. data/lib/natty-ui/wrapper/framed.rb +4 -4
  33. data/lib/natty-ui/wrapper/section.rb +18 -18
  34. data/lib/natty-ui/wrapper/table.rb +432 -171
  35. data/lib/natty-ui/wrapper.rb +37 -20
  36. data/lib/natty-ui.rb +14 -10
  37. metadata +10 -8
  38. data/lib/natty-ui/line_animation/default.rb +0 -36
  39. data/lib/natty-ui/line_animation/matrix.rb +0 -29
  40. data/lib/natty-ui/line_animation/rainbow.rb +0 -31
  41. data/lib/natty-ui/line_animation/type_writer.rb +0 -45
  42. data/lib/natty-ui/line_animation.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e92abc0c7952b3470af1cee08261712ecf8468b05944dd3967c46ee95c040806
4
- data.tar.gz: a1b277e69f56f58c5dc1668565cc4cf763f17c5242d42d1f79b4590c432cb8da
3
+ metadata.gz: bbaeb874eda95058545f313e3b0c2ea93235681c917b35419d3d6c1d00da96b0
4
+ data.tar.gz: 8af26d5eddcfd85a61053ccde48eef9c8fd5a12a67ebd22d2a904adba29deba1
5
5
  SHA512:
6
- metadata.gz: 47aa3f7076379258e10a78592ca2375146c15850f234f2f69085ef41e88a168855bcd8e19fa1d21c09aad0917e872d3fd2d1941b2dc10bb0e74aa17e47ee1608
7
- data.tar.gz: 79e91c8b88e746064393df5b1d46f355184983ce9ff821f786a9452c99f5b5c40d2980226ff055e6fe8a51e18d18617a78a35535d514cf8d7cd1234dca098ce1
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 simply decorate your text with named ANSI attributes and colors
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 '[[bold underline]]Hello [[ff7bfd]]World[[/]]!'
16
+ ui.puts '[bold underline bright_white]Hello [ff7bfd]World!'
17
17
  ```
18
18
 
19
- or use different types of messages
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
- ```ruby
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
  ![illustration](https://raw.githubusercontent.com/mblumtritt/natty-ui/main/examples/illustration.png)
31
24
 
@@ -6,22 +6,14 @@ ui.space
6
6
  ui.h1 'NattyUI: 24-bit Color Support'
7
7
  ui.space
8
8
 
9
- RGB_COLORS = <<~SAMPLES.lines(chomp: true).map!(&:split)
10
- #800000 #8b0000 #a52a2a #b22222 #dc143c #ff0000 #ff6347 #ff7f50
11
- #cd5c5c #f08080 #e9967a #fa8072 #ffa07a #ff4500 #ff8c00 #ffa500
12
- #ffd700 #b8860b #daa520 #eee8aa #bdb76b #f0e68c #808000 #ffff00
13
- #9acd32 #556b2f #6b8e23 #7cfc00 #7fff00 #adff2f #006400 #008000
14
- #228b22 #00ff00 #32cd32 #90ee90 #98fb98 #8fbc8f #00fa9a #00ff7f
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
- 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
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
@@ -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) { "[[#{n}]]#{n.ljust(j)}[[/]] [[on_#{n}]] sample text [[/]]" }
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
@@ -6,26 +6,30 @@ ui.space
6
6
  ui.h1 'NattyUI: 8-bit Color Support'
7
7
  ui.space
8
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
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: '[[27]]◉' do
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 "[[#ff]]#{left}[[bg_default]] #{right}"
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: '[[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
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 [[yellow]]ipsum[[/]] dolor sit amet, consectetur adipisicing elit, sed
11
- do eiusmod tempor incididunt ut labore et dolore [[red]]magna[[/]] aliqua.
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 [[bold]]consequat[[/]].
13
+ aliquip ex ea commodo [bold]consequat[/].
14
14
  TEXT
15
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
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
@@ -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", ' '), <<~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[[/]].
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
- [[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[[/]].
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' => ['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'],
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'],
@@ -2,30 +2,58 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
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
- [[italic curly_underline ulc4]]elegant[[/]],
12
- [[italic underline ulc7]]simple[[/]] and
13
- [[italic dotted_underline ulca]]beautiful[[/]] tools that enhance your
14
- command line interfaces functionally and aesthetically.
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
- ui.msg('Features', glyph: '⭐️') { ui.ls(<<~FEATURES.lines(chomp: true)) }
18
- [[bold red]]T[[/]] text attributes
19
- 🌈 text coloring
20
- 🔦 text animation
21
- 🎩 heading elements
22
- 📏 horizontal rulers
23
- 📝 messages
24
- [[bold blue]]""[[/]] quote blocks
25
- [[yellow]]🄵[[/]] framed blocks
26
- ✅ tasks
27
- [[bold green]]…[[/]] progress bars
28
- [[blue]]┼┼[[/]] tables
29
- [[bold bright_white]]>[[bright_red]]_[[/]] user input
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 [[red]]magna[[/]] aliqua. Ut
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 [[bold]]consequat[[/]]. Duis
19
- aute irure [[bold green]]dolor[[/]] in
18
+ ea commodo [b]consequat[/b]. Duis
19
+ aute irure [bold green]dolor[/fg] in[/]
20
20
  reprehenderit in voluptate
21
- velit [[underline]]esse cillum[[/]] dolore eu
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 [[yellow]]ipsum[[/]] dolor sit amet, consectetur adipisicing elit, sed
11
- do eiusmod tempor incididunt ut labore et dolore [[red]]magna[[/]] aliqua.
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 [[bold]]consequat[[/]].
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.puts TEXT
23
- ui.framed { ui.puts IMPORTANT }
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 '[[italic #fad]]Custom Message', TEXT, glyph: '💡'
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 [[bright_yellow]]./source/#{name}[[/]]..."
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 ([[italic]]in ANSI version[[/]]) when the task',
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
@@ -23,7 +23,7 @@ choice =
23
23
  ui.query(
24
24
  'Which fruits do you prefer?',
25
25
  'Apples',
26
- '[[yellow]]Bananas[[/]]',
26
+ '[yellow]Bananas[/]',
27
27
  'Cherries',
28
28
  x: 'No fruits'
29
29
  )
data/examples/table.rb CHANGED
@@ -6,36 +6,36 @@ ui.space
6
6
  ui.h1 'NattyUI: Tables'
7
7
  ui.space
8
8
 
9
- ui.message 'Constructed Table' do
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
- User = Struct.new(:id, :name, :mail, :notes)
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
- users = [
27
- User.new(
28
- 1,
29
- 'Henry',
30
- 'henry@some.test',
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