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.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/examples/24bit-colors.rb +9 -5
- data/examples/3bit-colors.rb +7 -7
- data/examples/8bit-colors.rb +5 -7
- data/examples/attributes.rb +2 -3
- data/examples/elements.rb +9 -6
- data/examples/examples.rb +9 -9
- data/examples/frames.rb +31 -0
- data/examples/hbars.rb +6 -3
- data/examples/info.rb +13 -10
- data/examples/key-codes.rb +8 -9
- data/examples/ls.rb +24 -22
- data/examples/named-colors.rb +4 -3
- data/examples/sections.rb +26 -24
- data/examples/select.rb +28 -0
- data/examples/sh.rb +25 -7
- data/examples/tables.rb +19 -37
- data/examples/tasks.rb +32 -22
- data/examples/vbars.rb +5 -3
- data/lib/natty-ui/dumb_progress.rb +68 -0
- data/lib/natty-ui/element.rb +61 -70
- data/lib/natty-ui/features.rb +771 -949
- data/lib/natty-ui/frame.rb +87 -0
- data/lib/natty-ui/helper/table.rb +1376 -0
- data/lib/natty-ui/margin.rb +83 -0
- data/lib/natty-ui/progress.rb +116 -152
- data/lib/natty-ui/renderer/bars.rb +93 -0
- data/lib/natty-ui/renderer/choice.rb +56 -0
- data/lib/natty-ui/renderer/dumb_choice.rb +34 -0
- data/lib/natty-ui/renderer/dumb_select.rb +60 -0
- data/lib/natty-ui/renderer/dumb_shell_runner.rb +19 -0
- data/lib/natty-ui/renderer/heading.rb +26 -0
- data/lib/natty-ui/renderer/horizontal_rule.rb +32 -0
- data/lib/natty-ui/{ls_renderer.rb → renderer/ls.rb} +15 -27
- data/lib/natty-ui/renderer/mark.rb +13 -0
- data/lib/natty-ui/renderer/quote.rb +13 -0
- data/lib/natty-ui/renderer/select.rb +63 -0
- data/lib/natty-ui/renderer/shell.rb +15 -0
- data/lib/natty-ui/renderer/shell_runner.rb +29 -0
- data/lib/natty-ui/renderer/table_renderer.rb +429 -0
- data/lib/natty-ui/section.rb +144 -32
- data/lib/natty-ui/task.rb +38 -25
- data/lib/natty-ui/temporary.rb +27 -14
- data/lib/natty-ui/utils/border.rb +139 -0
- data/lib/natty-ui/utils/str_const.rb +62 -0
- data/lib/natty-ui/utils/utils.rb +47 -0
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui.rb +76 -35
- metadata +31 -28
- data/examples/cols.rb +0 -38
- data/examples/illustration.rb +0 -60
- data/examples/options.rb +0 -28
- data/examples/themes.rb +0 -51
- data/lib/natty-ui/attributes.rb +0 -593
- data/lib/natty-ui/choice.rb +0 -67
- data/lib/natty-ui/dumb_choice.rb +0 -47
- data/lib/natty-ui/dumb_options.rb +0 -64
- data/lib/natty-ui/framed.rb +0 -50
- data/lib/natty-ui/hbars_renderer.rb +0 -66
- data/lib/natty-ui/options.rb +0 -78
- data/lib/natty-ui/shell_renderer.rb +0 -91
- data/lib/natty-ui/table.rb +0 -325
- data/lib/natty-ui/table_renderer.rb +0 -165
- data/lib/natty-ui/theme.rb +0 -403
- data/lib/natty-ui/utils.rb +0 -111
- data/lib/natty-ui/vbars_renderer.rb +0 -49
- data/lib/natty-ui/width_finder.rb +0 -137
- data/natty-ui.gemspec +0 -34
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffd6017665733941fd093cbedda29b355bc207fd0ed3cecfdc041fcbc4b015f1
|
|
4
|
+
data.tar.gz: 0c8bd80f79200f5a0736a3830724e3effba02e45e90a7700ff3282206e0892fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc669642409c79aab2bf8147e6a1a490b83920e2549d8bf869c11d21e914c21b2f3e8e17135ce281d619716bbfb35536213826494a7e83ac37d996365c4ef6e4
|
|
7
|
+
data.tar.gz: 28ebfab029b8e77b9179f5d9652031e997cadc57e8eaf600729ccda22e0eaeb5443839ea58b7e157d7e425c495adddd38bd725d6c5e58758c9dff61b86be2f82
|
data/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#
|
|
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
|
-

