natty-ui 0.12.1 → 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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +22 -26
- data/examples/24bit-colors.rb +4 -7
- data/examples/3bit-colors.rb +28 -6
- data/examples/8bit-colors.rb +18 -21
- data/examples/attributes.rb +30 -22
- data/examples/cols.rb +40 -0
- data/examples/elements.rb +31 -0
- data/examples/examples.rb +45 -0
- data/examples/illustration.rb +56 -54
- data/examples/ls.rb +16 -16
- data/examples/named-colors.rb +23 -0
- data/examples/sections.rb +29 -0
- data/examples/tables.rb +62 -0
- data/examples/tasks.rb +52 -0
- data/lib/natty-ui/attributes.rb +604 -0
- data/lib/natty-ui/choice.rb +56 -0
- data/lib/natty-ui/dumb_choice.rb +45 -0
- data/lib/natty-ui/element.rb +78 -0
- data/lib/natty-ui/features.rb +798 -0
- data/lib/natty-ui/framed.rb +51 -0
- data/lib/natty-ui/ls_renderer.rb +93 -0
- data/lib/natty-ui/progress.rb +187 -0
- data/lib/natty-ui/section.rb +69 -0
- data/lib/natty-ui/table.rb +241 -0
- data/lib/natty-ui/table_renderer.rb +147 -0
- data/lib/natty-ui/task.rb +44 -0
- data/lib/natty-ui/temporary.rb +38 -0
- data/lib/natty-ui/theme.rb +303 -0
- data/lib/natty-ui/utils.rb +79 -0
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/width_finder.rb +125 -0
- data/lib/natty-ui.rb +89 -147
- metadata +44 -53
- data/examples/animate.rb +0 -42
- data/examples/attributes_list.rb +0 -12
- data/examples/demo.rb +0 -51
- data/examples/message.rb +0 -30
- data/examples/progress.rb +0 -66
- data/examples/query.rb +0 -39
- data/examples/read_key.rb +0 -13
- data/examples/table.rb +0 -39
- data/lib/natty-ui/animation/binary.rb +0 -36
- data/lib/natty-ui/animation/default.rb +0 -38
- data/lib/natty-ui/animation/matrix.rb +0 -51
- data/lib/natty-ui/animation/rainbow.rb +0 -28
- data/lib/natty-ui/animation/type_writer.rb +0 -44
- data/lib/natty-ui/animation.rb +0 -69
- data/lib/natty-ui/ansi/constants.rb +0 -75
- data/lib/natty-ui/ansi.rb +0 -530
- data/lib/natty-ui/ansi_wrapper.rb +0 -232
- data/lib/natty-ui/frame.rb +0 -53
- data/lib/natty-ui/glyph.rb +0 -64
- data/lib/natty-ui/key_map.rb +0 -142
- data/lib/natty-ui/preload.rb +0 -12
- data/lib/natty-ui/spinner.rb +0 -120
- data/lib/natty-ui/text/east_asian_width.rb +0 -2529
- data/lib/natty-ui/text.rb +0 -203
- data/lib/natty-ui/wrapper/animate.rb +0 -17
- data/lib/natty-ui/wrapper/ask.rb +0 -78
- data/lib/natty-ui/wrapper/element.rb +0 -79
- data/lib/natty-ui/wrapper/features.rb +0 -21
- data/lib/natty-ui/wrapper/framed.rb +0 -45
- data/lib/natty-ui/wrapper/heading.rb +0 -64
- data/lib/natty-ui/wrapper/horizontal_rule.rb +0 -37
- data/lib/natty-ui/wrapper/list_in_columns.rb +0 -138
- data/lib/natty-ui/wrapper/message.rb +0 -109
- data/lib/natty-ui/wrapper/mixins.rb +0 -75
- data/lib/natty-ui/wrapper/progress.rb +0 -63
- data/lib/natty-ui/wrapper/query.rb +0 -89
- data/lib/natty-ui/wrapper/quote.rb +0 -25
- data/lib/natty-ui/wrapper/request.rb +0 -54
- data/lib/natty-ui/wrapper/section.rb +0 -118
- data/lib/natty-ui/wrapper/table.rb +0 -550
- data/lib/natty-ui/wrapper/task.rb +0 -55
- data/lib/natty-ui/wrapper.rb +0 -239
@@ -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
|
-
|
4
|
-
require_relative 'natty-ui/
|
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
|
-
#
|
9
|
-
# lovely, 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
|
-
|
17
|
-
|
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
|
-
|
23
|
-
|
15
|
+
# Uses the Text tools of the Terminal.rb gem
|
16
|
+
Text = Terminal::Text
|
24
17
|
|
25
|
-
|
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
|
-
|
34
|
-
#
|
35
|
-
#
|
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
|
-
# @
|
52
|
-
#
|
53
|
-
|
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
|
-
#
|
28
|
+
# Supported input mode.
|
61
29
|
#
|
62
|
-
# @
|
63
|
-
# @return [
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
#
|
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
|
-
# @
|
80
|
-
# @
|
81
|
-
#
|
82
|
-
|
83
|
-
|
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
|
-
#
|
87
|
-
|
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
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
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
|
149
|
-
|
150
|
-
|
151
|
-
|
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
|
-
|
156
|
-
|
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
|
-
|
175
|
-
module Kernel
|
176
|
-
|
177
|
-
|
178
|
-
|
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.
|
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:
|
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
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/
|
34
|
-
- examples/
|
44
|
+
- examples/cols.rb
|
45
|
+
- examples/elements.rb
|
46
|
+
- examples/examples.rb
|
35
47
|
- examples/illustration.rb
|
36
48
|
- examples/ls.rb
|
37
|
-
- examples/
|
38
|
-
- examples/
|
39
|
-
- examples/
|
40
|
-
- examples/
|
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/
|
44
|
-
- lib/natty-ui/
|
45
|
-
- lib/natty-ui/
|
46
|
-
- lib/natty-ui/
|
47
|
-
- lib/natty-ui/
|
48
|
-
- lib/natty-ui/
|
49
|
-
- lib/natty-ui/
|
50
|
-
- lib/natty-ui/
|
51
|
-
- lib/natty-ui/
|
52
|
-
- lib/natty-ui/
|
53
|
-
- lib/natty-ui/
|
54
|
-
- lib/natty-ui/
|
55
|
-
- lib/natty-ui/
|
56
|
-
- lib/natty-ui/
|
57
|
-
- lib/natty-ui/
|
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/
|
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,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
91
|
- !ruby/object:Gem::Version
|
100
92
|
version: '0'
|
101
93
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
103
|
-
signing_key:
|
94
|
+
rubygems_version: 3.6.9
|
104
95
|
specification_version: 4
|
105
96
|
summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
|
106
97
|
natty user interface you like to have for your CLI.
|
data/examples/animate.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/natty-ui'
|
4
|
-
|
5
|
-
ui.h1 'NattyUI: Text Line Animation', space: 2
|
6
|
-
|
7
|
-
TEXT = <<~TEXT.tr("\n", ' ')
|
8
|
-
Lorem [yellow]ipsum[/] dolor sit amet, consectetur adipisicing elit, sed
|
9
|
-
do eiusmod tempor incididunt ut labore et dolore [red]magna[/] aliqua.
|
10
|
-
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
11
|
-
aliquip ex ea commodo [bold]consequat[/].
|
12
|
-
TEXT
|
13
|
-
|
14
|
-
ui.message 'Default Animation' do
|
15
|
-
ui.animate TEXT, animation: :default
|
16
|
-
end
|
17
|
-
ui.space
|
18
|
-
|
19
|
-
ui.message 'Shiny Rainbow' do
|
20
|
-
ui.animate TEXT, animation: :rainbow
|
21
|
-
end
|
22
|
-
ui.space
|
23
|
-
|
24
|
-
ui.message 'Binary Encoded' do
|
25
|
-
ui.animate TEXT, animation: :binary, style: 'green', alt_style: :bright_green
|
26
|
-
end
|
27
|
-
ui.space
|
28
|
-
|
29
|
-
ui.message 'Matrix Style' do
|
30
|
-
ui.animate TEXT, animation: :matrix
|
31
|
-
end
|
32
|
-
ui.space
|
33
|
-
|
34
|
-
ui.message 'Typewriter Like' do
|
35
|
-
ui.animate TEXT, animation: :type_writer
|
36
|
-
end
|
37
|
-
ui.space
|
38
|
-
|
39
|
-
ui.message 'Default Styled' do
|
40
|
-
ui.animate TEXT, style: 'bold bright_white on_red'
|
41
|
-
end
|
42
|
-
ui.space
|
data/examples/attributes_list.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/natty-ui'
|
4
|
-
|
5
|
-
ui.h2 'NattyUI: All Attribute and Defined Color Names', space: 2
|
6
|
-
|
7
|
-
ui.ls(
|
8
|
-
(NattyUI::Ansi.attribute_names + NattyUI::Ansi.color_names)
|
9
|
-
.sort!
|
10
|
-
.map! { |name| "[#{name}]#{name}" }
|
11
|
-
)
|
12
|
-
ui.space
|
data/examples/demo.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/natty-ui'
|
4
|
-
|
5
|
-
ui.page do
|
6
|
-
ui.h1 'NattyUI: Examples', space: 2
|
7
|
-
|
8
|
-
ruby =
|
9
|
-
ENV.fetch('RUBY') do
|
10
|
-
require('rbconfig')
|
11
|
-
File.join(
|
12
|
-
RbConfig::CONFIG['bindir'],
|
13
|
-
"#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}"
|
14
|
-
).sub(/.*\s.*/m, '"\&"')
|
15
|
-
end
|
16
|
-
run = ->(name) { system(ruby, File.join(__dir__, "#{name}.rb")) }
|
17
|
-
run['illustration']
|
18
|
-
|
19
|
-
ui.space
|
20
|
-
|
21
|
-
choices = {}
|
22
|
-
examples = {}
|
23
|
-
{
|
24
|
-
'1' => ['attributes', 'ANSI Attributes'],
|
25
|
-
'2' => ['3bit-colors', '3/4-bit Color Support'],
|
26
|
-
'3' => ['8bit-colors', '8-bit Color Support'],
|
27
|
-
'4' => ['24bit-colors', '24-bit Color Support'],
|
28
|
-
'5' => ['message', 'Message Types'],
|
29
|
-
'6' => ['ls', 'Print In Columns'],
|
30
|
-
'7' => %w[table Tables],
|
31
|
-
'8' => ['animate', 'Text Line Animation'],
|
32
|
-
'9' => ['progress', 'Progress Indication'],
|
33
|
-
'0' => ['query', 'User Queries'],
|
34
|
-
'ESC' => [nil, 'Exit Demo']
|
35
|
-
}.each_pair do |key, (name, descr)|
|
36
|
-
examples[key] = name
|
37
|
-
choices[key] = descr
|
38
|
-
end
|
39
|
-
|
40
|
-
loop do
|
41
|
-
choice =
|
42
|
-
ui.query(
|
43
|
-
'Which example do you like to run?',
|
44
|
-
display: :compact,
|
45
|
-
**choices
|
46
|
-
) or break
|
47
|
-
example = examples[choice] or break
|
48
|
-
ui.cls
|
49
|
-
run[example]
|
50
|
-
end
|
51
|
-
end
|
data/examples/message.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/natty-ui'
|
4
|
-
|
5
|
-
ui.h1 'NattyUI: Message Types', space: 2
|
6
|
-
|
7
|
-
TEXT = <<~TEXT.tr("\n", ' ')
|
8
|
-
Lorem [yellow]ipsum[/fg] dolor sit amet, consectetur adipisicing elit, sed
|
9
|
-
do eiusmod tempor incididunt ut labore et dolore [red]magna[/fg] aliqua.
|
10
|
-
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
11
|
-
aliquip ex ea commodo [b]consequat[/b].
|
12
|
-
TEXT
|
13
|
-
|
14
|
-
ui.framed do
|
15
|
-
ui.info 'Informative Message', TEXT
|
16
|
-
ui.warning 'Warning Message' do
|
17
|
-
ui.framed(type: :double) do
|
18
|
-
ui.puts(
|
19
|
-
'[red]>>>[/fg] [i]Important information maybe here[/i] [red]<<<',
|
20
|
-
align: :center
|
21
|
-
)
|
22
|
-
end
|
23
|
-
ui.puts('[italic f4]Ut enim ad minim veniam', align: :right)
|
24
|
-
end
|
25
|
-
ui.error 'Error Message', TEXT
|
26
|
-
ui.failed 'Fail Message', TEXT
|
27
|
-
ui.message '[italic #fad]Custom Message', TEXT, glyph: '💡'
|
28
|
-
end
|
29
|
-
|
30
|
-
ui.space
|