natty-ui 0.12.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +23 -24
  4. data/examples/24bit-colors.rb +4 -9
  5. data/examples/3bit-colors.rb +28 -8
  6. data/examples/8bit-colors.rb +18 -23
  7. data/examples/attributes.rb +30 -25
  8. data/examples/cols.rb +40 -0
  9. data/examples/elements.rb +31 -0
  10. data/examples/examples.rb +45 -0
  11. data/examples/illustration.rb +56 -54
  12. data/examples/ls.rb +16 -18
  13. data/examples/named-colors.rb +23 -0
  14. data/examples/sections.rb +29 -0
  15. data/examples/tables.rb +62 -0
  16. data/examples/tasks.rb +52 -0
  17. data/lib/natty-ui/attributes.rb +604 -0
  18. data/lib/natty-ui/choice.rb +56 -0
  19. data/lib/natty-ui/dumb_choice.rb +45 -0
  20. data/lib/natty-ui/element.rb +78 -0
  21. data/lib/natty-ui/features.rb +798 -0
  22. data/lib/natty-ui/framed.rb +51 -0
  23. data/lib/natty-ui/ls_renderer.rb +93 -0
  24. data/lib/natty-ui/progress.rb +187 -0
  25. data/lib/natty-ui/section.rb +69 -0
  26. data/lib/natty-ui/table.rb +241 -0
  27. data/lib/natty-ui/table_renderer.rb +147 -0
  28. data/lib/natty-ui/task.rb +44 -0
  29. data/lib/natty-ui/temporary.rb +38 -0
  30. data/lib/natty-ui/theme.rb +303 -0
  31. data/lib/natty-ui/utils.rb +79 -0
  32. data/lib/natty-ui/version.rb +1 -1
  33. data/lib/natty-ui/width_finder.rb +125 -0
  34. data/lib/natty-ui.rb +89 -147
  35. metadata +47 -56
  36. data/examples/animate.rb +0 -44
  37. data/examples/attributes_list.rb +0 -14
  38. data/examples/demo.rb +0 -53
  39. data/examples/message.rb +0 -32
  40. data/examples/progress.rb +0 -68
  41. data/examples/query.rb +0 -41
  42. data/examples/read_key.rb +0 -13
  43. data/examples/table.rb +0 -41
  44. data/lib/natty-ui/animation/binary.rb +0 -36
  45. data/lib/natty-ui/animation/default.rb +0 -38
  46. data/lib/natty-ui/animation/matrix.rb +0 -51
  47. data/lib/natty-ui/animation/rainbow.rb +0 -28
  48. data/lib/natty-ui/animation/type_writer.rb +0 -44
  49. data/lib/natty-ui/animation.rb +0 -69
  50. data/lib/natty-ui/ansi/constants.rb +0 -75
  51. data/lib/natty-ui/ansi.rb +0 -521
  52. data/lib/natty-ui/ansi_wrapper.rb +0 -199
  53. data/lib/natty-ui/frame.rb +0 -53
  54. data/lib/natty-ui/glyph.rb +0 -64
  55. data/lib/natty-ui/key_map.rb +0 -142
  56. data/lib/natty-ui/preload.rb +0 -12
  57. data/lib/natty-ui/spinner.rb +0 -120
  58. data/lib/natty-ui/text/east_asian_width.rb +0 -2529
  59. data/lib/natty-ui/text.rb +0 -203
  60. data/lib/natty-ui/wrapper/animate.rb +0 -17
  61. data/lib/natty-ui/wrapper/ask.rb +0 -78
  62. data/lib/natty-ui/wrapper/element.rb +0 -79
  63. data/lib/natty-ui/wrapper/features.rb +0 -21
  64. data/lib/natty-ui/wrapper/framed.rb +0 -45
  65. data/lib/natty-ui/wrapper/heading.rb +0 -60
  66. data/lib/natty-ui/wrapper/horizontal_rule.rb +0 -37
  67. data/lib/natty-ui/wrapper/list_in_columns.rb +0 -138
  68. data/lib/natty-ui/wrapper/message.rb +0 -109
  69. data/lib/natty-ui/wrapper/mixins.rb +0 -67
  70. data/lib/natty-ui/wrapper/progress.rb +0 -74
  71. data/lib/natty-ui/wrapper/query.rb +0 -89
  72. data/lib/natty-ui/wrapper/quote.rb +0 -25
  73. data/lib/natty-ui/wrapper/request.rb +0 -54
  74. data/lib/natty-ui/wrapper/section.rb +0 -118
  75. data/lib/natty-ui/wrapper/table.rb +0 -551
  76. data/lib/natty-ui/wrapper/task.rb +0 -55
  77. data/lib/natty-ui/wrapper.rb +0 -230
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NattyUI
4
+ class WidthFinder
5
+ # sum, columns =
6
+ def self.find(columns, max_width, saving_by_column = 1)
7
+ new(columns, max_width, saving_by_column).find
8
+ end
9
+
10
+ # width, padding_left, padding_right =
11
+ def self.adjust(width, padding_left, padding_right)
12
+ target = (width / 2) + 1
13
+ padding = padding_left + padding_right
14
+ return width - padding, padding_left, padding_right if padding < target
15
+ ep = ([padding_left, padding_right].max * 100.0) / padding
16
+ padding = width - target
17
+ [
18
+ target,
19
+ padding_left = ((padding * ep) / 100).to_i,
20
+ padding - padding_left
21
+ ]
22
+ end
23
+
24
+ def initialize(columns, max_width, saving_by_column)
25
+ @max_width = max_width
26
+ @saving_by_column = saving_by_column
27
+ columns, max = fit_max_width(columns, max_width, saving_by_column)
28
+ default = max_width / columns.size
29
+ @columns = columns.map { Column.create(_1, default, max) }
30
+ end
31
+
32
+ def find
33
+ sum = @columns.sum(&:value)
34
+ if sum < @max_width
35
+ sum = expand(sum)
36
+ elsif @max_width < sum
37
+ sum = shrink(sum)
38
+ end
39
+ [sum, @columns.map(&:value)]
40
+ end
41
+
42
+ private
43
+
44
+ def fit_max_width(columns, max_width, saving_by_column)
45
+ ret = max_width - columns.size + 1
46
+ return columns, ret if ret >= 1
47
+ saving_by_column += 1
48
+ columns = columns.dup
49
+ until ret >= 1
50
+ columns.pop
51
+ ret += saving_by_column
52
+ end
53
+ [columns, ret]
54
+ end
55
+
56
+ def expand(sum)
57
+ max_width = [@columns.sum(&:max_val), @max_width].min
58
+ expandables = @columns.find_all(&:expandable?)
59
+ while !expandables.empty? && sum < max_width
60
+ curr = expandables.min_by(&:value)
61
+ curr.value += 1
62
+ sum += 1
63
+ expandables.delete(curr) unless curr.expandable?
64
+ end
65
+ sum
66
+ end
67
+
68
+ def shrink(sum)
69
+ sum = shrink_elastic(sum)
70
+ return sum if sum <= @max_width
71
+ sum = shrink_harder(sum, @columns.find_all { _1.value > 1 && _1.fix? })
72
+ return sum if sum <= @max_width
73
+ sum = shrink_harder(sum, @columns.find_all { _1.value > 1 })
74
+ until sum <= @max_width
75
+ sum -= @columns.pop.value
76
+ sum -= @saving_by_column
77
+ end
78
+ sum
79
+ end
80
+
81
+ def shrink_elastic(sum)
82
+ shrinkables = @columns.find_all(&:shrinkable?)
83
+ while !shrinkables.empty? && @max_width < sum
84
+ curr = shrinkables.max_by(&:min_dist)
85
+ curr.value -= 1
86
+ sum -= 1
87
+ shrinkables.delete(curr) unless curr.shrinkable?
88
+ end
89
+ sum
90
+ end
91
+
92
+ def shrink_harder(sum, shrinkables)
93
+ while !shrinkables.empty? && @max_width < sum
94
+ curr = shrinkables.max_by(&:value)
95
+ curr.value -= 1
96
+ sum -= 1
97
+ shrinkables.delete(curr) if curr.value == 1
98
+ end
99
+ sum
100
+ end
101
+
102
+ Column =
103
+ Struct.new(:value, :min_val, :max_val) do
104
+ def self.create(value, default, max)
105
+ case value
106
+ when nil
107
+ new(default, 1, max)
108
+ when Range
109
+ min = (value.begin || 1).clamp(1, max)
110
+ max = (value.end || max).clamp(1, max)
111
+ new(min + ((max - min) / 2), min, max)
112
+ else
113
+ new(value = value.clamp(1, max), value, value)
114
+ end
115
+ end
116
+
117
+ def shrinkable? = min_val < value
118
+ def expandable? = value < max_val
119
+ def fix? = min_val == max_val
120
+ def min_dist = value - min_val
121
+ end
122
+ private_constant :Column
123
+ end
124
+ private_constant :WidthFinder
125
+ end
data/lib/natty-ui.rb CHANGED
@@ -1,179 +1,121 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'natty-ui/text'
4
- require_relative 'natty-ui/wrapper'
5
- require_relative 'natty-ui/ansi_wrapper'
3
+ require 'terminal'
4
+ require_relative 'natty-ui/features'
6
5
 
