bogo-ui 0.1.26 → 0.4.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/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +10 -14
- data/LICENSE +2 -2
- data/README.md +7 -7
- data/bogo-ui.gemspec +6 -4
- data/lib/bogo/ui/table.rb +153 -0
- data/lib/{bogo-ui → bogo/ui}/version.rb +1 -1
- data/lib/bogo/ui.rb +203 -0
- data/lib/bogo-ui/table.rb +1 -153
- data/lib/bogo-ui/ui.rb +1 -200
- data/lib/bogo-ui.rb +1 -3
- metadata +46 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bbf5d13fee181921324f6063ddbbf3b74757d005871c50279301f9746e7c16e
|
4
|
+
data.tar.gz: 987c4c10f1dde5373fce212588364a0e895629832e96fe8191928ad922c1d3aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceccd08e72c8e7087c3f023a52543d37eec3a57f9dd0f30d64cd1a73774fe67dd9bf951d988fc15838aa9a38bc3ec19c05522e8401f575d5cfa88217d1166af1
|
7
|
+
data.tar.gz: cca83360cd8808160a4f6226597f2daa9e0f16318f429fec1cac8372461905f4f2e5ec1d8040d18385acc6922d39019086d8951029fc5708cd5e20bc3097b9c9
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
# Contributing
|
2
2
|
|
3
|
-
##
|
3
|
+
## Fixes
|
4
4
|
|
5
|
-
|
5
|
+
Have a fix to some bug you want to submit? Well you're
|
6
|
+
awesome. Please just include a description of the bug
|
7
|
+
(or link to originating issue) and test coverage on the
|
8
|
+
modifications.
|
6
9
|
|
7
|
-
|
10
|
+
## New Features
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
## Pull requests
|
14
|
-
|
15
|
-
* https://github.com/spox/bogo-ui/pulls
|
16
|
-
|
17
|
-
Please base all pull requests of the `develop` branch. Merges to
|
18
|
-
`master` only occur through the `develop` branch. Pull requests
|
19
|
-
based on `master` will likely be cherry picked.
|
12
|
+
Have a new feature you want to add? Well you're awesome
|
13
|
+
too! It may be a good idea to submit an issue first to
|
14
|
+
describe the desired feature and get any feedback. Please
|
15
|
+
be sure to include tests.
|
20
16
|
|
21
17
|
## Issues
|
22
18
|
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright 2022 Chris Roberts
|
2
2
|
|
3
3
|
Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
you may not use this file except in compliance with the License.
|
@@ -10,4 +10,4 @@
|
|
10
10
|
distributed under the License is distributed on an "AS IS" BASIS,
|
11
11
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
See the License for the specific language governing permissions and
|
13
|
-
limitations under the License.
|
13
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -7,10 +7,10 @@ Simple CLI output helpers.
|
|
7
7
|
Output formatted information to the CLI.
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
require 'bogo
|
10
|
+
require 'bogo/ui'
|
11
11
|
|
12
12
|
ui = Bogo::Ui.new(
|
13
|
-
:
|
13
|
+
app_name: 'TestApp'
|
14
14
|
)
|
15
15
|
|
16
16
|
ui.info 'This is information'
|
@@ -29,9 +29,9 @@ This is a table helper. Under the hood it uses the Command Line Reporter
|
|
29
29
|
with a few modifications. Direct usage:
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
require 'bogo
|
32
|
+
require 'bogo/ui'
|
33
33
|
|
34
|
-
ui = Bogo::Ui.new(:
|
34
|
+
ui = Bogo::Ui.new(app_name: 'TestApp')
|
35
35
|
Bogo::Ui::Table.new(ui) do
|
36
36
|
table do
|
37
37
|
row do
|
@@ -51,9 +51,9 @@ for when polling for updates and wanting to keep the existing table
|
|
51
51
|
structure:
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
require 'bogo
|
54
|
+
require 'bogo/ui'
|
55
55
|
|
56
|
-
ui = Bogo::Ui.new(:
|
56
|
+
ui = Bogo::Ui.new(app_name: 'TestApp')
|
57
57
|
tbl = Bogo::Ui::Table.new(ui) do
|
58
58
|
table do
|
59
59
|
row do
|
@@ -81,4 +81,4 @@ tbl.display
|
|
81
81
|
|
82
82
|
## Info
|
83
83
|
* Repository: https://github.com/spox/bogo-ui
|
84
|
-
* Command Line Reporter: https://github.com/wbailey/command_line_reporter
|
84
|
+
* Command Line Reporter: https://github.com/wbailey/command_line_reporter
|
data/bogo-ui.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
|
2
|
-
require 'bogo
|
2
|
+
require 'bogo/ui/version'
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'bogo-ui'
|
5
5
|
s.version = Bogo::Ui::VERSION.version
|
@@ -10,8 +10,10 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = 'UI Helper libraries'
|
11
11
|
s.require_path = 'lib'
|
12
12
|
s.license = 'Apache 2.0'
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
13
|
+
s.add_runtime_dependency 'bogo', '~> 0.2'
|
14
|
+
s.add_runtime_dependency 'command_line_reporter', '~> 4.0'
|
15
|
+
s.add_runtime_dependency 'paint', '~> 2.2'
|
16
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
17
|
+
s.add_development_dependency 'minitest', '~> 5.5'
|
16
18
|
s.files = Dir['lib/**/*'] + %w(bogo-ui.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
|
17
19
|
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'command_line_reporter'
|
2
|
+
|
3
|
+
module Bogo
|
4
|
+
|
5
|
+
class Ui
|
6
|
+
# Table output helper
|
7
|
+
class Table
|
8
|
+
|
9
|
+
include CommandLineReporter
|
10
|
+
|
11
|
+
# @return [Bogo::Ui]
|
12
|
+
attr_reader :ui
|
13
|
+
# @return [Array<Proc>]
|
14
|
+
attr_reader :table
|
15
|
+
# @return [Object]
|
16
|
+
attr_reader :proxy_to
|
17
|
+
|
18
|
+
# Create a new instance
|
19
|
+
#
|
20
|
+
# @param ui [Bogo::Ui]
|
21
|
+
# @yield table content
|
22
|
+
# @return [self]
|
23
|
+
def initialize(ui, inst=nil, &block)
|
24
|
+
@proxy_to = inst
|
25
|
+
@ui = ui
|
26
|
+
@base = block
|
27
|
+
@content = []
|
28
|
+
@printed_lines = []
|
29
|
+
end
|
30
|
+
|
31
|
+
# If proxy instance is provided, forward if possible
|
32
|
+
def method_missing(m_name, *args, &block)
|
33
|
+
if(proxy_to && proxy_to.respond_to?(m_name, true))
|
34
|
+
proxy_to.send(m_name, *args, &block)
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Update the table content
|
41
|
+
#
|
42
|
+
# @yield table content
|
43
|
+
# @return [self]
|
44
|
+
def update(&block)
|
45
|
+
@content << block
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
undef_method :table # Remove imported table method before defining
|
50
|
+
# Override to provide buffered support
|
51
|
+
#
|
52
|
+
# @param options [Hash]
|
53
|
+
# @return [self]
|
54
|
+
def table(options={})
|
55
|
+
@table = BufferedTable.new(options)
|
56
|
+
yield
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
# Override to provide buffered support
|
61
|
+
#
|
62
|
+
# @param options [Hash]
|
63
|
+
# @return [self]
|
64
|
+
def row(options={})
|
65
|
+
options[:encoding] ||= @table.encoding
|
66
|
+
@row = BufferedRow.new(options.merge(:buffer => @table.buffer))
|
67
|
+
yield
|
68
|
+
@table.add(@row)
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
# Output table to defined UI
|
73
|
+
#
|
74
|
+
# @return [self]
|
75
|
+
# @note can be called multiple times to print table updates
|
76
|
+
def display
|
77
|
+
# init the table
|
78
|
+
instance_exec(&@base)
|
79
|
+
# load the table
|
80
|
+
@content.each do |tblock|
|
81
|
+
instance_exec(&tblock)
|
82
|
+
end
|
83
|
+
@table.output
|
84
|
+
@table.buffer.rewind
|
85
|
+
output = @table.buffer.read.split("\n")
|
86
|
+
output = output.find_all do |line|
|
87
|
+
!@printed_lines.include?(
|
88
|
+
Digest::SHA256.hexdigest(line.gsub(/\s/, ''))
|
89
|
+
)
|
90
|
+
end
|
91
|
+
@printed_lines.concat(
|
92
|
+
output.map{|l| Digest::SHA256.hexdigest(l.gsub(/\s/, '')) }
|
93
|
+
)
|
94
|
+
ui.puts output.join("\n") unless output.empty?
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
# Wrapper class to get desired buffering
|
99
|
+
class BufferedTable < CommandLineReporter::Table
|
100
|
+
|
101
|
+
# @return [StringIO]
|
102
|
+
attr_reader :buffer
|
103
|
+
|
104
|
+
# Create new instance and init buffer
|
105
|
+
#
|
106
|
+
# @return [self]
|
107
|
+
def initialize(*args)
|
108
|
+
@buffer = StringIO.new
|
109
|
+
super
|
110
|
+
end
|
111
|
+
|
112
|
+
# buffered puts
|
113
|
+
def puts(string)
|
114
|
+
buffer.puts(string)
|
115
|
+
end
|
116
|
+
|
117
|
+
# buffered print
|
118
|
+
def print(string)
|
119
|
+
buffer.print(string)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
# Wrapper class to get desired buffering
|
125
|
+
class BufferedRow < CommandLineReporter::Row
|
126
|
+
|
127
|
+
# @return [StringIO]
|
128
|
+
attr_reader :buffer
|
129
|
+
|
130
|
+
# Create new instance and init buffer
|
131
|
+
#
|
132
|
+
# @return [self]
|
133
|
+
def initialize(options={})
|
134
|
+
@buffer = options.delete(:buffer)
|
135
|
+
super
|
136
|
+
end
|
137
|
+
|
138
|
+
# buffered puts
|
139
|
+
def puts(string)
|
140
|
+
buffer.puts(string)
|
141
|
+
end
|
142
|
+
|
143
|
+
# buffered print
|
144
|
+
def print(string)
|
145
|
+
buffer.print(string)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
data/lib/bogo/ui.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'bogo'
|
2
|
+
require 'paint'
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
module Bogo
|
6
|
+
# CLI UI helper
|
7
|
+
class Ui
|
8
|
+
autoload :Table, 'bogo/ui/table'
|
9
|
+
autoload :VERSION, 'bogo/ui/version'
|
10
|
+
|
11
|
+
# Custom exception type when confirmation is
|
12
|
+
# declined by the user
|
13
|
+
class ConfirmationDeclined < StandardError; end
|
14
|
+
|
15
|
+
# @return [Truthy, Falsey]
|
16
|
+
attr_accessor :colorize
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :application_name
|
19
|
+
# @return [IO]
|
20
|
+
attr_reader :output_to
|
21
|
+
# @return [Truthy, Falsey]
|
22
|
+
attr_accessor :auto_confirm
|
23
|
+
# @return [Truthy, Falsey]
|
24
|
+
attr_accessor :auto_default
|
25
|
+
# @return [Smash] options
|
26
|
+
attr_reader :options
|
27
|
+
|
28
|
+
# Build new UI instance
|
29
|
+
#
|
30
|
+
# @param args [Hash]
|
31
|
+
# @option args [String] :app_name name of application
|
32
|
+
# @option args [TrueClass, FalseClass] :colors enable/disable colors
|
33
|
+
# @option args [IO] :output_to IO to write
|
34
|
+
# @return [self]
|
35
|
+
def initialize(args={})
|
36
|
+
@application_name = args.fetch(:app_name, 'App')
|
37
|
+
@colorize = args.fetch(:colors, true)
|
38
|
+
@output_to = args.fetch(:output_to, $stdout)
|
39
|
+
@auto_confirm = args.fetch(:auto_confirm, args.fetch(:yes, false))
|
40
|
+
@auto_default = args.fetch(:auto_default, args.fetch(:defaults, false))
|
41
|
+
@options = args.to_smash
|
42
|
+
end
|
43
|
+
|
44
|
+
# Output directly
|
45
|
+
#
|
46
|
+
# @param string [String]
|
47
|
+
# @return [String]
|
48
|
+
def puts(string='')
|
49
|
+
output_to.puts string
|
50
|
+
string
|
51
|
+
end
|
52
|
+
|
53
|
+
# Output directly
|
54
|
+
#
|
55
|
+
# @param string [String]
|
56
|
+
# @return [String]
|
57
|
+
def print(string='')
|
58
|
+
output_to.print string
|
59
|
+
string
|
60
|
+
end
|
61
|
+
|
62
|
+
# Output information string
|
63
|
+
#
|
64
|
+
# @param string [String]
|
65
|
+
# @return [String]
|
66
|
+
def info(string, *args)
|
67
|
+
output_method = args.include?(:nonewline) ? :print : :puts
|
68
|
+
o_color = args.include?(:verbose) ? :yellow : :green
|
69
|
+
self.send(output_method, "#{color("[#{application_name}]:", o_color)} #{string}")
|
70
|
+
string
|
71
|
+
end
|
72
|
+
|
73
|
+
# Format warning string
|
74
|
+
#
|
75
|
+
# @param string [String]
|
76
|
+
# @return [String]
|
77
|
+
def warn(string, *args)
|
78
|
+
output_method = args.include?(:nonewline) ? :print : :puts
|
79
|
+
self.send(output_method, "#{color('[WARN]:', :yellow, :bold)} #{string}")
|
80
|
+
string
|
81
|
+
end
|
82
|
+
|
83
|
+
# Format error string
|
84
|
+
#
|
85
|
+
# @param string [String]
|
86
|
+
# @return [String]
|
87
|
+
def error(string, *args)
|
88
|
+
output_method = args.include?(:nonewline) ? :print : :puts
|
89
|
+
self.send(output_method, "#{color('[ERROR]:', :red, :bold)} #{string}")
|
90
|
+
string
|
91
|
+
end
|
92
|
+
|
93
|
+
# Format fatal string
|
94
|
+
#
|
95
|
+
# @param string [String]
|
96
|
+
# @return [String]
|
97
|
+
def fatal(string, *args)
|
98
|
+
output_method = args.include?(:nonewline) ? :print : :puts
|
99
|
+
self.send(output_method, "#{color('[FATAL]:', :red, :bold)} #{string}")
|
100
|
+
string
|
101
|
+
end
|
102
|
+
|
103
|
+
# Output info if verbose flag is set
|
104
|
+
#
|
105
|
+
# @param string [String]
|
106
|
+
# @return [String, NilClass]
|
107
|
+
def verbose(string, *args)
|
108
|
+
if(options[:verbose])
|
109
|
+
info(string, :verbose, *args)
|
110
|
+
string
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Format debug string and output only if debug is set
|
115
|
+
#
|
116
|
+
# @param string [String]
|
117
|
+
# @return [String, NilClass]
|
118
|
+
def debug(string, *args)
|
119
|
+
if(options[:debug])
|
120
|
+
output_method = args.include?(:nonewline) ? :print : :puts
|
121
|
+
self.send(output_method, "#{color('[DEBUG]:', :white, :bold)} #{string}")
|
122
|
+
string
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Colorize string
|
127
|
+
#
|
128
|
+
# @param string [String]
|
129
|
+
# @param args [Symbol]
|
130
|
+
# @return [String]
|
131
|
+
def color(string, *args)
|
132
|
+
if(colorize)
|
133
|
+
Paint[string, *args]
|
134
|
+
else
|
135
|
+
string
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Prompt for question and receive answer
|
140
|
+
#
|
141
|
+
# @param question [String]
|
142
|
+
# @param default [String]
|
143
|
+
# @return [String]
|
144
|
+
def ask(question, *args)
|
145
|
+
opts = (args.detect{|x| x.is_a?(Hash)} || {}).to_smash
|
146
|
+
default = args.detect{|x| x.is_a?(String)} || opts[:default]
|
147
|
+
if(auto_default && default)
|
148
|
+
default
|
149
|
+
else
|
150
|
+
valid = opts[:valid]
|
151
|
+
string = question.dup
|
152
|
+
if(default)
|
153
|
+
default_string = !default.to_s.empty? && opts[:hide_default] ? '*****' : default
|
154
|
+
string << " [#{default_string}]"
|
155
|
+
end
|
156
|
+
result = nil
|
157
|
+
until(result)
|
158
|
+
info "#{string}: ", :nonewline
|
159
|
+
result = opts[:no_echo] ?
|
160
|
+
$stdin.noecho(&:gets).strip :
|
161
|
+
$stdin.gets.strip
|
162
|
+
puts "\n" if opts[:no_echo]
|
163
|
+
if(result.to_s.empty? && default)
|
164
|
+
result = default.to_s
|
165
|
+
end
|
166
|
+
|
167
|
+
if(valid)
|
168
|
+
case valid
|
169
|
+
when Array
|
170
|
+
result = nil unless valid.include?(result)
|
171
|
+
when Regexp
|
172
|
+
result = nil unless result =~ valid
|
173
|
+
end
|
174
|
+
end
|
175
|
+
if(result.to_s.empty?)
|
176
|
+
error 'Please provide a valid value'
|
177
|
+
result = nil
|
178
|
+
end
|
179
|
+
end
|
180
|
+
result
|
181
|
+
end
|
182
|
+
end
|
183
|
+
alias_method :ask_question, :ask
|
184
|
+
|
185
|
+
# Confirm question. Requires user to provide Y or N answer
|
186
|
+
#
|
187
|
+
# @param question [String]
|
188
|
+
def confirm(question)
|
189
|
+
unless(auto_confirm)
|
190
|
+
result = ask("#{question} (Y/N)", :valid => /[YyNn]/).downcase
|
191
|
+
raise ConfirmationDeclined.new 'Confirmation declined!' unless result == 'y'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Create a new table
|
196
|
+
#
|
197
|
+
# @param inst [Object] instance to attach table (for method call proxy)
|
198
|
+
# @return [Table]
|
199
|
+
def table(inst=nil, &block)
|
200
|
+
Table.new(self, inst, &block)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
data/lib/bogo-ui/table.rb
CHANGED
@@ -1,153 +1 @@
|
|
1
|
-
require 'bogo
|
2
|
-
require 'command_line_reporter'
|
3
|
-
|
4
|
-
module Bogo
|
5
|
-
|
6
|
-
class Ui
|
7
|
-
# Table output helper
|
8
|
-
class Table
|
9
|
-
|
10
|
-
include CommandLineReporter
|
11
|
-
|
12
|
-
# @return [Bogo::Ui]
|
13
|
-
attr_reader :ui
|
14
|
-
# @return [Array<Proc>]
|
15
|
-
attr_reader :table
|
16
|
-
# @return [Object]
|
17
|
-
attr_reader :proxy_to
|
18
|
-
|
19
|
-
# Create a new instance
|
20
|
-
#
|
21
|
-
# @param ui [Bogo::Ui]
|
22
|
-
# @yield table content
|
23
|
-
# @return [self]
|
24
|
-
def initialize(ui, inst=nil, &block)
|
25
|
-
@proxy_to = inst
|
26
|
-
@ui = ui
|
27
|
-
@base = block
|
28
|
-
@content = []
|
29
|
-
@printed_lines = []
|
30
|
-
end
|
31
|
-
|
32
|
-
# If proxy instance is provided, forward if possible
|
33
|
-
def method_missing(m_name, *args, &block)
|
34
|
-
if(proxy_to && proxy_to.respond_to?(m_name, true))
|
35
|
-
proxy_to.send(m_name, *args, &block)
|
36
|
-
else
|
37
|
-
super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Update the table content
|
42
|
-
#
|
43
|
-
# @yield table content
|
44
|
-
# @return [self]
|
45
|
-
def update(&block)
|
46
|
-
@content << block
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
# Override to provide buffered support
|
51
|
-
#
|
52
|
-
# @param options [Hash]
|
53
|
-
# @return [self]
|
54
|
-
def table(options={})
|
55
|
-
@table = BufferedTable.new(options)
|
56
|
-
yield
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
|
-
# Override to provide buffered support
|
61
|
-
#
|
62
|
-
# @param options [Hash]
|
63
|
-
# @return [self]
|
64
|
-
def row(options={})
|
65
|
-
options[:encoding] ||= @table.encoding
|
66
|
-
@row = BufferedRow.new(options.merge(:buffer => @table.buffer))
|
67
|
-
yield
|
68
|
-
@table.add(@row)
|
69
|
-
self
|
70
|
-
end
|
71
|
-
|
72
|
-
# Output table to defined UI
|
73
|
-
#
|
74
|
-
# @return [self]
|
75
|
-
# @note can be called multiple times to print table updates
|
76
|
-
def display
|
77
|
-
# init the table
|
78
|
-
instance_exec(&@base)
|
79
|
-
# load the table
|
80
|
-
@content.each do |tblock|
|
81
|
-
instance_exec(&tblock)
|
82
|
-
end
|
83
|
-
@table.output
|
84
|
-
@table.buffer.rewind
|
85
|
-
output = @table.buffer.read.split("\n")
|
86
|
-
output = output.find_all do |line|
|
87
|
-
!@printed_lines.include?(
|
88
|
-
Digest::SHA256.hexdigest(line.gsub(/\s/, ''))
|
89
|
-
)
|
90
|
-
end
|
91
|
-
@printed_lines.concat(
|
92
|
-
output.map{|l| Digest::SHA256.hexdigest(l.gsub(/\s/, '')) }
|
93
|
-
)
|
94
|
-
ui.puts output.join("\n") unless output.empty?
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
# Wrapper class to get desired buffering
|
99
|
-
class BufferedTable < CommandLineReporter::Table
|
100
|
-
|
101
|
-
# @return [StringIO]
|
102
|
-
attr_reader :buffer
|
103
|
-
|
104
|
-
# Create new instance and init buffer
|
105
|
-
#
|
106
|
-
# @return [self]
|
107
|
-
def initialize(*args)
|
108
|
-
@buffer = StringIO.new
|
109
|
-
super
|
110
|
-
end
|
111
|
-
|
112
|
-
# buffered puts
|
113
|
-
def puts(string)
|
114
|
-
buffer.puts(string)
|
115
|
-
end
|
116
|
-
|
117
|
-
# buffered print
|
118
|
-
def print(string)
|
119
|
-
buffer.print(string)
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
# Wrapper class to get desired buffering
|
125
|
-
class BufferedRow < CommandLineReporter::Row
|
126
|
-
|
127
|
-
# @return [StringIO]
|
128
|
-
attr_reader :buffer
|
129
|
-
|
130
|
-
# Create new instance and init buffer
|
131
|
-
#
|
132
|
-
# @return [self]
|
133
|
-
def initialize(options={})
|
134
|
-
@buffer = options.delete(:buffer)
|
135
|
-
super
|
136
|
-
end
|
137
|
-
|
138
|
-
# buffered puts
|
139
|
-
def puts(string)
|
140
|
-
buffer.puts(string)
|
141
|
-
end
|
142
|
-
|
143
|
-
# buffered print
|
144
|
-
def print(string)
|
145
|
-
buffer.print(string)
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
1
|
+
require 'bogo/ui'
|
data/lib/bogo-ui/ui.rb
CHANGED
@@ -1,200 +1 @@
|
|
1
|
-
require 'bogo
|
2
|
-
require 'paint'
|
3
|
-
require 'io/console'
|
4
|
-
|
5
|
-
module Bogo
|
6
|
-
# CLI UI helper
|
7
|
-
class Ui
|
8
|
-
|
9
|
-
autoload :Table, 'bogo-ui/table'
|
10
|
-
|
11
|
-
# @return [Truthy, Falsey]
|
12
|
-
attr_accessor :colorize
|
13
|
-
# @return [String]
|
14
|
-
attr_accessor :application_name
|
15
|
-
# @return [IO]
|
16
|
-
attr_reader :output_to
|
17
|
-
# @return [Truthy, Falsey]
|
18
|
-
attr_accessor :auto_confirm
|
19
|
-
# @return [Truthy, Falsey]
|
20
|
-
attr_accessor :auto_default
|
21
|
-
# @return [Smash] options
|
22
|
-
attr_reader :options
|
23
|
-
|
24
|
-
# Build new UI instance
|
25
|
-
#
|
26
|
-
# @param args [Hash]
|
27
|
-
# @option args [String] :app_name name of application
|
28
|
-
# @option args [TrueClass, FalseClass] :colors enable/disable colors
|
29
|
-
# @option args [IO] :output_to IO to write
|
30
|
-
# @return [self]
|
31
|
-
def initialize(args={})
|
32
|
-
@application_name = args.fetch(:app_name, 'App')
|
33
|
-
@colorize = args.fetch(:colors, true)
|
34
|
-
@output_to = args.fetch(:output_to, $stdout)
|
35
|
-
@auto_confirm = args.fetch(:auto_confirm, args.fetch(:yes, false))
|
36
|
-
@auto_default = args.fetch(:auto_default, args.fetch(:defaults, false))
|
37
|
-
@options = args.to_smash
|
38
|
-
end
|
39
|
-
|
40
|
-
# Output directly
|
41
|
-
#
|
42
|
-
# @param string [String]
|
43
|
-
# @return [String]
|
44
|
-
def puts(string='')
|
45
|
-
output_to.puts string
|
46
|
-
string
|
47
|
-
end
|
48
|
-
|
49
|
-
# Output directly
|
50
|
-
#
|
51
|
-
# @param string [String]
|
52
|
-
# @return [String]
|
53
|
-
def print(string='')
|
54
|
-
output_to.print string
|
55
|
-
string
|
56
|
-
end
|
57
|
-
|
58
|
-
# Output information string
|
59
|
-
#
|
60
|
-
# @param string [String]
|
61
|
-
# @return [String]
|
62
|
-
def info(string, *args)
|
63
|
-
output_method = args.include?(:nonewline) ? :print : :puts
|
64
|
-
o_color = args.include?(:verbose) ? :yellow : :green
|
65
|
-
self.send(output_method, "#{color("[#{application_name}]:", o_color)} #{string}")
|
66
|
-
string
|
67
|
-
end
|
68
|
-
|
69
|
-
# Format warning string
|
70
|
-
#
|
71
|
-
# @param string [String]
|
72
|
-
# @return [String]
|
73
|
-
def warn(string, *args)
|
74
|
-
output_method = args.include?(:nonewline) ? :print : :puts
|
75
|
-
self.send(output_method, "#{color('[WARN]:', :yellow, :bold)} #{string}")
|
76
|
-
string
|
77
|
-
end
|
78
|
-
|
79
|
-
# Format error string
|
80
|
-
#
|
81
|
-
# @param string [String]
|
82
|
-
# @return [String]
|
83
|
-
def error(string, *args)
|
84
|
-
output_method = args.include?(:nonewline) ? :print : :puts
|
85
|
-
self.send(output_method, "#{color('[ERROR]:', :red, :bold)} #{string}")
|
86
|
-
string
|
87
|
-
end
|
88
|
-
|
89
|
-
# Format fatal string
|
90
|
-
#
|
91
|
-
# @param string [String]
|
92
|
-
# @return [String]
|
93
|
-
def fatal(string, *args)
|
94
|
-
output_method = args.include?(:nonewline) ? :print : :puts
|
95
|
-
self.send(output_method, "#{color('[FATAL]:', :red, :bold)} #{string}")
|
96
|
-
string
|
97
|
-
end
|
98
|
-
|
99
|
-
# Output info if verbose flag is set
|
100
|
-
#
|
101
|
-
# @param string [String]
|
102
|
-
# @return [String, NilClass]
|
103
|
-
def verbose(string, *args)
|
104
|
-
if(options[:verbose])
|
105
|
-
info(string, :verbose, *args)
|
106
|
-
string
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# Format debug string and output only if debug is set
|
111
|
-
#
|
112
|
-
# @param string [String]
|
113
|
-
# @return [String, NilClass]
|
114
|
-
def debug(string, *args)
|
115
|
-
if(options[:debug])
|
116
|
-
output_method = args.include?(:nonewline) ? :print : :puts
|
117
|
-
self.send(output_method, "#{color('[DEBUG]:', :white, :bold)} #{string}")
|
118
|
-
string
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# Colorize string
|
123
|
-
#
|
124
|
-
# @param string [String]
|
125
|
-
# @param args [Symbol]
|
126
|
-
# @return [String]
|
127
|
-
def color(string, *args)
|
128
|
-
if(colorize)
|
129
|
-
Paint[string, *args]
|
130
|
-
else
|
131
|
-
string
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# Prompt for question and receive answer
|
136
|
-
#
|
137
|
-
# @param question [String]
|
138
|
-
# @param default [String]
|
139
|
-
# @return [String]
|
140
|
-
def ask(question, *args)
|
141
|
-
opts = (args.detect{|x| x.is_a?(Hash)} || {}).to_smash
|
142
|
-
default = args.detect{|x| x.is_a?(String)} || opts[:default]
|
143
|
-
if(auto_default && default)
|
144
|
-
default
|
145
|
-
else
|
146
|
-
valid = opts[:valid]
|
147
|
-
string = question.dup
|
148
|
-
if(default)
|
149
|
-
default_string = !default.to_s.empty? && opts[:hide_default] ? '*****' : default
|
150
|
-
string << " [#{default_string}]"
|
151
|
-
end
|
152
|
-
result = nil
|
153
|
-
until(result)
|
154
|
-
info "#{string}: ", :nonewline
|
155
|
-
result = opts[:no_echo] ?
|
156
|
-
$stdin.noecho(&:gets).strip :
|
157
|
-
$stdin.gets.strip
|
158
|
-
puts "\n" if opts[:no_echo]
|
159
|
-
if(result.to_s.empty? && default)
|
160
|
-
result = default.to_s
|
161
|
-
end
|
162
|
-
|
163
|
-
if(valid)
|
164
|
-
case valid
|
165
|
-
when Array
|
166
|
-
result = nil unless valid.include?(result)
|
167
|
-
when Regexp
|
168
|
-
result = nil unless result =~ valid
|
169
|
-
end
|
170
|
-
end
|
171
|
-
if(result.to_s.empty?)
|
172
|
-
error 'Please provide a valid value'
|
173
|
-
result = nil
|
174
|
-
end
|
175
|
-
end
|
176
|
-
result
|
177
|
-
end
|
178
|
-
end
|
179
|
-
alias_method :ask_question, :ask
|
180
|
-
|
181
|
-
# Confirm question. Requires user to provide Y or N answer
|
182
|
-
#
|
183
|
-
# @param question [String]
|
184
|
-
def confirm(question)
|
185
|
-
unless(auto_confirm)
|
186
|
-
result = ask("#{question} (Y/N)", :valid => /[YyNn]/).downcase
|
187
|
-
raise 'Confirmation declined!' unless result == 'y'
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
# Create a new table
|
192
|
-
#
|
193
|
-
# @param inst [Object] instance to attach table (for method call proxy)
|
194
|
-
# @return [Table]
|
195
|
-
def table(inst=nil, &block)
|
196
|
-
Table.new(self, inst, &block)
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
end
|
1
|
+
require 'bogo/ui'
|
data/lib/bogo-ui.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bogo-ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bogo
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: command_line_reporter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '4.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '4.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: paint
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.5'
|
55
83
|
description: UI Helper libraries
|
56
84
|
email: code@chrisroberts.org
|
57
85
|
executables: []
|
@@ -66,7 +94,9 @@ files:
|
|
66
94
|
- lib/bogo-ui.rb
|
67
95
|
- lib/bogo-ui/table.rb
|
68
96
|
- lib/bogo-ui/ui.rb
|
69
|
-
- lib/bogo
|
97
|
+
- lib/bogo/ui.rb
|
98
|
+
- lib/bogo/ui/table.rb
|
99
|
+
- lib/bogo/ui/version.rb
|
70
100
|
homepage: https://github.com/spox/bogo-ui
|
71
101
|
licenses:
|
72
102
|
- Apache 2.0
|
@@ -86,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
116
|
- !ruby/object:Gem::Version
|
87
117
|
version: '0'
|
88
118
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.7.6
|
119
|
+
rubygems_version: 3.4.0.dev
|
91
120
|
signing_key:
|
92
121
|
specification_version: 4
|
93
122
|
summary: UI Helper libraries
|