natty-ui 0.35.0 → 1.0.2

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -6
  3. data/examples/24bit-colors.rb +9 -5
  4. data/examples/3bit-colors.rb +7 -7
  5. data/examples/8bit-colors.rb +5 -7
  6. data/examples/attributes.rb +2 -3
  7. data/examples/elements.rb +9 -6
  8. data/examples/examples.rb +9 -9
  9. data/examples/frames.rb +31 -0
  10. data/examples/hbars.rb +6 -3
  11. data/examples/info.rb +13 -10
  12. data/examples/key-codes.rb +8 -9
  13. data/examples/ls.rb +24 -22
  14. data/examples/named-colors.rb +4 -3
  15. data/examples/sections.rb +26 -24
  16. data/examples/select.rb +28 -0
  17. data/examples/sh.rb +25 -7
  18. data/examples/tables.rb +19 -37
  19. data/examples/tasks.rb +32 -22
  20. data/examples/vbars.rb +5 -3
  21. data/lib/natty-ui/dumb_progress.rb +68 -0
  22. data/lib/natty-ui/element.rb +61 -70
  23. data/lib/natty-ui/features.rb +771 -949
  24. data/lib/natty-ui/frame.rb +87 -0
  25. data/lib/natty-ui/helper/table.rb +1376 -0
  26. data/lib/natty-ui/margin.rb +83 -0
  27. data/lib/natty-ui/progress.rb +116 -152
  28. data/lib/natty-ui/renderer/bars.rb +93 -0
  29. data/lib/natty-ui/renderer/choice.rb +56 -0
  30. data/lib/natty-ui/renderer/dumb_choice.rb +34 -0
  31. data/lib/natty-ui/renderer/dumb_select.rb +60 -0
  32. data/lib/natty-ui/renderer/dumb_shell_runner.rb +19 -0
  33. data/lib/natty-ui/renderer/heading.rb +26 -0
  34. data/lib/natty-ui/renderer/horizontal_rule.rb +32 -0
  35. data/lib/natty-ui/{ls_renderer.rb → renderer/ls.rb} +15 -27
  36. data/lib/natty-ui/renderer/mark.rb +13 -0
  37. data/lib/natty-ui/renderer/quote.rb +13 -0
  38. data/lib/natty-ui/renderer/select.rb +63 -0
  39. data/lib/natty-ui/renderer/shell.rb +15 -0
  40. data/lib/natty-ui/renderer/shell_runner.rb +29 -0
  41. data/lib/natty-ui/renderer/table_renderer.rb +429 -0
  42. data/lib/natty-ui/section.rb +144 -32
  43. data/lib/natty-ui/task.rb +38 -25
  44. data/lib/natty-ui/temporary.rb +27 -14
  45. data/lib/natty-ui/utils/border.rb +139 -0
  46. data/lib/natty-ui/utils/str_const.rb +62 -0
  47. data/lib/natty-ui/utils/utils.rb +47 -0
  48. data/lib/natty-ui/version.rb +1 -1
  49. data/lib/natty-ui.rb +76 -35
  50. metadata +31 -28
  51. data/examples/cols.rb +0 -38
  52. data/examples/illustration.rb +0 -60
  53. data/examples/options.rb +0 -28
  54. data/examples/themes.rb +0 -51
  55. data/lib/natty-ui/attributes.rb +0 -593
  56. data/lib/natty-ui/choice.rb +0 -67
  57. data/lib/natty-ui/dumb_choice.rb +0 -47
  58. data/lib/natty-ui/dumb_options.rb +0 -64
  59. data/lib/natty-ui/framed.rb +0 -50
  60. data/lib/natty-ui/hbars_renderer.rb +0 -66
  61. data/lib/natty-ui/options.rb +0 -78
  62. data/lib/natty-ui/shell_renderer.rb +0 -91
  63. data/lib/natty-ui/table.rb +0 -325
  64. data/lib/natty-ui/table_renderer.rb +0 -165
  65. data/lib/natty-ui/theme.rb +0 -403
  66. data/lib/natty-ui/utils.rb +0 -111
  67. data/lib/natty-ui/vbars_renderer.rb +0 -49
  68. data/lib/natty-ui/width_finder.rb +0 -137
  69. data/natty-ui.gemspec +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f193a0c86adab949f0d0c40d522e879d47f0a75a6a52ae9cf4f9ff39a7582e0e