6
+ # This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
7
+ # natty user interface you like to have for your command line applications.
7
8
  #
8
- # Module to create beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
9
- # natty user interfaces for your CLI application.
10
- #
11
- # It creates {Wrapper} instances which can optionally support ANSI. The UI
12
- # consists of {Wrapper::Element}s and {Wrapper::Section}s for different
13
- # {Features}.
9
+ # The {NattyUI} ​ᓚᕠᗢ main module implements all {Features}.
14
10
  #
15
11
  module NattyUI
16
- class << self
17
- # @see .valid_in?
18
- # @return [IO] IO stream used to read input
19
- # @raise [TypeError] when a non-readable stream will be assigned
20
- attr_reader :in_stream
12
+ # Uses the ANSI tools of the Terminal.rb gem
13
+ Ansi = Terminal::Ansi
21
14
 
22
- # @return [Wrapper, Wrapper::Element] active UI element
23
- attr_reader :element
15
+ # Uses the Text tools of the Terminal.rb gem
16
+ Text = Terminal::Text
24
17
 
25
- # @param [IO] stream to read input
26
- def in_stream=(stream)
27
- unless valid_in?(stream)
28
- raise(TypeError, "readable IO required - #{stream.inspect}")
29
- end
30
- @in_stream = stream
31
- end
18
+ extend Features
32
19
 