|
|
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](
|
|
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](
|
|
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
|
|
69
|
+
It uses the fantastic [Terminal.rb](https://rubygems.org/gems/terminal_rb) gem.
|
data/examples/24bit-colors.rb
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
ui.
|
|
5
|
+
ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]24-bit Color Support' do
|
|
6
6
|
bar = '█' * ui.columns
|
|
7
7
|
rainbow =
|
|
8
|
-
(7..
|
|
9
|
-
NattyUI::Ansi.rainbow(
|
|
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.
|
|
13
|
-
ui.puts(*rainbow)
|
|
17
|
+
ui.puts rainbow.join, padding: [1, 0]
|
|
14
18
|
end
|
data/examples/3bit-colors.rb
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
ui.
|
|
6
|
-
ui.
|
|
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
|
-
|
|
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| "[
|
|
33
|
-
|
|
30
|
+
].map { |name| "[on_#{name}] [/bg] [#{name}]#{name}[/fg]" }
|
|
31
|
+
|
|
32
|
+
ui.ls colors
|
|
33
|
+
ui.space
|
|
34
34
|
end
|
data/examples/8bit-colors.rb
CHANGED
|
@@ -2,22 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
ui.
|
|
6
|
-
color = ->(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
|
|
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
|
|
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}[
|
|
26
|
+
ui.puts "[#ff]#{left}[on_default]#{right}"
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
29
|
end
|
data/examples/attributes.rb
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
ui.
|
|
6
|
-
ui.
|
|
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.
|
|
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
|
-
|
|
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
|
-
'
|
|
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.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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][
|
|
42
|
+
ui.await { ui.puts '[faint][\Press a key to continue...]' }
|
|
43
43
|
else
|
|
44
44
|
ui.space
|
|
45
45
|
end
|
data/examples/frames.rb
ADDED
|
@@ -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.
|
|
6
|
-
values = [11.
|
|
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
|
|
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 { "[#{
|
|
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.
|
|
16
|
+
ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Terminal Information' do
|
|
17
17
|
ui.space
|
|
18
|
-
ui.table do |table|
|
|
19
|
-
table.
|
|
20
|
-
table.
|
|
21
|
-
table.
|
|
22
|
-
table.
|
|
23
|
-
table.
|
|
24
|
-
table.columns[0].assign(
|
|
25
|
-
|
|
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
|
data/examples/key-codes.rb
CHANGED
|
@@ -2,24 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
ui.
|
|
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]#{
|
|
9
|
-
|
|
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 { "[\\#{
|
|
19
|
+
event.to_a.map { "[\\#{it}]" }.join('+')
|
|
19
20
|
}#{" @ #{event.position.join(', ')}" if event.position}"
|
|
20
21
|
)
|
|
21
|
-
event.name
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
data/examples/named-colors.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative '../lib/natty-ui'
|
|
4
4
|
|
|
5
|
-
ui.
|
|
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-
|
|
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
|
-
"[
|
|
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.
|
|
6
|
-
ui.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
ui.
|
|
16
|
-
|
|
17
|
-
|
|
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.
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
28
|
-
|
|
28
|
+
ui.error 'Error' do
|
|
29
|
+
ui.puts 'Section to display error messages.'
|
|
30
|
+
end
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
ui.fatal 'Fatal' do
|
|
33
|
+
ui.puts 'Section to be used when things escalate.'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
34
36
|
end
|
data/examples/select.rb
ADDED
|
@@ -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.
|
|
5
|
+
ui.begin '[b]ᓚᕠᗢ NattyUI[/b] [i green]Shell Execute' do
|
|
6
6
|
ui.space
|
|
7
|
-
ui.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 '
|
|
15
|
-
ui.
|
|
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
|