4
- data.tar.gz: 2841fcf9135c48ef2df17ffcea4f5ff7619fe51dc62a489e58a9b7fc21f2bc1d
3
+ metadata.gz: ffd6017665733941fd093cbedda29b355bc207fd0ed3cecfdc041fcbc4b015f1
4
+ data.tar.gz: 0c8bd80f79200f5a0736a3830724e3effba02e45e90a7700ff3282206e0892fa
5
5
  SHA512:
6
- metadata.gz: 8d956fcf0d7cf2809bda3db9e82e84a02fe260e7646c54f1ba195dc04e3e8842677d6bb2c6e3dc95712c2da59580d6753e5218cccd2779408d10c1174cf96d12
7
- data.tar.gz: 99c7fa8acd5d4f6c12db79b95e02da4a269ade5439a8d6918ca8b47a07ac2dce24cb2f91a146f23fe3b9d4554588b2e6f9b02be476cf725d9e058985f7ed763a
6
+ metadata.gz: fc669642409c79aab2bf8147e6a1a490b83920e2549d8bf869c11d21e914c21b2f3e8e17135ce281d619716bbfb35536213826494a7e83ac37d996365c4ef6e4
7
+ data.tar.gz: 28ebfab029b8e77b9179f5d9652031e997cadc57e8eaf600729ccda22e0eaeb5443839ea58b7e157d7e425c495adddd38bd725d6c5e58758c9dff61b86be2f82
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
- # ​ᓚᕠᗢ NattyUI ![version](https://img.shields.io/gem/v/natty-ui?label=)
1
+ # ᓚᕠᗢ NattyUI v1.0.2
2
2
 