33
- # Create a wrapper for given `stream`.
34
- #
35
- # @see .valid_out?
36
- #
37
- # @param [IO] stream valid out stream
38
- # @param [Boolean, :auto] ansi whether ANSI should be supported
39
- # or automatically selected
40
- # @return [Wrapper] wrapper for the given `stream`
41
- # @raise [TypeError] when `stream` is not a writable stream
42
- def new(stream, ansi: :auto)
43
- unless valid_out?(stream)
44
- raise(TypeError, "writable IO required - #{stream.inspect}")
45
- end
46
- wrapper_class(stream, ansi).__send__(:new, stream)
47
- end
48
-
49
- # Test if the given `stream` can be used for input
20
+ class << self
21
+ # Current used {Element} (or {NattyUI} as top element) supporting all
22
+ # {Features}.
50
23
  #
51
- # @param [IO] stream IO instance to test
52
- # @return [Boolean] whether if the given stream is usable
53
- def valid_in?(stream)
54
- (stream.is_a?(IO) && !stream.closed? && stream.stat.readable?) ||
55
- (stream.is_a?(StringIO) && !stream.closed_read?)
56
- rescue StandardError
57
- false
58
- end
24
+ # @return [Features]
25
+ # current element or itself
26
+ attr_reader :element
59
27
 
60
- # Test if the given `stream` can be used for output
28
+ # Supported input mode.
61
29
  #
62
- # @param [IO] stream IO instance to test
63
- # @return [Boolean] whether if the given stream is usable
64
- def valid_out?(stream)
65
- (stream.is_a?(IO) && !stream.closed? && stream.stat.writable?) ||
66
- (stream.is_a?(StringIO) && !stream.closed_write?)
67
- rescue StandardError
68
- false
30
+ # @attribute [r] input_mode
31
+ # @return [:default]
32
+ # when terminal uses ANSI
33
+ # @return [:dumb]
34
+ # when terminal does not support ANSI or interactive input
35
+ # @return [nil]
36
+ # when terminal inoput is not supported
37
+ def input_mode
38
+ case Terminal.input_mode
39
+ when :csi_u
40
+ :default
41
+ when :legacy
42
+ Terminal.ansi? ? :default : :dumb
43
+ when :dumb
44
+ :dumb
45
+ end
69
46
  end
