natty-ui 0.32.0 → 0.34.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/.yardopts +0 -1
- data/README.md +4 -0
- data/examples/hbars.rb +3 -3
- data/examples/info.rb +1 -1
- data/examples/key-codes.rb +18 -23
- data/examples/named-colors.rb +8 -6
- data/examples/sh.rb +17 -0
- data/examples/tasks.rb +4 -4
- data/examples/vbars.rb +4 -4
- data/lib/natty-ui/attributes.rb +7 -3
- data/lib/natty-ui/choice.rb +6 -5
- data/lib/natty-ui/dumb_choice.rb +6 -5
- data/lib/natty-ui/dumb_options.rb +6 -5
- data/lib/natty-ui/element.rb +28 -3
- data/lib/natty-ui/features.rb +59 -74
- data/lib/natty-ui/framed.rb +4 -4
- data/lib/natty-ui/ls_renderer.rb +2 -0
- data/lib/natty-ui/options.rb +3 -2
- data/lib/natty-ui/progress.rb +9 -7
- data/lib/natty-ui/section.rb +1 -1
- data/lib/natty-ui/shell_renderer.rb +9 -10
- data/lib/natty-ui/table_renderer.rb +2 -0
- data/lib/natty-ui/temporary.rb +3 -4
- data/lib/natty-ui/theme.rb +9 -2
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/width_finder.rb +2 -0
- data/lib/natty-ui.rb +10 -21
- data/natty-ui.gemspec +34 -0
- metadata +11 -12
- data/LICENSE +0 -28
- data/lib/natty-ui/shell_command.rb +0 -132
data/natty-ui.gemspec
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/natty-ui/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'natty-ui'
|
|
7
|
+
spec.version = NattyUI::VERSION
|
|
8
|
+
spec.summary = <<~SUMMARY.tr("\n", ' ')
|
|
9
|
+
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich,
|
|
10
|
+
lovely, natty user interface you like to have for your CLI.
|
|
11
|
+
SUMMARY
|
|
12
|
+
spec.description = <<~DESCRIPTION.tr("\n", ' ')
|
|
13
|
+
This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
|
|
14
|
+
natty user interface tool you like to have for your command line
|
|
15
|
+
applications. It contains elegant, simple and beautiful features that
|
|
16
|
+
enhance your command line interfaces functionally and aesthetically.
|
|
17
|
+
DESCRIPTION
|
|
18
|
+
|
|
19
|
+
spec.author = 'Mike Blumtritt'
|
|
20
|
+
spec.licenses = %w[MIT Ruby]
|
|
21
|
+
spec.homepage = 'https://codeberg.org/mblumtritt/natty-ui'
|
|
22
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
23
|
+
spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
|
|
24
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/natty-ui'
|
|
25
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
26
|
+
spec.metadata['yard.run'] = 'yard'
|
|
27
|
+
|
|
28
|
+
spec.required_ruby_version = '>= 3.0'
|
|
29
|
+
spec.add_dependency 'terminal_rb', '>= 0.17.0'
|
|
30
|
+
|
|
31
|
+
spec.files = Dir['lib/**/*.rb'] + Dir['examples/*.rb']
|
|
32
|
+
spec.files << 'natty-ui.gemspec' << '.yardopts'
|
|
33
|
+
spec.extra_rdoc_files = %w[README.md]
|
|
34
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: natty-ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.34.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Blumtritt
|
|
@@ -15,27 +15,24 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.17.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
26
|
-
description:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
command line interfaces functionally and aesthetically.
|
|
25
|
+
version: 0.17.0
|
|
26
|
+
description: 'This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich,
|
|
27
|
+
lovely, natty user interface tool you like to have for your command line applications.
|
|
28
|
+
It contains elegant, simple and beautiful features that enhance your command line
|
|
29
|
+
interfaces functionally and aesthetically. '
|
|
31
30
|
executables: []
|
|
32
31
|
extensions: []
|
|
33
32
|
extra_rdoc_files:
|
|
34
|
-
- LICENSE
|
|
35
33
|
- README.md
|
|
36
34
|
files:
|
|
37
35
|
- ".yardopts"
|
|
38
|
-
- LICENSE
|
|
39
36
|
- README.md
|
|
40
37
|
- examples/24bit-colors.rb
|
|
41
38
|
- examples/3bit-colors.rb
|
|
@@ -52,6 +49,7 @@ files:
|
|
|
52
49
|
- examples/named-colors.rb
|
|
53
50
|
- examples/options.rb
|
|
54
51
|
- examples/sections.rb
|
|
52
|
+
- examples/sh.rb
|
|
55
53
|
- examples/tables.rb
|
|
56
54
|
- examples/tasks.rb
|
|
57
55
|
- examples/themes.rb
|
|
@@ -69,7 +67,6 @@ files:
|
|
|
69
67
|
- lib/natty-ui/options.rb
|
|
70
68
|
- lib/natty-ui/progress.rb
|
|
71
69
|
- lib/natty-ui/section.rb
|
|
72
|
-
- lib/natty-ui/shell_command.rb
|
|
73
70
|
- lib/natty-ui/shell_renderer.rb
|
|
74
71
|
- lib/natty-ui/table.rb
|
|
75
72
|
- lib/natty-ui/table_renderer.rb
|
|
@@ -81,9 +78,11 @@ files:
|
|
|
81
78
|
- lib/natty-ui/version.rb
|
|
82
79
|
- lib/natty-ui/width_finder.rb
|
|
83
80
|
- lib/natty_ui.rb
|
|
81
|
+
- natty-ui.gemspec
|
|
84
82
|
homepage: https://codeberg.org/mblumtritt/natty-ui
|
|
85
83
|
licenses:
|
|
86
|
-
-
|
|
84
|
+
- MIT
|
|
85
|
+
- Ruby
|
|
87
86
|
metadata:
|
|
88
87
|
source_code_uri: https://codeberg.org/mblumtritt/natty-ui
|
|
89
88
|
bug_tracker_uri: https://codeberg.org/mblumtritt/natty-ui/issues
|
data/LICENSE
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
BSD 3-Clause License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017-2025, Mike Blumtritt. All rights reserved.
|
|
4
|
-
|
|
5
|
-
Redistribution and use in source and binary forms, with or without
|
|
6
|
-
modification, are permitted provided that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
-
list of conditions and the following disclaimer.
|
|
10
|
-
|
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
-
this list of conditions and the following disclaimer in the documentation
|
|
13
|
-
and/or other materials provided with the distribution.
|
|
14
|
-
|
|
15
|
-
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
-
contributors may be used to endorse or promote products derived from
|
|
17
|
-
this software without specific prior written permission.
|
|
18
|
-
|
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
module NattyUI
|
|
2
|
-
module ShellCommand
|
|
3
|
-
class << self
|
|
4
|
-
def call(*cmd, shell: false, input: nil, **options)
|
|
5
|
-
options = options.except(:in, :out, :err)
|
|
6
|
-
env = (cmd[0].is_a?(Hash) ? cmd.shift.dup : {}).freeze
|
|
7
|
-
if shell
|
|
8
|
-
cmd = cmd.map! { _escape(_1) }.join(' ')
|
|
9
|
-
elsif cmd.size == 1 && cmd[0].include?(' ')
|
|
10
|
-
cmd = cmd[0]
|
|
11
|
-
end
|
|
12
|
-
cmd.freeze
|
|
13
|
-
input = Input.for(input)
|
|
14
|
-
ret = nil
|
|
15
|
-
with_io(options, input) do |cio, out_r, err_r, in_w|
|
|
16
|
-
thread = Process.detach(Process.spawn(env, *cmd, options))
|
|
17
|
-
begin
|
|
18
|
-
cio.each(&:close)
|
|
19
|
-
read = [out_r, err_r]
|
|
20
|
-
write = [in_w] if in_w
|
|
21
|
-
while !read.empty? || write
|
|
22
|
-
rr, wr, = IO.select(read, write)
|
|
23
|
-
if rr.include?(out_r)
|
|
24
|
-
begin
|
|
25
|
-
yield(out_r.readline(chomp: true), :output)
|
|
26
|
-
rescue SystemCallError, IOError
|
|
27
|
-
read.delete(out_r)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
if rr.include?(err_r)
|
|
31
|
-
begin
|
|
32
|
-
yield(err_r.readline(chomp: true), :error)
|
|
33
|
-
rescue SystemCallError, IOError
|
|
34
|
-
read.delete(err_r)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
next if wr.empty?
|
|
38
|
-
begin
|
|
39
|
-
next if input.call(in_w)
|
|
40
|
-
rescue SystemCallError, IOError
|
|
41
|
-
# nop
|
|
42
|
-
end
|
|
43
|
-
in_w.close
|
|
44
|
-
write = nil
|
|
45
|
-
end
|
|
46
|
-
ensure
|
|
47
|
-
ret = thread.join.value
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
ret
|
|
51
|
-
rescue SystemCallError, IOError
|
|
52
|
-
nil
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def with_io(options, input)
|
|
58
|
-
IO.pipe do |out_r, out_w|
|
|
59
|
-
IO.pipe do |err_r, err_w|
|
|
60
|
-
cio = [options[:out] = out_w, options[:err] = err_w]
|
|
61
|
-
return yield(cio, out_r, err_r) unless input
|
|
62
|
-
IO.pipe do |in_r, in_w|
|
|
63
|
-
cio << (options[:in] = in_r)
|
|
64
|
-
in_w.sync = true
|
|
65
|
-
yield(cio, out_r, err_r, in_w)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def _escape(str)
|
|
72
|
-
return +"''" if str.empty?
|
|
73
|
-
str = str.dup
|
|
74
|
-
str.gsub!(%r{[^A-Za-z0-9_\-.,:+/@\n]}, "\\\\\\&")
|
|
75
|
-
str.gsub!("\n", "'\n'")
|
|
76
|
-
str
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
module Input
|
|
81
|
-
def self.for(obj)
|
|
82
|
-
return unless obj
|
|
83
|
-
return CopyWriter.new(obj) if obj.respond_to?(:readpartial)
|
|
84
|
-
return CopyWriter.new(obj.to_io) if obj.respond_to?(:to_io)
|
|
85
|
-
return ArrayWriter.new(obj) if obj.is_a?(Array)
|
|
86
|
-
return EnumerableWriter.new(obj) if obj.respond_to?(:each)
|
|
87
|
-
return ArrayWriter.new(obj.to_a) if obj.respond_to?(:to_a)
|
|
88
|
-
Writer.new(obj)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
class Writer
|
|
92
|
-
def call(io) = (io.write(_next) if @obj)
|
|
93
|
-
def initialize(obj) = (@obj = obj)
|
|
94
|
-
def _next = (_, @obj = @obj, nil).first
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
class CopyWriter < Writer
|
|
98
|
-
def call(io) = (IO.copy_stream(_next, io) if @obj)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
class ArrayWriter
|
|
102
|
-
def call(io) = io.write(@ry[@idx += 1] || return)
|
|
103
|
-
|
|
104
|
-
def initialize(ary)
|
|
105
|
-
@ry = ary
|
|
106
|
-
@idx = -1
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
class EnumerableWriter
|
|
111
|
-
def call(io)
|
|
112
|
-
io.write(@enum.next)
|
|
113
|
-
rescue StopIteration
|
|
114
|
-
false
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def initialize(enum)
|
|
118
|
-
@enum =
|
|
119
|
-
if enum.respond_to?(:enum_for)
|
|
120
|
-
enum.enum_for(:each)
|
|
121
|
-
else
|
|
122
|
-
Enumerator.new { |y| enum.each { y << _1 } }
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
private_constant :Input
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
private_constant :ShellCommand
|
|
132
|
-
end
|