3
3
  This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, 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: [codeberg.org](https://codeberg.org/mblumtritt/natty-ui)
7
- - Help: [rubydoc.info](https://rubydoc.info/gems/natty-ui/NattyUI)
7
+ - Help: [rubydoc.info](https://rubydoc.info/gems/natty-ui/1.0.2/NattyUI)
8
8
 
9
9
  ## Features
10
10
 
11
- ![illustration](./examples/illustration.png)
11
+ ![illustration](./examples/illustration.jpeg)
12
12
 
13
13
  - automatic line break of all text output
14
14
  - markup of text attributes and colors using a [BBCode](https://en.wikipedia.org/wiki/BBCode) like syntax
@@ -28,7 +28,7 @@ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely, nat
28
28
 
29
29
  ## Help
30
30
 
31
- 📕 See the [online help](https://rubydoc.info/gems/natty-ui/index) and have a look at the [examples](./examples/) directory to learn from code.
31
+ 📕 See the [online help](https://rubydoc.info/gems/natty-ui/index) and have a look at the [examples](https://codeberg.org/mblumtritt/natty-ui/src/branch/main/examples) directory to learn from code.
32
32
 
33
33
  ### Run Examples
34
34
 
@@ -52,7 +52,7 @@ You can install the gem in your system with
52
52
  gem install natty-ui
53
53
  ```
54
54
 
55
- or you can use [Bundler](http://gembundler.com/) to add NattyUI to your own project:
55
+ or you can use [Bundler](https://bundler.io) to add NattyUI to your own project:
56
56
 
57
57
  ```shell
58
58
  bundle add natty-ui
@@ -66,4 +66,4 @@ require 'natty-ui'
66
66
 
67
67
  ## Dependencies
68
68
 
69
- It uses only the fantastic [Terminal.rb](https://rubygems.org/gems/terminal_rb) gem.
69
+ It uses the fantastic [Terminal.rb](https://rubygems.org/gems/terminal_rb) gem.
@@ -2,13 +2,17 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]24-bit Color Support[/]' do
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]24-bit Color Support' do
6
6
  bar = '█' * ui.columns
7
7
  rainbow =
8
- (7..21).map do |i|
9
- NattyUI::Ansi.rainbow(bar, seed: 3, spread: 3.25, frequency: i / 200.0)
8
+ (7..27).map do |i|
9
+ NattyUI::Ansi.rainbow(
10
+ bar,
11
+ spread: 3.33,
12
+ seed: 3.33,
13
+ frequency: i / 333.33
14
+ )
10
15
  end
11
16
 
12
- ui.space
13
- ui.puts(*rainbow)
17
+ ui.puts rainbow.join, padding: [1, 0]
14
18
  end
@@ -2,16 +2,14 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]3/4bit Color Support[/]' do
6
- ui.space
7
- ui.puts <<~INFO, eol: false
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]3/4bit Color Support' do
6
+ ui.puts <<~INFO, eol: false, padding: [1, 0]
8
7
  Terminals may support colors. You can colorize foreground text and
9
8
  background. The very basic color palette consists of eight colors and may
10
9
  be extended with eight colors which are much brighter.
11
10
  INFO
12
11
 
13
- ui.space
14
- ui.ls(
12
+ colors =
15
13
  %w[
16
14
  black
17
15
  red
@@ -29,6 +27,8 @@ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]3/4bit Color Support[/]' do
29
27
  bright_magenta
30
28
  bright_cyan
31
29
  bright_white
32
- ].map { |name| "[bg_#{name}]  [/bg] [#{name}]#{name}[/fg]" }
33
- )
30
+ ].map { |name| "[on_#{name}] [/bg] [#{name}]#{name}[/fg]" }
31
+
32
+ ui.ls colors
33
+ ui.space
34
34
  end
@@ -2,22 +2,20 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]8bit Color Support[/]' do
6
- color = ->(i) { "[bg#{i = i.to_s(16).rjust(2, '0')}] #{i} " }
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]8bit Color Support' do
6
+ color = ->(i) { "[on#{i = i.to_s(16).rjust(2, '0')}] #{i} " }
7
7
 
8
8
  ui.space