70
47
 
71
- # Translate embedded attribute descriptions into ANSI control codes.
72
- #
73
- # @param [#to_s] str string to edit
74
- # @return [String] edited string
75
- def embellish(str) = Text.embellish(str)
76
-
77
- # Remove embedded attribute descriptions from given string.
48
+ # Terminal title.
78
49
  #
79
- # @param [#to_s] str string to edit
80
- # @param [:keep,:remove] ansi keep or remove ANSI codes too
81
- # @return [String] edited string
82
- def plain(str, ansi: :keep)
83
- ansi == :keep ? Text.plain_but_ansi(str) : Text.plain(str)
50
+ # @attribute [r] title
51
+ # @return [String]
52
+ # configured title
53
+ # @return [nil]
54
+ # when no title was set
55
+ def title = @title_stack.last
56
+
57
+ # @attribute [w] title
58
+ def title=(value)
59
+ if value
60
+ title = Ansi.plain(value).gsub(/\s+/, ' ')
61
+ _write(Ansi.tab_title(title)) if Terminal.ansi?
62
+ @title_stack << title
63
+ else
64
+ @title_stack.pop
65
+ last = @title_stack[-1]
66
+ _write(Ansi.tab_title(last)) if last && Terminal.ansi?
67
+ end
84
68
  end
85
69
 
86
- # Calculate monospace (display) width of given String.
87
- # It respects Unicode character sizes inclusive emoji.
88
- #
89
- # @param [#to_s] str string to calculate
90
- # @return [Integer] the display size
91
- def display_width(str) = Text.width(str)
70
+ # @!visibility private
71
+ attr_reader :lines_written
92
72
 
93
- # Convert given arguments into strings and yield each line.
94
- # Optionally limit the line width to given `max_width`.
95
- #
96
- # @overload each_line(..., max_width: nil)
97
- # @param [#to_s] ... objects converted to text lines
98
- # @param [#to_i, nil] max_width maximum line width
99
- # @yieldparam [String] line string line
100
- # @return [nil]
101
- # @overload each_line(..., max_width: nil)
102
- # @param [#to_s] ... objects converted to text lines
103
- # @param [#to_i, nil] max_width maximum line width
104
- # @return [Enumerator] line enumerator
105
- def each_line(*strs, max_width: nil, &block)
106
- return to_enum(__method__, *strs, max_width: max_width) unless block
107
- return Text.simple_each_line(strs, &block) unless max_width
108
- Text.each_line(strs, max_width, &block)
73
+ # @!visibility private
74
+ def back_to_line(number, erase: true)
75
+ return @lines_written if (c = @lines_written - number) <= 0
76
+ if Terminal.ansi?
77
+ _write(erase ? (Ansi::LINE_ERASE_PREV * c) : Ansi.cursor_prev_line(c))
78
+ end
79
+ @lines_written = number
109
80
  end
110
81
 
111
- # Read next raw key (keyboard input) from {in_stream}.
112
- #
113
- # The input will be returned as named key codes like "Ctrl+C" by default.
114
- # This can be changed by the `mode` parameter:
115
- #
116
- # - `:named` - name if available (fallback to raw)
117
- # - `:raw` - key code "as is"
118
- # - `:both` - key code and name if available
119
- #
120
- # @param [:named, :raw, :both] mode modfies the result
121
- # @return [String] read key
122
- def read_key(mode: :named)
123
- return @in_stream.getch unless defined?(@in_stream.getc)
124
- return @in_stream.getc unless defined?(@in_stream.raw)
125
- @in_stream.raw do |raw_stream|
126
- key = raw_stream.getc
127
- while (nc = raw_stream.read_nonblock(1, exception: false))
128
- nc.is_a?(String) ? key += nc : break
129
- end
130
- return key if mode == :raw
131
- return key, KEY_MAP[key]&.dup if mode == :both
132
- KEY_MAP[key]&.dup || key
82
+ # @!visibility private
83
+ def alternate_screen
84
+ return yield unless Terminal.ansi?
85
+ begin
86
+ _write(Ansi::SCREEN_ALTERNATE)
87
+ yield
88
+ ensure
89
+ _write(Ansi::SCREEN_ALTERNATE_OFF)
133
90
  end
