natty-ui 0.7.0 → 0.9.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +7 -3
  3. data/README.md +25 -47
  4. data/examples/24bit-colors.rb +27 -0
  5. data/examples/3bit-colors.rb +14 -0
  6. data/examples/8bit-colors.rb +31 -0
  7. data/examples/animate.rb +24 -0
  8. data/examples/attributes.rb +25 -159
  9. data/examples/demo.rb +53 -0
  10. data/examples/illustration.png +0 -0
  11. data/examples/illustration.rb +29 -0
  12. data/examples/{list_in_columns.rb → ls.rb} +13 -20
  13. data/examples/message.rb +30 -0
  14. data/examples/progress.rb +25 -30
  15. data/examples/query.rb +26 -28
  16. data/examples/read_key.rb +13 -0
  17. data/examples/table.rb +36 -0
  18. data/lib/natty-ui/ansi.rb +351 -305
  19. data/lib/natty-ui/ansi_constants.rb +73 -0
  20. data/lib/natty-ui/ansi_wrapper.rb +136 -162
  21. data/lib/natty-ui/features.rb +11 -18
  22. data/lib/natty-ui/key_map.rb +119 -0
  23. data/lib/natty-ui/line_animation/default.rb +35 -0
  24. data/lib/natty-ui/line_animation/matrix.rb +28 -0
  25. data/lib/natty-ui/line_animation/rainbow.rb +30 -0
  26. data/lib/natty-ui/line_animation/test.rb +29 -0
  27. data/lib/natty-ui/line_animation/type_writer.rb +64 -0
  28. data/lib/natty-ui/line_animation.rb +54 -0
  29. data/lib/natty-ui/version.rb +2 -2
  30. data/lib/natty-ui/wrapper/animate.rb +17 -0
  31. data/lib/natty-ui/wrapper/ask.rb +21 -21
  32. data/lib/natty-ui/wrapper/element.rb +19 -23
  33. data/lib/natty-ui/wrapper/framed.rb +29 -19
  34. data/lib/natty-ui/wrapper/heading.rb +26 -53
  35. data/lib/natty-ui/wrapper/horizontal_rule.rb +37 -0
  36. data/lib/natty-ui/wrapper/list_in_columns.rb +71 -12
  37. data/lib/natty-ui/wrapper/message.rb +20 -27
  38. data/lib/natty-ui/wrapper/progress.rb +40 -13
  39. data/lib/natty-ui/wrapper/query.rb +34 -31
  40. data/lib/natty-ui/wrapper/quote.rb +25 -0
  41. data/lib/natty-ui/wrapper/request.rb +21 -10
  42. data/lib/natty-ui/wrapper/section.rb +55 -39
  43. data/lib/natty-ui/wrapper/table.rb +298 -0
  44. data/lib/natty-ui/wrapper/task.rb +6 -7
  45. data/lib/natty-ui/wrapper.rb +123 -41
  46. data/lib/natty-ui.rb +65 -40
  47. metadata +28 -9
  48. data/examples/basic.rb +0 -62
data/examples/progress.rb CHANGED
@@ -1,68 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
- UI = NattyUI::StdOut
6
-
7
- UI.space
8
- UI.h1 'NattyUI Progress Indication Demo'
9
- UI.space
5
+ ui.space
6
+ ui.h1 'NattyUI: Progress Indication'
7
+ ui.space
10
8
 
11
9
  # just simulate some work
12
10
  def something = sleep(0.5)
13
11
  def some = sleep(0.15)
14
12
 
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 }
13
+ ui.info 'Tasks are sections to visualize step by step processing.' do
14
+ ui.task 'Assemble assets' do
15
+ ui.task('Initialize') { something }
18
16
 
19
- progress = task.progress 'Connect to server...'
17
+ progress = ui.progress 'Connect to server...'
20
18
  20.times do
21
19
  progress.step
22
20
  some
23
21
  end
24
22
  progress.ok 'Connected'
25
23
 
26
- task.task('Collect files...') { something }
24
+ ui.task('Collect files...') { something }
27
25
 
28
- task.task 'Compile files...' do |subtask|
26
+ ui.task 'Compile files...' do
29
27
  %w[readme.txt main.css main.html sub.html].each do |name|
30
- subtask.msg "Compile file [[bright_yellow]]./source/#{name}[[/]]..."
28
+ ui.msg "Compile file [[bright_yellow]]./source/#{name}[[/]]..."
31
29
  something
32
30
  end
33
- subtask.done 'Files compiled.'
31
+ ui.done 'Files compiled.'
34
32
  end
