natty-ui 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ad3de350d186095b5c1d0c55e94171367fc2efefbfbe78a17c31aa10a7a94e6
4
- data.tar.gz: e7bdd00a40c25dec0fe0526cf09e2bc7ad967f7772f4de9dc321218d96114448
3
+ metadata.gz: 0aa357f7937c367ecc77396e7241f33a774973d773b99c6923cc975199755a14
4
+ data.tar.gz: '060778aaca552a23c57e39e4efd8adf3eff07658e6a712708b6c8e46c5077bc1'
5
5
  SHA512:
6
- metadata.gz: e7fa944d6f43866e23745edd5859d0428c3372821056a4cfb43af243b1dc358516be76f221e529c8efb89dfc3e0100296b1b7b28cc379017f2744bd46ee66070
7
- data.tar.gz: '09dbb59441a7a07dc3d8550f33e7d64f11ec657d6ae8b708064ee597cb99b90a3738f87861141f23df64160c6a71a3b86d4b6aa7bf4d173997d4970df5923a7d'
6
+ metadata.gz: c79a14e0f8b02181a19268958c8784e306f66853e0e09f40ae630043a3f89b699aaaaee72622d06fff43df0eab9814908b5d692f748df0c7ff5f67d4cac1b460
7
+ data.tar.gz: 7b27b83b5592b3ec556e640d7d583983ec42615ac036c40a0f5b2a305616e3df846f292aae191952e312aeaf6d9e4be99ab84ed123c1853acbf055c515b9335f
@@ -7,7 +7,7 @@ ui.h1 'NattyUI: 8-bit Color Support'
7
7
  ui.space
8
8
 
9
9
  color = ->(i) { "[bg#{i = i.to_s(16).rjust(2, '0')}] #{i} " }
10
- ui.msg 'System Colors', glyph: :point do
10
+ ui.msg 'System Colors' do
11
11
  ui.puts <<~COLORS