134
- rescue Interrupt, SystemCallError
135
- nil
136
91
  end
137
92
 
138
93
  private
139
94
 
140
- def wrapper_class(stream, ansi)
141
- return AnsiWrapper if ansi == true
142
- return Wrapper if ansi == false || ENV.key?('NO_COLOR')
143
- return AnsiWrapper if ENV['ANSI'] == '1'
144
- return Wrapper if ENV['TERM'] == 'dumb'
145
- stream.tty? ? AnsiWrapper : Wrapper
146
- end
95
+ def _write(str) = Terminal.__send__(:_write, str)
147
96
 
148
- def stderr_is_stdout?
149
- STDOUT.tty? && STDERR.tty? && STDOUT.pos == STDERR.pos
150
- rescue IOError, SystemCallError
151
- false
97
+ def with(element)
98
+ Terminal.hide_cursor if @element == self
99
+ current, @element = @element, element
100
+ yield(element) if block_given?
101
+ ensure
102
+ element.done if element.respond_to?(:done)
103
+ Terminal.show_cursor if (@element = current) == self
152
104
  end
153
105
  end
154
106
 
155
- # Instance for standard output.
156
- StdOut = new(STDOUT)
157
-
158
- # Instance for standard error output.
159
- StdErr = stderr_is_stdout? ? StdOut : new(STDERR)
160
-
161
- dir = __dir__
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'))
165
- autoload(:KEY_MAP, File.join(dir, 'natty-ui', 'key_map'))
166
- autoload(:Spinner, File.join(dir, 'natty-ui', 'spinner'))
167
-
168
- private_constant :Animation, :KEY_MAP
169
-
170
- @element = StdOut
171
- self.in_stream = STDIN
107
+ @element = self
108
+ @lines_written = 0
109
+ @title_stack = []
172
110
  end
173
111
 
174
- # @!visibility private
175
- module Kernel
176
- # @see NattyUI.element
177
- # @return [NattyUI::Wrapper, NattyUI::Wrapper::Element] active UI element
178
- def ui = NattyUI.element unless defined?(ui)
112
+ unless defined?(Kernel.ui)
113
+ module Kernel
114
+ # @attribute [r] ui
115
+ # @return [NattyUI::Features] current used ui element
116
+ # @see NattyUI.element
117
+ def ui = NattyUI.element
118
+
119
+ # alias ​ᓚᕠᗢ ui
120
+ end
179
121
  end
metadata CHANGED
@@ -1,26 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natty-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-08-03 00:00:00.000000000 Z
12
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: terminal_rb
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.9.5
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.9.5
13
26
  description: |
14
- This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,
27
+ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
15
28
  natty user interface tool you like to have for your command line applications.
16
29
  It contains elegant, simple and beautiful features that enhance your
17
30
  command line interfaces functionally and aesthetically.
18
- email:
19
31
  executables: []
20
32
  extensions: []
21
33
  extra_rdoc_files:
22
- - README.md
23
34
  - LICENSE
35
+ - README.md
24
36
  files:
25
37
  - ".yardopts"
26
38
  - LICENSE
@@ -28,63 +40,43 @@ files:
28
40
  - examples/24bit-colors.rb
29
41
  - examples/3bit-colors.rb
30
42
  - examples/8bit-colors.rb
31
- - examples/animate.rb
32
43
  - examples/attributes.rb
33
- - examples/attributes_list.rb
34
- - examples/demo.rb
44
+ - examples/cols.rb
45
+ - examples/elements.rb
46
+ - examples/examples.rb
35
47
  - examples/illustration.rb
36
48
  - examples/ls.rb
37
- - examples/message.rb
38
- - examples/progress.rb
39
- - examples/query.rb
40
- - examples/read_key.rb
41
- - examples/table.rb
49
+ - examples/named-colors.rb
50
+ - examples/sections.rb
51
+ - examples/tables.rb
52
+ - examples/tasks.rb
42
53
  - lib/natty-ui.rb
