natty-ui 0.11.2 → 0.12.1
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 +5 -2
- data/examples/24bit-colors.rb +1 -3
- data/examples/3bit-colors.rb +1 -3
- data/examples/8bit-colors.rb +4 -6
- data/examples/animate.rb +7 -9
- data/examples/attributes.rb +7 -10
- data/examples/attributes_list.rb +2 -4
- data/examples/demo.rb +1 -3
- data/examples/ls.rb +1 -3
- data/examples/message.rb +1 -3
- data/examples/progress.rb +9 -6
- data/examples/query.rb +1 -3
- data/examples/read_key.rb +1 -1
- data/examples/table.rb +1 -3
- data/lib/natty-ui/animation/binary.rb +1 -2
- data/lib/natty-ui/animation/default.rb +9 -13
- data/lib/natty-ui/animation/matrix.rb +0 -4
- data/lib/natty-ui/animation/type_writer.rb +5 -5
- data/lib/natty-ui/animation.rb +6 -6
- data/lib/natty-ui/ansi/constants.rb +6 -6
- data/lib/natty-ui/ansi.rb +19 -10
- data/lib/natty-ui/ansi_wrapper.rb +58 -29
- data/lib/natty-ui/frame.rb +53 -0
- data/lib/natty-ui/glyph.rb +64 -0
- data/lib/natty-ui/preload.rb +5 -2
- data/lib/natty-ui/spinner.rb +120 -0
- data/lib/natty-ui/text/east_asian_width.rb +1 -1
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/wrapper/ask.rb +1 -1
- data/lib/natty-ui/wrapper/framed.rb +3 -3
- data/lib/natty-ui/wrapper/heading.rb +10 -6
- data/lib/natty-ui/wrapper/list_in_columns.rb +1 -1
- data/lib/natty-ui/wrapper/message.rb +2 -2
- data/lib/natty-ui/wrapper/mixins.rb +11 -3
- data/lib/natty-ui/wrapper/progress.rb +7 -36
- data/lib/natty-ui/wrapper/request.rb +1 -1
- data/lib/natty-ui/wrapper/table.rb +8 -12
- data/lib/natty-ui/wrapper.rb +14 -5
- data/lib/natty-ui.rb +6 -66
- metadata +8 -5
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'text'
|
4
|
+
|
5
|
+
module NattyUI
|
6
|
+
# Helper class to select glyph types.
|
7
|
+
# @see Features#message
|
8
|
+
module Glyph
|
9
|
+
# Define glyph type used by default.
|
10
|
+
# @attribute [w] self.default
|
11
|
+
# @param value [Symbol] type name
|
12
|
+
# @return [Symbol] type name
|
13
|
+
def self.default=(value)
|
14
|
+
@default = self[value.nil? || value == :default ? :point : value]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Defined glyph type names.
|
18
|
+
# @see []
|
19
|
+
#
|
20
|
+
# @attribute [r] self.names
|
21
|
+
# @return [Array<Symbol>] supported attribute names
|
22
|
+
def self.names = @all.keys
|
23
|
+
|
24
|
+
# @param name [Symbol, #to_s]
|
25
|
+
# defined type name (see {.names})
|
26
|
+
# or glyph
|
27
|
+
# @return [String] glyph definition
|
28
|
+
def self.[](name)
|
29
|
+
return @default if name == :default
|
30
|
+
Text.embellish(
|
31
|
+
if name.is_a?(Symbol)
|
32
|
+
@all[name] or raise(ArgumentError, "invalid glyph type - #{name}")
|
33
|
+
else
|
34
|
+
name.to_s
|
35
|
+
end
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
@all = {
|
40
|
+
completed: '[b 52]✓',
|
41
|
+
dot: '[27]•',
|
42
|
+
error: '[b d0]𝙓',
|
43
|
+
failed: '[b c4]𝑭',
|
44
|
+
information: '[b 77]𝒊',
|
45
|
+
point: '[27]◉',
|
46
|
+
query: '[b 27]▸',
|
47
|
+
task: '[b 27]➔',
|
48
|
+
warning: '[b dd]!'
|
49
|
+
}.compare_by_identity
|
50
|
+
|
51
|
+
# GLYPH = {
|
52
|
+
# default: '●',
|
53
|
+
# information: '🅸 ',
|
54
|
+
# warning: '🆆 ',
|
55
|
+
# error: '🅴 ',
|
56
|
+
# completed: '✓',
|
57
|
+
# failed: '🅵 ',
|
58
|
+
# task: '➔',
|
59
|
+
# query: '🆀 '
|
60
|
+
# }.compare_by_identity.freeze
|
61
|
+
|
62
|
+
self.default = nil
|
63
|
+
end
|
64
|
+
end
|
data/lib/natty-ui/preload.rb
CHANGED
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'ansi'
|
4
|
+
|
5
|
+
module NattyUI
|
6
|
+
# Helper class to select spinner types.
|
7
|
+
# @see Features#progress
|
8
|
+
module Spinner
|
9
|
+
class << self
|
10
|
+
# Define spinner type used by default.
|
11
|
+
# @attribute [w] self.default
|
12
|
+
# @param value [Symbol] type name
|
13
|
+
# @return [Symbol] type name
|
14
|
+
def default=(value)
|
15
|
+
@default = self[value.nil? || value == :default ? :pulse : value]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Defined spinner type names.
|
19
|
+
# @see []
|
20
|
+
#
|
21
|
+
# @attribute [r] self.names
|
22
|
+
# @return [Array<Symbol>] supported attribute names
|
23
|
+
def names = @all.keys
|
24
|
+
|
25
|
+
# @param name [Symbol, #to_a, #to_s]
|
26
|
+
# defined type name (see {.names})
|
27
|
+
# or spinner elements
|
28
|
+
# @return [Enumerator] spinner definition
|
29
|
+
def [](name)
|
30
|
+
return @default if name == :default
|
31
|
+
parts =
|
32
|
+
if name.is_a?(Symbol)
|
33
|
+
@all[name] or raise(ArgumentError, "invalid spinner type - #{name}")
|
34
|
+
else
|
35
|
+
name
|
36
|
+
end
|
37
|
+
parts =
|
38
|
+
(parts.respond_to?(:map) ? parts : parts.to_s.chars).map do |part|
|
39
|
+
"#{@style}#{part}#{Ansi::RESET}"
|
40
|
+
end
|
41
|
+
raise(ArgumentError, "invalid spinner type - #{name}") if parts.empty?
|
42
|
+
parts = parts.zip(parts).flatten(1) while parts.size < 6
|
43
|
+
Enumerator.new { |y| parts.each { y << _1 } while true }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def slide(a, b, size, prefix = nil, suffix = prefix)
|
49
|
+
Enumerator.new do |y|
|
50
|
+
fn =
|
51
|
+
lambda do |i|
|
52
|
+
y << "#{prefix}#{a * (i += 1)}#{b * (size - i)}#{suffix}"
|
53
|
+
end
|
54
|
+
size.times(&fn)
|
55
|
+
a, b = b, a
|
56
|
+
size.times(&fn)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def bounce(a, b, size, prefix = nil, suffix = prefix)
|
61
|
+
Enumerator.new do |y|
|
62
|
+
fn =
|
63
|
+
lambda do |i|
|
64
|
+
y << "#{prefix}#{a * (i += 1)}#{b * (size - i)}#{suffix}"
|
65
|
+
end
|
66
|
+
size.times(&fn)
|
67
|
+
a, b = b, a
|
68
|
+
(size - 1).times(&fn)
|
69
|
+
fn = ->(i) { y << "#{prefix}#{a * i}#{b * (size - i)}#{suffix}" }
|
70
|
+
(size - 2).downto(0, &fn)
|
71
|
+
a, b = b, a
|
72
|
+
(size - 1).downto(0, &fn)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def move(a, b, size, prefix = nil, suffix = prefix)
|
77
|
+
Enumerator.new do |y|
|
78
|
+
size.times do |i|
|
79
|
+
y << "#{prefix}#{b * i}#{a}#{b * (size - i - 1)}#{suffix}"
|
80
|
+
end
|
81
|
+
y << "#{prefix}#{b * size}#{suffix}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
@style = Ansi[:bold, 220]
|
87
|
+
@all = {
|
88
|
+
bar: '▁▂▃▄▅▆▇█▇▆▅▄▃▂',
|
89
|
+
blink: '■□▪▫',
|
90
|
+
blocks: '▖▘▝▗',
|
91
|
+
bounce: bounce('◼︎', '◻︎', 7),
|
92
|
+
bounce2: bounce('▰', '▱', 7),
|
93
|
+
bounce3: bounce('● ', '◌ ', 7),
|
94
|
+
bounce4: bounce('=', ' ', 5, '[', ']'),
|
95
|
+
circle: '◐◓◑◒',
|
96
|
+
colors: '🟨🟨🟧🟧🟥🟥🟦🟦🟪🟪🟩🟩',
|
97
|
+
dots: '⣷⣯⣟⡿⢿⣻⣽⣾',
|
98
|
+
dots2: '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏',
|
99
|
+
dots3: '⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓',
|
100
|
+
dots4: '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆',
|
101
|
+
dots5: '⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋',
|
102
|
+
move: move('◼︎', '◻︎', 7),
|
103
|
+
move2: move('▰', '▱', 7),
|
104
|
+
move3: move('● ', '◌ ', 7),
|
105
|
+
move4: move('=', ' ', 5, '[', ']'),
|
106
|
+
pulse: '•✺◉●◉✺',
|
107
|
+
slide: slide('◼︎', '◻︎', 7),
|
108
|
+
slide2: slide('▰', '▱', 7),
|
109
|
+
slide3: slide('● ', '◌ ', 7),
|
110
|
+
slide4: slide('=', ' ', 5, '[', ']'),
|
111
|
+
slide5: slide('.', ' ', 3),
|
112
|
+
snake: '⠁⠉⠙⠸⢰⣠⣄⡆⠇⠃',
|
113
|
+
stod: '⡿⣟⣯⣷⣾⣽⣻⢿',
|
114
|
+
swap: '㊂㊀㊁',
|
115
|
+
vintage: '-\\|/'
|
116
|
+
}.compare_by_identity
|
117
|
+
|
118
|
+
self.default = nil
|
119
|
+
end
|
120
|
+
end
|
data/lib/natty-ui/version.rb
CHANGED
data/lib/natty-ui/wrapper/ask.rb
CHANGED
@@ -11,12 +11,12 @@ module NattyUI
|
|
11
11
|
# {Wrapper::Element#close}.
|
12
12
|
#
|
13
13
|
# @param [Array<#to_s>] args more objects to print
|
14
|
-
# @param [
|
14
|
+
# @param [Symbol, String] type frame type; see {NattyUI::Frame}
|
15
15
|
# @yieldparam [Wrapper::Framed] framed the created section
|
16
16
|
# @return [Object] the result of the code block
|
17
17
|
# @return [Wrapper::Framed] itself, when no code block is given
|
18
|
-
def framed(*args, type: :
|
19
|
-
_section(:Framed, args, type: NattyUI
|
18
|
+
def framed(*args, type: :default, &block)
|
19
|
+
_section(:Framed, args, type: NattyUI::Frame[type], &block)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -7,32 +7,33 @@ module NattyUI
|
|
7
7
|
# Prints a H1 title.
|
8
8
|
#
|
9
9
|
# @param [#to_s] title text
|
10
|
+
# @param [#to_i] space space around the heading
|
10
11
|
# @return [Wrapper::Section, Wrapper] it's parent object
|
11
|
-
def h1(title) = _element(:Heading, title, '═══════')
|
12
|
+
def h1(title, space: 0) = _element(:Heading, title, space, '═══════')
|
12
13
|
|
13
14
|
# Prints a H2 title.
|
14
15
|
#
|
15
16
|
# @param (see #h1)
|
16
17
|
# @return (see #h1)
|
17
|
-
def h2(title) = _element(:Heading, title, '━━━━━')
|
18
|
+
def h2(title, space: 0) = _element(:Heading, title, space, '━━━━━')
|
18
19
|
|
19
20
|
# Prints a H3 title.
|
20
21
|
#
|
21
22
|
# @param (see #h1)
|
22
23
|
# @return (see #h1)
|
23
|
-
def h3(title) = _element(:Heading, title, '━━━')
|
24
|
+
def h3(title, space: 0) = _element(:Heading, title, space, '━━━')
|
24
25
|
|
25
26
|
# Prints a H4 title.
|
26
27
|
#
|
27
28
|
# @param (see #h1)
|
28
29
|
# @return (see #h1)
|
29
|
-
def h4(title) = _element(:Heading, title, '───')
|
30
|
+
def h4(title, space: 0) = _element(:Heading, title, space, '───')
|
30
31
|
|
31
32
|
# Prints a H5 title.
|
32
33
|
#
|
33
34
|
# @param (see #h1)
|
34
35
|
# @return (see #h1)
|
35
|
-
def h5(title) = _element(:Heading, title, '──')
|
36
|
+
def h5(title, space: 0) = _element(:Heading, title, space, '──')
|
36
37
|
end
|
37
38
|
|
38
39
|
class Wrapper
|
@@ -47,13 +48,16 @@ module NattyUI
|
|
47
48
|
class Heading < Element
|
48
49
|
protected
|
49
50
|
|
50
|
-
def call(title, enclose)
|
51
|
+
def call(title, space, enclose)
|
52
|
+
(space = space.to_i).positive? and (before = space / 2).positive? and
|
53
|
+
@parent.space(before)
|
51
54
|
@parent.puts(
|
52
55
|
title,
|
53
56
|
prefix: "#{Ansi[39]}#{enclose} #{Ansi[:bold, 255]}",
|
54
57
|
suffix: " #{Ansi[:bold_off, 39]}#{enclose}#{Ansi::RESET}",
|
55
58
|
max_width: available_width - 2 - (enclose.size * 2)
|
56
59
|
)
|
60
|
+
@parent.space(space - before) if before
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -9,7 +9,7 @@ module NattyUI
|
|
9
9
|
#
|
10
10
|
# @param [#to_s] title object to print as section title
|
11
11
|
# @param [Array<#to_s>] args more objects to print
|
12
|
-
# @param [#to_s] glyph
|
12
|
+
# @param [Symbol, #to_s] glyph used for the title; see {NattyUI::Glyph}
|
13
13
|
# @yieldparam [Wrapper::Message] message the created section
|
14
14
|
# @return [Object] the result of the code block
|
15
15
|
# @return [Wrapper::Message] itself, when no code block is given
|
@@ -94,7 +94,7 @@ module NattyUI
|
|
94
94
|
protected
|
95
95
|
|
96
96
|
def initialize(parent, title:, glyph:)
|
97
|
-
glyph = NattyUI
|
97
|
+
glyph = NattyUI::Glyph[glyph]
|
98
98
|
prefix_width = Text.width(glyph) + 1
|
99
99
|
super(
|
100
100
|
parent,
|
@@ -43,9 +43,17 @@ module NattyUI
|
|
43
43
|
# @return [Float] current value
|
44
44
|
attr_reader :value
|
45
45
|
|
46
|
-
def value=(
|
47
|
-
@value = [0,
|
48
|
-
@max_value = @value if @max_value&.<
|
46
|
+
def value=(value)
|
47
|
+
@value = [0, value.to_f].max
|
48
|
+
@max_value = @value if @max_value&.< @value
|
49
|
+
redraw
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [String, nil] current information
|
53
|
+
attr_reader :info
|
54
|
+
|
55
|
+
def info=(value)
|
56
|
+
@info = value
|
49
57
|
redraw
|
50
58
|
end
|
51
59
|
|
@@ -18,11 +18,9 @@ module NattyUI
|
|
18
18
|
#
|
19
19
|
# @param [#to_s] title object to print as progress title
|
20
20
|
# @param [#to_f] max_value maximum value of the progress
|
21
|
-
# @param [
|
22
|
-
# :snake, :swap, :triangles, :vintage, #to_s] spinner type of spinner or
|
23
|
-
# spinner elements
|
21
|
+
# @param [Symbol, #to_a, #to_s] spinner spinner type; see {NattyUI::Spinner}
|
24
22
|
# @return [Wrapper::Progress] the created progress element
|
25
|
-
def progress(title, max_value: nil, spinner: :
|
23
|
+
def progress(title, max_value: nil, spinner: :default)
|
26
24
|
_element(:Progress, title, max_value, spinner)
|
27
25
|
end
|
28
26
|
end
|
@@ -38,37 +36,16 @@ module NattyUI
|
|
38
36
|
|
39
37
|
protected
|
40
38
|
|
41
|
-
def call(title, max_value,
|
39
|
+
def call(title, max_value, _spinner)
|
42
40
|
@final_text = [title]
|
43
41
|
@max_value = [0, max_value.to_f].max if max_value
|
44
42
|
@value = @progress = 0
|
45
|
-
draw(title, SPINNER[spinner] || spinner.to_s)
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
SPINNER = {
|
50
|
-
bar: '▁▂▃▄▅▆▇█▇▆▅▄▃▂',
|
51
|
-
blink: '■□▪▫',
|
52
|
-
blocks: '▖▘▝▗',
|
53
|
-
braile: '⣷⣯⣟⡿⢿⣻⣽⣾',
|
54
|
-
braile_reverse: '⡿⣟⣯⣷⣾⣽⣻⢿',
|
55
|
-
circle: '◐◓◑◒',
|
56
|
-
colors: '🟨🟧🟥🟦🟪🟩',
|
57
|
-
pulse: '•✺◉●◉✺',
|
58
|
-
snake: '⠁⠉⠙⠸⢰⣠⣄⡆⠇⠃',
|
59
|
-
swap: '㊂㊀㊁',
|
60
|
-
triangles: '◢◣◤◥',
|
61
|
-
vintage: '-\\|/'
|
62
|
-
}.compare_by_identity.freeze
|
63
|
-
private_constant :SPINNER
|
64
|
-
|
65
|
-
def draw(title, _spinner)
|
66
43
|
(wrapper.stream << @parent.prefix << "➔ #{title} ").flush
|
44
|
+
self
|
67
45
|
end
|
68
46
|
|
69
|
-
def end_draw = (wrapper.stream << "\n")
|
70
|
-
|
71
47
|
def redraw
|
48
|
+
return if @status
|
72
49
|
return (wrapper.stream << '.').flush unless @max_value
|
73
50
|
cn = (20 * @value / @max_value).to_i
|
74
51
|
return if @progress == cn
|
@@ -77,15 +54,9 @@ module NattyUI
|
|
77
54
|
end
|
78
55
|
|
79
56
|
def finish
|
80
|
-
|
57
|
+
wrapper.stream << "\n"
|
81
58
|
return @parent.failed(*@final_text) if failed?
|
82
|
-
|
83
|
-
:Message,
|
84
|
-
@final_text,
|
85
|
-
owner: @parent,
|
86
|
-
title: @final_text.shift,
|
87
|
-
glyph: @status = :completed
|
88
|
-
)
|
59
|
+
@parent.message(*@final_text, glyph: @status = :completed)
|
89
60
|
end
|
90
61
|
end
|
91
62
|
end
|
@@ -7,14 +7,11 @@ module NattyUI
|
|
7
7
|
#
|
8
8
|
# Table view of data.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
# :double, :heavy, :semi, :simple
|
12
|
-
#
|
13
|
-
# @overload table(*args, type: simple, expand: false)
|
10
|
+
# @overload table(*args, type: :default, expand: false)
|
14
11
|
# Display the given arrays as rows of a table.
|
15
12
|
#
|
16
13
|
# @param [#map<#map<#to_s>>] args one or more arrays representing rows of the table
|
17
|
-
# @param [Symbol] type frame type
|
14
|
+
# @param [Symbol, String] type frame type; see {NattyUI::Frame}
|
18
15
|
# @param [false, true. :equal] expand
|
19
16
|
#
|
20
17
|
# @example
|
@@ -33,10 +30,10 @@ module NattyUI
|
|
33
30
|
# # ───────┼───────┼───────────
|
34
31
|
# # kiwi │ 1.5$ │ Newzeeland
|
35
32
|
#
|
36
|
-
# @overload table(type:
|
33
|
+
# @overload table(type: :default, expand: false)
|
37
34
|
# Construct and display a table.
|
38
35
|
#
|
39
|
-
# @param [Symbol] type frame type
|
36
|
+
# @param [Symbol, String] type frame type; see {NattyUI::Frame}
|
40
37
|
# @param [false, true. :equal] expand
|
41
38
|
#
|
42
39
|
# @example
|
@@ -58,8 +55,8 @@ module NattyUI
|
|
58
55
|
#
|
59
56
|
# @yield [Table] table construction helper
|
60
57
|
# @return [Wrapper::Section, Wrapper] it's parent object
|
61
|
-
def table(*table, type: :
|
62
|
-
type = NattyUI
|
58
|
+
def table(*table, type: :default, expand: false)
|
59
|
+
type = NattyUI::Frame[type]
|
63
60
|
table = Table.create(*table)
|
64
61
|
yield(table) if block_given?
|
65
62
|
_element(:Table, table, type, expand)
|
@@ -162,8 +159,7 @@ module NattyUI
|
|
162
159
|
if columns.size == 1 && columns[0].respond_to?(:map)
|
163
160
|
columns = columns[0]
|
164
161
|
end
|
165
|
-
columns =
|
166
|
-
columns.map { |cell| as_cell(cell, align, style) if cell }.to_a
|
162
|
+
columns = columns.map { as_cell(_1, align, style) if _1 }.to_a
|
167
163
|
@rows << (columns.empty? ? nil : columns)
|
168
164
|
self
|
169
165
|
end
|
@@ -370,7 +366,7 @@ module NattyUI
|
|
370
366
|
@parent.available_width - 1,
|
371
367
|
frame,
|
372
368
|
enlarge
|
373
|
-
) {
|
369
|
+
) { @parent.puts(_1) }
|
374
370
|
@parent
|
375
371
|
end
|
376
372
|
end
|
data/lib/natty-ui/wrapper.rb
CHANGED
@@ -31,6 +31,15 @@ module NattyUI
|
|
31
31
|
# @return [Boolean] whether ANSI is supported
|
32
32
|
def ansi? = false
|
33
33
|
|
34
|
+
# Cursor visibility
|
35
|
+
# @attribute [r] cursor
|
36
|
+
def cursor = @cursor.zero?
|
37
|
+
|
38
|
+
# @attribute [w] cursor
|
39
|
+
def cursor=(value)
|
40
|
+
# nop
|
41
|
+
end
|
42
|
+
|
34
43
|
# @attribute [r] screen_size
|
35
44
|
# @return [[Integer, Integer]] screen size as rows and columns
|
36
45
|
def screen_size = (@screen_size ||= determine_screen_size)
|
@@ -43,6 +52,10 @@ module NattyUI
|
|
43
52
|
# @return [Integer] number of screen columns
|
44
53
|
def screen_columns = screen_size[1]
|
45
54
|
|
55
|
+
# @attribute [r] wrapper
|
56
|
+
# @return [Wrapper] self
|
57
|
+
alias wrapper itself
|
58
|
+
|
46
59
|
# @!group Tool functions
|
47
60
|
|
48
61
|
# Print given arguments line-wise to the output stream.
|
@@ -144,10 +157,6 @@ module NattyUI
|
|
144
157
|
# @!visibility private
|
145
158
|
alias inspect to_s
|
146
159
|
|
147
|
-
# @attribute [r] wrapper
|
148
|
-
# @return [Wrapper] self
|
149
|
-
alias wrapper itself
|
150
|
-
|
151
160
|
# @!visibility private
|
152
161
|
alias available_width screen_columns
|
153
162
|
|
@@ -198,7 +207,7 @@ module NattyUI
|
|
198
207
|
|
199
208
|
def initialize(stream)
|
200
209
|
@stream = stream
|
201
|
-
@lines_written = 0
|
210
|
+
@lines_written = @cursor = 0
|
202
211
|
end
|
203
212
|
|
204
213
|
private_class_method :new
|
data/lib/natty-ui.rb
CHANGED
@@ -5,8 +5,8 @@ require_relative 'natty-ui/wrapper'
|
|
5
5
|
require_relative 'natty-ui/ansi_wrapper'
|
6
6
|
|
7
7
|
#
|
8
|
-
# Module to create beautiful, nice, nifty, fancy, neat, pretty, cool,
|
9
|
-
# natty user interfaces for your CLI application.
|
8
|
+
# Module to create beautiful, nice, nifty, fancy, neat, pretty, cool, rich,
|
9
|
+
# lovely, natty user interfaces for your CLI application.
|
10
10
|
#
|
11
11
|
# It creates {Wrapper} instances which can optionally support ANSI. The UI
|
12
12
|
# consists of {Wrapper::Element}s and {Wrapper::Section}s for different
|
@@ -135,34 +135,6 @@ module NattyUI
|
|
135
135
|
nil
|
136
136
|
end
|
137
137
|
|
138
|
-
# @return [Array<Symbol>] available glyph names
|
139
|
-
def glyph_names = GLYPH.keys
|
140
|
-
|
141
|
-
# Get a pre-defined glyph.
|
142
|
-
#
|
143
|
-
# @param [Symbol] name glyph name
|
144
|
-
# @return [String] the glyph
|
145
|
-
# @return [nil] when glyph is not defined
|
146
|
-
def glyph(name) = GLYPH[name]
|
147
|
-
|
148
|
-
# @return [Array<Symbol>] available frame names
|
149
|
-
def frame_names = FRAME.keys
|
150
|
-
|
151
|
-
# Get a frame definition.
|
152
|
-
#
|
153
|
-
# @param [Symbol] name frame type name
|
154
|
-
# @return [String] the frame definition
|
155
|
-
# @raise [ArgumentError] when an invalid name is specified
|
156
|
-
def frame(name)
|
157
|
-
if name.is_a?(Symbol)
|
158
|
-
ret = FRAME[name] and return ret
|
159
|
-
elsif name.is_a?(String)
|
160
|
-
return name if name.size == 11
|
161
|
-
return name * 11 if name.size == 1
|
162
|
-
end
|
163
|
-
raise(ArgumentError, "invalid frame type - #{name.inspect}")
|
164
|
-
end
|
165
|
-
|
166
138
|
private
|
167
139
|
|
168
140
|
def wrapper_class(stream, ansi)
|
@@ -188,44 +160,12 @@ module NattyUI
|
|
188
160
|
|
189
161
|
dir = __dir__
|
190
162
|
autoload(:Animation, File.join(dir, 'natty-ui', 'animation'))
|
163
|
+
autoload(:Frame, File.join(dir, 'natty-ui', 'frame'))
|
164
|
+
autoload(:Glyph, File.join(dir, 'natty-ui', 'glyph'))
|
191
165
|
autoload(:KEY_MAP, File.join(dir, 'natty-ui', 'key_map'))
|
166
|
+
autoload(:Spinner, File.join(dir, 'natty-ui', 'spinner'))
|
192
167
|
|
193
|
-
|
194
|
-
default: "#{Ansi[:bold, 255]}•#{Ansi::RESET}",
|
195
|
-
point: "#{Ansi[0x27]}◉#{Ansi::RESET}",
|
196
|
-
information: "#{Ansi[:bold, 119]}𝒊#{Ansi::RESET}",
|
197
|
-
warning: "#{Ansi[:bold, 221]}!#{Ansi::RESET}",
|
198
|
-
error: "#{Ansi[:bold, 208]}𝙓#{Ansi::RESET}",
|
199
|
-
completed: "#{Ansi[:bold, 82]}✓#{Ansi::RESET}",
|
200
|
-
failed: "#{Ansi[:bold, 196]}𝑭#{Ansi::RESET}",
|
201
|
-
task: "#{Ansi[:bold, 39]}➔#{Ansi::RESET}",
|
202
|
-
query: "#{Ansi[:bold, 39]}▸#{Ansi::RESET}"
|
203
|
-
}.compare_by_identity.freeze
|
204
|
-
|
205
|
-
# GLYPH = {
|
206
|
-
# default: '●',
|
207
|
-
# information: '🅸 ',
|
208
|
-
# warning: '🆆 ',
|
209
|
-
# error: '🅴 ',
|
210
|
-
# completed: '✓',
|
211
|
-
# failed: '🅵 ',
|
212
|
-
# task: '➔',
|
213
|
-
# query: '🆀 '
|
214
|
-
# }.compare_by_identity.freeze
|
215
|
-
|
216
|
-
FRAME = {
|
217
|
-
rounded: '╭╮╰╯│─┼┬┴├┤',
|
218
|
-
simple: '┌┐└┘│─┼┬┴├┤',
|
219
|
-
heavy: '┏┓┗┛┃━╋┳┻┣┫',
|
220
|
-
double: '╔╗╚╝║═╬╦╩╠╣',
|
221
|
-
semi: '╒╕╘╛│═╪╤╧╞╡',
|
222
|
-
semi2: '╓╖╙╜│─╫╥╨╟╢',
|
223
|
-
rows: ' ── ',
|
224
|
-
cols: ' │ │ ',
|
225
|
-
undecorated: ' '
|
226
|
-
}.compare_by_identity.freeze
|
227
|
-
|
228
|
-
private_constant :Animation, :KEY_MAP, :GLYPH, :FRAME
|
168
|
+
private_constant :Animation, :KEY_MAP
|
229
169
|
|
230
170
|
@element = StdOut
|
231
171
|
self.in_stream = STDIN
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natty-ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
|
-
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
|
14
|
+
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
|
15
15
|
natty user interface tool you like to have for your command line applications.
|
16
16
|
It contains elegant, simple and beautiful features that enhance your
|
17
17
|
command line interfaces functionally and aesthetically.
|
@@ -49,8 +49,11 @@ files:
|
|
49
49
|
- lib/natty-ui/ansi.rb
|
50
50
|
- lib/natty-ui/ansi/constants.rb
|
51
51
|
- lib/natty-ui/ansi_wrapper.rb
|
52
|
+
- lib/natty-ui/frame.rb
|
53
|
+
- lib/natty-ui/glyph.rb
|
52
54
|
- lib/natty-ui/key_map.rb
|
53
55
|
- lib/natty-ui/preload.rb
|
56
|
+
- lib/natty-ui/spinner.rb
|
54
57
|
- lib/natty-ui/text.rb
|
55
58
|
- lib/natty-ui/text/east_asian_width.rb
|
56
59
|
- lib/natty-ui/version.rb
|
@@ -99,6 +102,6 @@ requirements: []
|
|
99
102
|
rubygems_version: 3.5.17
|
100
103
|
signing_key:
|
101
104
|
specification_version: 4
|
102
|
-
summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
|
103
|
-
user interface you like to have for your CLI.
|
105
|
+
summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
|
106
|
+
natty user interface you like to have for your CLI.
|
104
107
|
test_files: []
|