9
- ui.message 'System Colors', <<~COLORS.chomp
9
+ ui.message('System Colors').puts(<<~COLORS.chomp).end
10
10
  [#ff]#{0.upto(7).map(&color).join}
11
11
  [#00]#{8.upto(15).map(&color).join}
12
12
  COLORS
13
- ui.end
14
13
 
15
14
  ui.space
16
- ui.message 'Grayscale', <<~GRAYSCALE.chomp
15
+ ui.message('Grayscale').puts(<<~GRAYSCALE.chomp).end
17
16
  [#ff]#{0xe8.upto(0xf3).map(&color).join}
18
17
  [#ff]#{0xf4.upto(0xff).map(&color).join}
19
18
  GRAYSCALE
20
- ui.end
21
19
 
22
20
  ui.space
23
21
  ui.message '6x6x6 Color Cube' do
@@ -25,7 +23,7 @@ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]8bit Color Support[/]' do
25
23
  b.step(b + 185, by: 36) do |i|
26
24
  left = i.upto(i + 5).map(&color).join
27
25
  right = (i + 18).upto(i + 23).map(&color).join
28
- ui.puts "[#ff]#{left}[bg_default]#{right}"
26
+ ui.puts "[#ff]#{left}[on_default]#{right}"
29
27
  end
30
28
  end
31
29
  end
@@ -2,9 +2,8 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]ANSI Attributes[/]' do
6
- ui.space
7
- ui.puts <<~INFO_1, <<~INFO_2, eol: false
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]ANSI Attributes' do
6
+ ui.puts <<~INFO_1, <<~INFO_2, eol: false, padding: [1, 0]
8
7
  NattyUI supports all well known attributes like
9
8
  [b]bold[/b],
10
9
  [i]italic[/i],
data/examples/elements.rb CHANGED
@@ -2,23 +2,26 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Simple Elements[/]' do
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI:[/b] [i]Simple Elements' do
6
6
  ui.space
7
7
  ui.h1 'This is a [b]H1[/b] heading element'
8
8
 
9
9
  ui.space
10
10
  ui.h2 'This is a [b]H2[/b] heading element'
11
11
 
12
+ ui.space
13
+ ui.hr
14
+
12
15
  ui.space
13
16
  ui.quote "This is a\nmulti-line quotation"
14
17
 
18
+ ui.space
19
+ ui.hr '~'
20
+
15
21
  ui.space
16
22
  ui.h3 'This is a [b]H3[/b] heading element'
17
- ui.mark(
18
- 'This is a multi-line message',
19
- 'with a leading checkmark.',
20
- mark: :checkmark
21
- )
23
+ ui.mark "This is a multi-line\nmarked message."
24
+ ui.mark 'And this is', 'another one.', mark: '[bold bright_red]!'
22
25
 
23
26
  ui.space
24
27
  ui.h4 'This is a [b]H4[/b] heading element'
data/examples/examples.rb CHANGED
@@ -12,12 +12,13 @@ EXAMPLES = {
12
12
  'elements' => 'Simple Elements',
13
13
  'ls' => 'Print Lists',
14
14
  'tables' => 'Print Tables',
15
- 'cols' => 'Print Columns',
16
15
  'vbars' => 'Print Vertical Bars',
17
16
  'hbars' => 'Print Horizontal Bars',
18
17
  'sections' => 'Sections',
18
+ 'frames' => 'Frames',
19
+ 'sh' => 'Shell Execute',
19
20
  'tasks' => 'Tasks',
20
- 'options' => 'Options and Selections'
21
+ 'select' => 'Selections'
21
22
  }.freeze
22
23
 
23
24
  ui.space
@@ -25,12 +26,11 @@ ui.space
25
26
  while true
26
27
  selected =
27
28
  ui.choice(**EXAMPLES, abortable: true, selected: selected) do
28
- ui.cols(
29
- "[red] /\\_/\\\n( o.o )\n > ^ <",
30
- '[bright_green b]Select a natty example:',
31
- width: 8
32
- )
33
- ui.div('[faint](Abort with [\\ESC])', padding: [1, 0, 1])
29
+ ui.puts <<~INFO, padding: [0, 0, 1]
30
+ [red] /\\_/\\
31
+ [red]( o.o ) [bright_green b]Select a natty example:
32
+ [red] > ^ < [/fg faint](Abort with [\\ESC])
33
+ INFO
34
34
  end
35
35
 
36
36
  ui.space unless Terminal.ansi?
@@ -39,7 +39,7 @@ while true
39
39
  ui.temporary do
40
40
  load("#{__dir__}/#{selected}.rb")
41
41
  if Terminal.ansi?
42
- ui.await { ui.puts '[faint][\\Press ENTER to continue...]' }
42
+ ui.await { ui.puts '[faint][\Press a key to continue...]' }
43
43
  else
44
44
  ui.space
45
45
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Frames' do
6
+ ui.puts <<~INFO, eol: false, padding: [1, 0]
7
+ A [i]framed section[/i] is a block element which supports all other
8
+ features.
9
+ This means frames may contain text,
10
+ other sections and frames,
11
+ titles,
12
+ horizontal rules,
13
+ lists,
14
+ progress bars and much more.
15
+ INFO
16
+
17
+ ui.frame do
18
+ ui.margin 1, 0.25 do
19
+ ui.frame border: :heavy do
20
+ ui.puts 'Frames can have different types of borders.', padding: 1
21
+
22
+ ui.frame border: :double do
23
+ ui.puts 'And can have different borders for horizontal rules.',
24
+ padding: 1
25
+ ui.hr :single
26
+ ui.puts 'Frames are fun!', padding: [0, 1]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/examples/hbars.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Horizontal Bars[/]' do
6
- values = [11.97, 14.35, 15.51, 12.39, 14.3, 10.6, 17.7].freeze
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Print Horizontal Bars' do
6
+ values = [11.9712, 14.35, 15.51, 12.39, 14.3, 10.6, 17.7].freeze
7
7
 
8
8
  ui.space
9
9
  ui.hbars values, style: :blue
@@ -12,6 +12,9 @@ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Horizontal Bars[/]' do
12
12
  ui.space
13
13
  ui.hbars values, style: :green, normalize: true, width: 0.5, min: 10
14
14
  ui.puts <<~INFO, eol: false
15
- These are the same values but [i]normalized[/i] and printed in half width.
15
+ These are the same values but [i]normalized[/i] and limited to the half
16
+ width of the terminal.
16
17
  INFO
18
+
19
+ ui.space
17
20
  end
data/examples/info.rb CHANGED
@@ -4,7 +4,7 @@ require_relative '../lib/natty-ui'
4
4
 
5
5
  def colors
6
6
  return Terminal.colors if Terminal.colors < 8
7
- color_bar = "#{(0..15).map { "[#{_1.to_s(16).rjust(2, '0')}]██" }.join}[/]"
7
+ color_bar = "#{(0..15).map { "[#{it.to_s(16).rjust(2, '0')}]██" }.join}[/]"
8
8
  return "#{Terminal.colors}\n#{color_bar}" unless Terminal.true_color?
9
9
  <<~COLORS
10
10
  true color
@@ -13,15 +13,18 @@ def colors
13
13
  COLORS
14
14
  end
15
15
 
16
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Terminal Information[/]' do
16
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Terminal Information' do
17
17
  ui.space
18
- ui.table do |table|
19
- table.add 'Identifier', Terminal.application || 'unidentified'
20
- table.add 'ANSI support', Terminal.ansi? ? 'yes' : 'no'
21
- table.add 'Input mode', Terminal.input_mode
22
- table.add 'Screen size', Terminal.size.join(' x ')
23
- table.add 'Colors', colors
24
- table.columns[0].assign(width: 15, padding_right: 2, align: :right)
25
- table.columns[1].style = %i[bold bright_yellow]
18
+ ui.table(border: :none) do |table|
19
+ table.add_row 'Identifier', Terminal.application || 'unidentified'
20
+ table.add_row 'ANSI support', Terminal.ansi? ? 'yes' : 'no'
21
+ table.add_row 'Input mode', Terminal.input_mode
22
+ table.add_row 'Screen size', Terminal.size.join(' x ')
23
+ table.add_row 'Colors', colors
24
+ table.columns[0].attributes.assign(
25
+ width: 15,
26
+ right_padding: 2,
27
+ align: :right
28
+ )
26
29
  end
27
30
  end
@@ -2,24 +2,23 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Keyboard Key Codes[/]' do
6
- ui.space
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Keyboard Key Codes' do
7
6
  ui.puts(
8
- "Your terminal uses [bright_blue]#{Terminal.input_mode}[/] mode. Press a key!",
9
- '[dim](Exit with ESC)'
7
+ "Your terminal uses [bright_blue]#{
8
+ Terminal.input_mode
9
+ }[/] mode. Press a key!",
10
+ '[dim](Exit with ESC)',
11
+ padding: [1, 0, 1]
10
12
  )
11
13
 
12
- ui.space
13
14
  # if you like to have mouse position changes reported then use
14
15
  # 'mouse_move: true' in next line
15
16
  Terminal.on_key_event(mouse: true, focus: true, mouse_move: false) do |event|
16
17
  ui.puts(
17
18
  "#{event.raw.inspect} [dim]→[/dim] [bold bright_green]#{
18
- event.to_a.map { "[\\#{_1}]" }.join('+')
19
+ event.to_a.map { "[\\#{it}]" }.join('+')
19
20
  }#{" @ #{event.position.join(', ')}" if event.position}"
20
21
  )
21
- event.name != 'Esc'
22
+ break if event.name == 'Esc'
22
23
  end
23
-
24
- ui.space
25
24
  end
data/examples/ls.rb CHANGED
@@ -2,28 +2,28 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- lorem = <<~IPSUM.lines(chomp: true)
6
- Lorem ipsum dolor sit amet,
7
- consectetur adipisicing elit,
8
- sed do eiusmod tempor
9
- incididunt ut labore et
10
- dolore [red]magna[/] aliqua.
11
- Ut enim ad minim veniam, quis
12
- nostrud exercitation ullamco
13
- laboris nisi ut aliquip ex
14
- ea commodo [b]consequat[/b].
15
- Duis aute irure [bold green]dolor[/fg] in[/]
16
- reprehenderit in voluptate
17
- velit [underline]esse cillum[/] dolore eu
18
- fugiat nulla pariatur.
19
- Excepteur sint occaecat
20
- cupidatat non proident,
21
- sunt in culpa qui officia
22
- deserunt mollit anim id
23
- est laborum.
24
- IPSUM
25
-
26
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Lists[/]' do
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Print Lists' do
6
+ lorem = <<~IPSUM.lines(chomp: true)
7
+ [b]Lorem ipsum[/b] dolor sit amet,
8
+ consectetur adipisicing elit,
9
+ sed do eiusmod tempor
10
+ incididunt ut labore et
11
+ dolore [red]magna[/] aliqua.
12
+ Ut enim ad minim veniam, quis
13
+ nostrud exercitation ullamco
14
+ laboris nisi ut aliquip ex
15
+ ea commodo [b]consequat[/b].
16
+ Duis aute irure [bold green]dolor[/fg] in[/]
17
+ reprehenderit in voluptate
18
+ velit [underline]esse cillum[/] dolore eu
19
+ fugiat nulla pariatur.
20
+ Excepteur sint occaecat
21
+ cupidatat non proident,
22
+ sunt in culpa qui officia
23
+ deserunt mollit anim id
24
+ est laborum.
25
+ IPSUM
26
+
27
27
  ui.space
28
28
  ui.h2 'Traditional Display'
29
29
  ui.ls lorem, glyph: 1, compact: false
@@ -47,4 +47,6 @@ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Lists[/]' do
47
47
  ui.space
48
48
  ui.h2 'Custom Glyph'
49
49
  ui.ls lorem.take(5), glyph: '[b bright_yellow]→[/]'
50
+
51
+ ui.space
50
52
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Named Colors Support[/]' do
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Named Colors Support' do
6
6
  ui.space
7
7
  ui.puts <<~INFO, eol: false
8
8
  NattyUI supports a series of named color values,
@@ -11,13 +11,14 @@ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Named Colors Support[/]' do
11
11
 
12
12
  ui.space
13
13
  ui.information 'Note' do
14
- ui.puts 'Not all terminal emulators support true-colors.'
14
+ ui.puts 'Not all terminal emulators support true-color.'
15
15
  end
16
16
 
17
17
  ui.space
18
18
  ui.ls(
19
19
  NattyUI::Ansi.named_colors.filter_map do |name|
20
- "[bg_#{name}] [/bg] [#{name}]#{name}[/fg]" unless /\d/.match?(name)
20
+ "[on_#{name}] [/bg] [#{name}]#{name}[/fg]" unless /\d/.match?(name)
21
21
  end
22
22
  )
23
+ ui.space
23
24
  end
data/examples/sections.rb CHANGED
@@ -2,33 +2,35 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Sections[/]' do
6
- ui.space
7
- ui.information 'Informative Message' do
8
- ui.puts <<~TEXT, eol: false
9
- Sections and messages are elements which support any other feature. This
10
- means they may contain text, other sections, titles, horizontal rules,
11
- lists, progress bars and much more!
12
- TEXT
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Sections' do
6
+ ui.puts <<~TEXT, eol: false, padding: [1, 0]
7
+ A [i]section[/i] is a block element which supports all other features.
8
+ This means sections may contain text,
9
+ other sections and frames,
10
+ titles,
11
+ horizontal rules,
12
+ lists,
13
+ progress bars and much more.
14
+ TEXT
13
15
 
14
- ui.space
15
- ui.cols do |cc|
16
- cc.add "()-()\n \\\"/\n  `", width: 6, style: :yellow
17
- cc.add 'You can add all other elements to a section.', vertical: :middle
16
+ ui.message 'Section Types' do
17
+ ui.puts 'There are several pre-defined message types displayed here:',
18
+ padding: [1, 0]
19
+
20
+ ui.information 'Information' do
21
+ ui.puts 'Section type for informational notes.'
18
22
  end
19
23
 
20
- ui.framed(<<~TEXT, align: :centered, eol: false).end
21
- Sections and messages can be called with code blocks and will be
22
- automatically closed when the block ends. Without a code block the
23
- section or message needs to be closed.
24
- TEXT
25
- end
24
+ ui.warning 'Warning' do
25
+ ui.puts 'Section to bring attention tocontent.'
26
+ end
26
27
 
27
- ui.warning "Warning\nThis is a warning message example."
28
- ui.end
28
+ ui.error 'Error' do
29
+ ui.puts 'Section to display error messages.'
30
+ end
29
31
 
30
- ui.error('Error Message', <<~MSG, align: :right, prefix: '[b red]>[/] ').end
31
- Error message text with
32
- print options.
33
- MSG
32
+ ui.fatal 'Fatal' do
33
+ ui.puts 'Section to be used when things escalate.'
34
+ end
35
+ end
34
36
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.section '[b]ᓚᕠᗢ NattyUI[/b] [i green]Selection' do
6
+ ui.space
7
+ ui.puts <<~INFO, eol: false
8
+ [i]Selections[/i] allow the user to select from several options
9
+ interactively.
10
+ If ANSI is available the user can use [b][Up][/b] and [b][Down][/b] keys to
11
+ navigate, switch the state of selected item with [b][Space][/b] and complete
12
+ the selection with [b][Enter][/b].
13
+ INFO
14
+
15
+ ui.space
16
+ selected =
17
+ ui.select 'Kitty', 'iTerm2', 'Ghostty', 'Tabby', 'Rio' do
18
+ ui.puts '[i]Which terminal applications have you already tested?[/i]'
19
+ end
20
+ case selected.size
21
+ when 0
22
+ ui.puts 'You selected nothing – test more in the future!'
23
+ when 1
24
+ ui.puts "#{selected.first} is indeed a nice terminal."
25
+ else
26
+ ui.puts "#{selected.join(', ')} are worth testing!"
27
+ end
28
+ end
data/examples/sh.rb CHANGED
@@ -2,16 +2,34 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Call Shell[/]' do
5
+ ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Shell Execute' do
6
6
  ui.space
7
- ui.message 'Pipe this file to [i]cat[/i]; limit to five lines' do
8
- File.open(__FILE__) do |file|
9
- ui.run 'cat', input: file, preserve_spaces: true, max_lines: 5
10
- end
7
+ ui.puts <<~INFO, eol: false
8
+ You can simply run Shell commands and wrap their output at word boundaries,
9
+ or run commands, capture their output and error messages, and limit the
10
+ number of lines displayed.
11
+ INFO
12
+
13
+ ui.space
14
+ ui.message 'Run a shell command' do
15
+ ui.sh 'echo "Hello Ruby!"'
16
+ end
17
+
18
+ ui.space
19
+ ui.message 'Run a shell script' do
20
+ ui.run <<~SH_SCRIPT
21
+ for i in 1 2 3 4
22
+ do
23
+ for str in 'Hello Ruby!' 'This is an example output.' 3 4
24
+ do echo "$str" && sleep 0.1
25
+ done
26
+ echo 'This is an error example.' >&2
27
+ done
28
+ SH_SCRIPT
11
29
  end
12
30
 
13
31
  ui.space
14
- ui.message 'Call [i]cat[/i] with invalid option' do
15
- ui.sh 'cat', '-?'
32
+ ui.message 'Pipe this file to [i]cat[/i] command and limit the line count' do
33
+ File.open(__FILE__) { |file| ui.run 'cat', input: file, max_lines: 5 }
16
34
  end
17
35
  end