43
- - lib/natty-ui/animation.rb
44
- - lib/natty-ui/animation/binary.rb
45
- - lib/natty-ui/animation/default.rb
46
- - lib/natty-ui/animation/matrix.rb
47
- - lib/natty-ui/animation/rainbow.rb
48
- - lib/natty-ui/animation/type_writer.rb
49
- - lib/natty-ui/ansi.rb
50
- - lib/natty-ui/ansi/constants.rb
51
- - lib/natty-ui/ansi_wrapper.rb
52
- - lib/natty-ui/frame.rb
53
- - lib/natty-ui/glyph.rb
54
- - lib/natty-ui/key_map.rb
55
- - lib/natty-ui/preload.rb
56
- - lib/natty-ui/spinner.rb
57
- - lib/natty-ui/text.rb
58
- - lib/natty-ui/text/east_asian_width.rb
54
+ - lib/natty-ui/attributes.rb
55
+ - lib/natty-ui/choice.rb
56
+ - lib/natty-ui/dumb_choice.rb
57
+ - lib/natty-ui/element.rb
58
+ - lib/natty-ui/features.rb
59
+ - lib/natty-ui/framed.rb
60
+ - lib/natty-ui/ls_renderer.rb
61
+ - lib/natty-ui/progress.rb
62
+ - lib/natty-ui/section.rb
63
+ - lib/natty-ui/table.rb
64
+ - lib/natty-ui/table_renderer.rb
65
+ - lib/natty-ui/task.rb
66
+ - lib/natty-ui/temporary.rb
67
+ - lib/natty-ui/theme.rb
68
+ - lib/natty-ui/utils.rb
59
69
  - lib/natty-ui/version.rb
60
- - lib/natty-ui/wrapper.rb
61
- - lib/natty-ui/wrapper/animate.rb
62
- - lib/natty-ui/wrapper/ask.rb
63
- - lib/natty-ui/wrapper/element.rb
64
- - lib/natty-ui/wrapper/features.rb
65
- - lib/natty-ui/wrapper/framed.rb
66
- - lib/natty-ui/wrapper/heading.rb
67
- - lib/natty-ui/wrapper/horizontal_rule.rb
68
- - lib/natty-ui/wrapper/list_in_columns.rb
69
- - lib/natty-ui/wrapper/message.rb
70
- - lib/natty-ui/wrapper/mixins.rb
71
- - lib/natty-ui/wrapper/progress.rb
72
- - lib/natty-ui/wrapper/query.rb
73
- - lib/natty-ui/wrapper/quote.rb
74
- - lib/natty-ui/wrapper/request.rb
75
- - lib/natty-ui/wrapper/section.rb
76
- - lib/natty-ui/wrapper/table.rb
77
- - lib/natty-ui/wrapper/task.rb
70
+ - lib/natty-ui/width_finder.rb
78
71
  - lib/natty_ui.rb
79
72
  homepage: https://github.com/mblumtritt/natty-ui
80
73
  licenses:
81
74
  - BSD-3-Clause
82
75
  metadata:
76
+ rubygems_mfa_required: 'true'
83
77
  source_code_uri: https://github.com/mblumtritt/natty-ui
84
78
  bug_tracker_uri: https://github.com/mblumtritt/natty-ui/issues
85
- documentation_uri: https://rubydoc.info/gems/natty-ui
86
- rubygems_mfa_required: 'true'
87
- post_install_message:
79
+ documentation_uri: https://rubydoc.info/gems/natty-ui/0.25.0/NattyUI/
88
80
  rdoc_options: []
89
81
  require_paths:
90
82
  - lib
@@ -99,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
91
  - !ruby/object:Gem::Version
100
92
  version: '0'
101
93
  requirements: []
102
- rubygems_version: 3.5.17
103
- signing_key:
94
+ rubygems_version: 3.6.9
104
95
  specification_version: 4
105
- summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely, natty
106
- user interface you like to have for your CLI.
96
+ summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
97
+ natty user interface you like to have for your CLI.
107
98
  test_files: []