12
12
  [#ff]#{0.upto(7).map(&color).join}
13
13
  [#00]#{8.upto(15).map(&color).join}
@@ -15,7 +15,7 @@ ui.msg 'System Colors', glyph: :point do
15
15
  COLORS
16
16
  end
17
17
 
18
- ui.msg '6x6x6 Color Cube', glyph: :point do
18
+ ui.msg '6x6x6 Color Cube' do
19
19
  [16, 22, 28].each do |b|
20
20
  b.step(b + 185, by: 36) do |i|
21
21
  left = i.upto(i + 5).map(&color).join
@@ -26,7 +26,7 @@ ui.msg '6x6x6 Color Cube', glyph: :point do
26
26
  end
27
27
  end
28
28
 
29
- ui.msg 'Grayscale', glyph: :point do
29
+ ui.msg 'Grayscale' do
30
30
  ui.puts <<~GRAYSCALE
31
31
  [#ff]#{232.upto(243).map(&color).join}
32
32
  [#ff]#{244.upto(255).map(&color).join}
data/examples/animate.rb CHANGED
@@ -13,32 +13,32 @@ TEXT = <<~TEXT.tr("\n", ' ')
13
13
  aliquip ex ea commodo [bold]consequat[/].
14
14
  TEXT
15
15
 
16
- ui.message 'Default Animation', glyph: :point do
16
+ ui.message 'Default Animation' do
17
17
  ui.animate TEXT, animation: :default
18
18
  end
19
19
  ui.space
20
20
 
21
- ui.message 'Shiny Rainbow', glyph: :point do
21
+ ui.message 'Shiny Rainbow' do
22
22
  ui.animate TEXT, animation: :rainbow
23
23
  end
24
24
  ui.space
25
25
 
26
- ui.message 'Binary Encoded', glyph: :point do
26
+ ui.message 'Binary Encoded' do
27
27
  ui.animate TEXT, animation: :binary, style: 'green', alt_style: :bright_green
28
28
  end
29
29
  ui.space
30
30
 
31
- ui.message 'Matrix Style', glyph: :point do
31
+ ui.message 'Matrix Style' do
32
32
  ui.animate TEXT, animation: :matrix
33
33
  end
34
34
  ui.space
35
35
 
36
- ui.message 'Typewriter Like', glyph: :point do
36
+ ui.message 'Typewriter Like' do
37
37
  ui.animate TEXT, animation: :type_writer
38
38
  end
39
39
  ui.space
40
40
 
41
- ui.message 'Default Styled', glyph: :point do
41
+ ui.message 'Default Styled' do
42
42
  ui.animate TEXT, style: 'bold bright_white on_red'
43
43
  end
44
44
  ui.space
data/examples/progress.rb CHANGED
@@ -7,8 +7,13 @@ ui.h1 'NattyUI: Progress Indication'
7
7
  ui.space
8
8
 
9
9
  # just simulate some work
10
- def something = sleep(0.5)
11
- def some = sleep(0.15)
10
+ if ENV.key?('NO_WAIT')
11
+ def something = nil
12
+ def some = nil
13
+ else
14
+ def something = sleep(0.5)
15
+ def some = sleep(0.15)
16
+ end
12
17
 
13
18
  ui.info 'Tasks are sections to visualize step by step processing.' do
14
19
  ui.task 'Assemble assets' do
@@ -25,7 +30,7 @@ ui.info 'Tasks are sections to visualize step by step processing.' do
25
30
 
26
31
  ui.task 'Compile files...' do
27
32
  %w[readme.txt main.css main.html sub.html].each do |name|
28
- ui.msg "Compile file [bright_yellow]./source/#{name}[/]..."
33
+ ui.msg "Compile file [bright_yellow]./source/#{name}[/]...", glyph: :dot
29
34
  something
30
35
  end
31
36
  ui.done 'Files compiled.'
@@ -12,9 +12,8 @@ module NattyUI
12
12
  35.times do |i|
13
13
  binary.each do |chars|
14
14
  rc = rand_char
15
- rc = @style + rc if rc.size == 1
16
15
  chars.pop
17
- chars.unshift(rc)
16
+ chars.unshift(rc.size == 1 ? @style + rc : rc)
18
17
  puts(stream, chars.join)
19
18
  end
20
19
  (stream << @top).flush
@@ -11,23 +11,19 @@ module NattyUI
11
11
  @lines.each do |line, size|
12
12
  time = 0.25 / size
13
13
  stream << style
14
+ line = Text.plain(line)
14
15
  if (num += 1).odd?
15
16
  stream << @pos1
16
- Text
17
- .plain(line)
18
- .each_char do |char|
19
- (stream << char).flush
20
- sleep(time)
21
- end
17
+ line.each_char do |char|
18
+ (stream << char).flush
19
+ sleep(time)
20
+ end
22
21
  else
23
22
  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
23
+ line.reverse.each_char do |char|
24
+ (stream << char << CURSOR_LEFT).flush
25
+ sleep(time)
26
+ end
31
27
  end
32
28
  stream << Ansi::RESET << @pos1 << line << Ansi::LINE_NEXT
33
29
  end
@@ -22,10 +22,6 @@ module NattyUI
22
22
  pos.pop(count).each { enc[_1] = line[_1] }
23
23
  pos.sample(pos.size / 3).each { enc[_1] = CHARS.sample }
24
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
25
  puts(stream, enc)
30
26
  end
31
27
  (stream << @top).flush
@@ -10,15 +10,15 @@ module NattyUI
10
10
  @style = attribute(:style, :default)
11
11
  @cursor_style = attribute(:cursor_style, 0x2e)
12
12
  @lines.each do |line, size|
13
+ line = Text.plain(line)
13
14
  if (num += 1).odd?
14
15
  stream << @pos1
15
- Text.plain(line).each_char { cursor(stream, _1).flush }
16
+ line.each_char { cursor(stream, _1).flush }
16
17
  else
17
18
  stream << Ansi.cursor_column(@prefix_width + size - 1)
18
- Text
19
- .plain(line)
20
- .reverse
21
- .each_char { (cursor(stream, _1) << CURSOR_2LEFT).flush }
19
+ line.reverse.each_char do |char|
20
+ (cursor(stream, char) << CURSOR_2LEFT).flush
21
+ end
22
22
  end
23
23
  stream << Ansi::RESET << @pos1 << line << Ansi::LINE_NEXT
24
24
  end
@@ -2,19 +2,19 @@
2
2
 
3
3
  module NattyUI
4
4
  module Animation
5
- def self.defined = @defined.keys
6
- def self.defined?(name) = @defined.key?(name)
7
- def self.define(**kwargs) = @defined.merge!(kwargs)
5
+ def self.names = @all.keys
8
6
 
9
7
  def self.[](name)
10
8
  return if name.nil?
11
- klass = @defined[name] || @defined[:default]
9
+ klass = @all[name] || @all[:default]
12
10
  return klass unless klass.is_a?(String)
13
11
  require(klass)
14
- klass = @defined[name] and return klass
12
+ klass = @all[name] and return klass
15
13
  raise(LoadError, "unknown animation - #{name}")
16
14
  end
17
15
 
16
+ def self.define(**kwargs) = @all.merge!(kwargs)
17
+
18
18
  class Base
19
19
  attr_reader :lines_written
20
20
 
@@ -58,7 +58,7 @@ module NattyUI
58
58
  private_constant :Base
59
59
 
60
60
  dir = __dir__
61
- @defined = {
61
+ @all = {
62
62
  binary: "#{dir}/animation/binary",
63
63
  default: "#{dir}/animation/default",
64
64
  matrix: "#{dir}/animation/matrix",
@@ -59,17 +59,17 @@ module NattyUI::Ansi
59
59
  REVEAL = self[:reveal].freeze
60
60
 
61
61
  # @!visibility private
62
- CLS = (CURSOR_HOME + SCREEN_ERASE).freeze
62
+ CLS = "#{CURSOR_HOME}#{SCREEN_ERASE}".freeze
63
63
 
64
64
  # @!visibility private
65
- CLL = (CURSOR_FIRST_COLUMN + LINE_ERASE).freeze
65
+ CLL = "#{CURSOR_FIRST_COLUMN}#{LINE_ERASE}".freeze
66
66
 
67
67
  # @!visibility private
68
68
  SCREEN_BLANK =
69
- (
70
- CURSOR_SAFE_POS + SCREEN_ALTERNATE + CURSOR_HOME + SCREEN_ERASE + RESET
71
- ).freeze
69
+ "#{CURSOR_SAFE_POS}#{
70
+ SCREEN_ALTERNATE
71
+ }#{CURSOR_HOME}#{SCREEN_ERASE}#{RESET}".freeze
72
72
 
73
73
  # @!visibility private
74
- SCREEN_UNBLANK = (RESET + SCREEN_ALTERNATE_OFF + CURSOR_RESTORE_POS).freeze
74
+ SCREEN_UNBLANK = "#{RESET}#{SCREEN_ALTERNATE_OFF}#{CURSOR_RESTORE_POS}".freeze
75
75
  end
@@ -85,11 +85,7 @@ module NattyUI
85
85
  (wrapper.stream << @msg << Ansi::CURSOR_HIDE).flush
86
86
  @msg = "#{Ansi::CLL}#{@msg}"
87
87
  return @msg << BAR_COLOR if @max_value
88
- spinner_color = Ansi[:bold, 220]
89
- @spinner =
90
- Enumerator.new do |y|
91
- spinner.each_char { y << "#{spinner_color}#{_1}" } while true
92
- end
88
+ @spinner = NattyUI::Spinner[spinner]
93
89
  end
94
90
 
95
91
  def redraw
@@ -162,7 +158,7 @@ module NattyUI
162
158
 
163
159
  def initialize(parent, title:, glyph:, **opts)
164
160
  color = COLORS[glyph] || COLORS[:default]
165
- glyph = NattyUI.glyph(glyph) || glyph
161
+ glyph = NattyUI::Glyph[glyph]
166
162
  prefix_width = Text.width(glyph) + 1
167
163
  parent.puts(
168
164
  title,
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NattyUI
4
+ # Helper class to select frame types.
5
+ # @see Features#framed
6
+ # @see Features#table
7
+ module Frame
8
+ # Define frame type used by default.
9
+ #
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 ? :rounded : value]
15
+ end
16
+
17
+ # Defined frame 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, String]
25
+ # defined type name (see {.names})
26
+ # or frame elements
27
+ # @return [String] frame definition
28
+ def self.[](name)
29
+ return @default if name == :default
30
+ if name.is_a?(Symbol)
31
+ ret = @all[name] and return ret
32
+ elsif name.is_a?(String)
33
+ return name if name.size == 11
34
+ return name * 11 if name.size == 1
35
+ end
36
+ raise(ArgumentError, "invalid frame type - #{name}")
37
+ end
38
+
39
+ @all = {
40
+ cols: ' │ │ ',
41
+ double: '╔╗╚╝║═╬╦╩╠╣',
42
+ heavy: '┏┓┗┛┃━╋┳┻┣┫',
43
+ rounded: '╭╮╰╯│─┼┬┴├┤',
44
+ rows: ' ── ',
45
+ semi: '╒╕╘╛│═╪╤╧╞╡',
46
+ semi2: '╓╖╙╜│─╫╥╨╟╢',
47
+ simple: '┌┐└┘│─┼┬┴├┤',
48
+ undecorated: ' '
49
+ }.compare_by_identity
50
+
51
+ self.default = nil
52
+ end
53
+ end
@@ -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
@@ -3,7 +3,10 @@
3
3
  require_relative '../natty-ui'
4
4
 
5
5
  module NattyUI
6
- Animation.defined?(:matrix)
7
- Text::EastAsianWidth[0]
6
+ Animation[nil]
7
+ Frame[:default]
8
+ Glyph[:default]
8
9
  KEY_MAP[0]
10
+ Spinner[:default]
11
+ Text.width("\u1100")
9
12
  end
@@ -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}"
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module NattyUI
4
4
  # The version number of the gem.
5
- VERSION = '0.11.2'
5
+ VERSION = '0.12.0'
6
6
  end
@@ -56,7 +56,7 @@ module NattyUI
56
56
  end
57
57
 
58
58
  def draw(question)
59
- glyph = NattyUI.glyph(:query)
59
+ glyph = NattyUI::Glyph[:query]
60
60
  @parent.print(
61
61
  question,
62
62
  prefix: "#{glyph} #{Ansi[255]}",
@@ -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 [:double, :heavy, :rounded, :semi, :simple] type frame type
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: :rounded, &block)
19
- _section(:Framed, args, type: NattyUI.frame(type), &block)
18
+ def framed(*args, type: :default, &block)
19
+ _section(:Framed, args, type: NattyUI::Frame[type], &block)
20
20
  end
21
21
  end
22
22
 
@@ -89,7 +89,7 @@ module NattyUI
89
89
  } #{Text.embellish(s)}"
90
90
  end
91
91
  else
92
- ->(s) { "#{glyph} #{Text.embellish(s)}" }
92
+ ->(s) { "#{Text.embellish(glyph)} #{Text.embellish(s)}" }
93
93
  end
94
94
  end
95
95
 
@@ -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 glyph/prefix used for the title
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.glyph(glyph) || glyph
97
+ glyph = NattyUI::Glyph[glyph]
98
98
  prefix_width = Text.width(glyph) + 1
99
99
  super(
100
100
  parent,
@@ -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 [:bar, :blink, :blocks, :braile, :circle, :colors, :pulse,
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: :pulse)
23
+ def progress(title, max_value: nil, spinner: :default)
26
24
  _element(:Progress, title, max_value, spinner)
27
25
  end
28
26
  end
@@ -42,26 +40,10 @@ module NattyUI
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)
43
+ draw(title, spinner)
46
44
  self
47
45
  end
48
46
 
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
47
  def draw(title, _spinner)
66
48
  (wrapper.stream << @parent.prefix << "➔ #{title} ").flush
67
49
  end
@@ -36,7 +36,7 @@ module NattyUI
36
36
 
37
37
  def draw(question)
38
38
  wrapper = @parent.wrapper
39
- glyph = NattyUI.glyph(:query)
39
+ glyph = NattyUI :Glyph[:query]
40
40
  @parent.print(
41
41
  question,
42
42
  prefix: "#{glyph} #{Ansi[255]}",
@@ -7,14 +7,11 @@ module NattyUI
7
7
  #
8
8
  # Table view of data.
9
9
  #
10
- # Defined values for `type` are
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: simple, expand: false)
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: :simple, expand: false)
62
- type = NattyUI.frame(type)
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)
data/lib/natty-ui.rb CHANGED
@@ -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
- GLYPH = {
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natty-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
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-02 00:00:00.000000000 Z
11
+ date: 2024-08-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
@@ -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