35
33
 
36
- progress = task.progress('Compress files', max_value: 11)
34
+ progress = ui.progress('Compress files', max_value: 11)
37
35
  11.times do
38
36
  progress.step
39
37
  something
40
38
  end
41
39
  progress.done 'All compressed'
42
40
 
43
- task.task('Signing') { something }
41
+ ui.task('Signing') { something }
44
42
 
45
- task.task('Store assembled results') { something }
43
+ ui.task('Store assembled results') { something }
46
44
  end
47
- info.puts(
45
+
46
+ ui.puts(
48
47
  'The details are removed ([[italic]]in ANSI version[[/]]) when the task',
49
48
  'ended sucessfully.'
50
49
  )
51
50
  end
52
51
 
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 }
56
-
57
- progress = task.progress 'Connect to server...'
58
- 20.times do
59
- progress.step
60
- some
52
+ ui.info 'Details of failed tasks will not be cleaned.' do
53
+ ui.task 'Assemble assets' do
54
+ ui.task('Initialize') { something }
55
+ ui.task('Connect to Server') do
56
+ something
57
+ ui.failed 'Unable to connect to server'
61
58
  end
62
- progress.failed 'Unable to connect to server'
63
-
64
- task.error 'This code will not be reachd!'
59
+ ui.error 'This code will not be reachd!'
65
60
  end
66
61
  end
67
62
 
68
- UI.space
63
+ ui.space
data/examples/query.rb CHANGED
@@ -1,43 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'natty-ui'
3
+ require_relative '../lib/natty-ui'
4
4
 
5
- UI = NattyUI::StdOut
5
+ ui.space
6
+ ui.h1 'NattyUI: User Queries'
7
+ ui.space
6
8
 
7
- UI.space
8
- UI.h1 'NattyUI Query Demo'
9
- UI.space
9
+ # little helper
10
+ def abort!
11
+ ui.failed 'aborted'
12
+ ui.space
13
+ exit
14
+ end
10
15
 
11
- unless UI.ask('Do you like to continute? (Y|n)')
12
- UI.failed 'aborted'
16
+ unless ui.ask('Do you like to continute? (Y|n): ')
17
+ ui.info 'ok, try later!'
18
+ ui.space
13
19
  exit
14
20
  end
15
21
 
16
22
  choice =
17
- UI.query(
23
+ ui.query(
18
24
  'Which fruits do you prefer?',
19
25
  'Apples',
20
- 'Bananas',
26
+ '[[yellow]]Bananas[[/]]',
21
27
  'Cherries',
22
- x: 'No fruits',
23
- result: :choice
28
+ x: 'No fruits'
24
29
  )
25
- unless choice
26
- UI.failed 'aborted'
27
- exit false
28
- end
29
- UI.info "Your choice: #{choice}"
30
+ abort! unless choice
31
+ ui.info "Your choice: #{choice}"
30
32
 
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}"
33
+ answer = ui.request 'What is your favorite verb?: '
34
+ abort! unless answer
35
+ ui.info "Your answer: #{answer.inspect}"
37
36
 
38
- answer = UI.request('What is your current password?', password: true)
39
- unless answer
40
- UI.failed 'aborted'
41
- exit false
42
- end
43
- UI.info "I'll keep your secret!"
37
+ answer = ui.request('What is your current password?:', password: true)
38
+ abort! unless answer
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
data/examples/table.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.space
6
+ ui.h1 'NattyUI: Tables'
7
+ ui.space
8
+
9
+ ui.message 'Constructed Table' do
10
+ ui.table type: :heavy do |table|
11
+ table.add 'X', 'O'
12
+ table.add 'O', 'O', 'X'
13
+ table.add nil, 'X'
14
+ end
15
+ end
16
+
17
+ ui.space
18
+
19
+ User = Struct.new(:id, :name, :mail, :notes)
20
+ USERS = [
21
+ User.new(
22
+ 1,
23
+ 'Henry',
24
+ 'henry@some.test',
25
+ 'This is fill text to generate a wide column which maybe rendered as multi line.'
26
+ ),
27
+ User.new(2, 'Sam', 'sam-sam@some.test', "enforced\nmulti-line"),
28
+ User.new(3, 'Taylor', 'taylor@some.test'),
29
+ User.new(3, 'Max', 'maxxx@some.test')
30
+ ].freeze
31
+
32
+ ui.message 'Data Table' do
33
+ ui.table(User.members, *USERS)
34
+ end
35
+
36
+ ui.space