data/examples/animate.rb DELETED
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/natty-ui'
4
-
5
- ui.space
6
- ui.h1 'NattyUI: Text Line Animation'
7
- ui.space
8
-
9
- TEXT = <<~TEXT.tr("\n", ' ')
10
- Lorem [yellow]ipsum[/] dolor sit amet, consectetur adipisicing elit, sed
11
- do eiusmod tempor incididunt ut labore et dolore [red]magna[/] aliqua.
12
- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
13
- aliquip ex ea commodo [bold]consequat[/].
14
- TEXT
15
-
16
- ui.message 'Default Animation' do
17
- ui.animate TEXT, animation: :default
18
- end
19
- ui.space
20
-
21
- ui.message 'Shiny Rainbow' do
22
- ui.animate TEXT, animation: :rainbow
23
- end
24
- ui.space
25
-
26
- ui.message 'Binary Encoded' do
27
- ui.animate TEXT, animation: :binary, style: 'green', alt_style: :bright_green
28
- end
29
- ui.space
30
-
31
- ui.message 'Matrix Style' do
32
- ui.animate TEXT, animation: :matrix
33
- end
34
- ui.space
35
-
36
- ui.message 'Typewriter Like' do
37
- ui.animate TEXT, animation: :type_writer
38
- end
39
- ui.space
40
-
41
- ui.message 'Default Styled' do
42
- ui.animate TEXT, style: 'bold bright_white on_red'
43
- end
44
- ui.space
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/natty-ui'
4
-
5
- ui.space
6
- ui.h2 'NattyUI: All Attribute and Defined Color Names'
7
- ui.space
8
-
9
- ui.ls(
10
- (NattyUI::Ansi.attribute_names + NattyUI::Ansi.color_names)
11
- .sort!
12
- .map! { |name| "[#{name}]#{name}[/]" }
13
- )
14
- ui.space
data/examples/demo.rb DELETED
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/natty-ui'
4
-
5
- ui.page do
6
- ui.space
7
- ui.h1 'NattyUI: Examples'
8
- ui.space
9
-
10
- ruby =
11
- ENV.fetch('RUBY') do
12
- require('rbconfig')
13
- File.join(
14
- RbConfig::CONFIG['bindir'],
15
- "#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}"
16
- ).sub(/.*\s.*/m, '"\&"')
17
- end
18
- run = ->(name) { system(ruby, File.join(__dir__, "#{name}.rb")) }
19
- run['illustration']
20
-
21
- ui.space
22
-
23
- choices = {}
24
- examples = {}
25
- {
26
- '1' => ['attributes', 'ANSI Attributes'],
27
- '2' => ['3bit-colors', '3/4-bit Color Support'],
28
- '3' => ['8bit-colors', '8-bit Color Support'],
29
- '4' => ['24bit-colors', '24-bit Color Support'],
30
- '5' => ['message', 'Message Types'],
31
- '6' => ['ls', 'Print In Columns'],
32
- '7' => %w[table Tables],
33
- '8' => ['animate', 'Text Line Animation'],
34
- '9' => ['progress', 'Progress Indication'],
35
- '0' => ['query', 'User Queries'],
36
- 'ESC' => [nil, 'Exit Demo']
37
- }.each_pair do |key, (name, descr)|
38
- examples[key] = name
39
- choices[key] = descr
40
- end
41
-
42
- loop do
43
- choice =
44
- ui.query(
45
- 'Which example do you like to run?',
46
- display: :compact,
47
- **choices
48
- ) or break
49
- example = examples[choice] or break
50
- ui.cls
51
- run[example]
52
- end
53
- end
data/examples/message.rb DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/natty-ui'
4
-
5
- ui.space
6
- ui.h1 'NattyUI: Message Types'
7
- ui.space
8
-
9
- TEXT = <<~TEXT.tr("\n", ' ')
10
- Lorem [yellow]ipsum[/fg] dolor sit amet, consectetur adipisicing elit, sed
11
- do eiusmod tempor incididunt ut labore et dolore [red]magna[/fg] aliqua.
12
- Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
13
- aliquip ex ea commodo [b]consequat[/b].
14
- TEXT
15
-
16
- ui.framed do
17
- ui.info 'Informative Message', TEXT
18
- ui.warning 'Warning Message' do
19
- ui.framed(type: :double) do
20
- ui.puts(
21
- '[red]>>>[/fg] [i]Important information maybe here[/i] [red]<<<',
22
- align: :center
23
- )
24
- end
25
- ui.puts('[italic f4]Ut enim ad minim veniam', align: :right)
26
- end
27
- ui.error 'Error Message', TEXT
28
- ui.failed 'Fail Message', TEXT
29
- ui.message '[italic #fad]Custom Message', TEXT, glyph: '💡'
30
- end
31
-
32
- ui.space