blackbox 3.1.4 → 3.2.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.
@@ -167,6 +167,21 @@
167
167
  </ul>
168
168
  </ul>
169
169
 
170
+
171
+ <ul id="alpha_U" class="alpha">
172
+ <li class="letter">U</li>
173
+ <ul>
174
+
175
+ <li>
176
+ <span class='object_link'><a href="BB/Unix.html" title="BB::Unix (module)">Unix</a></span>
177
+
178
+ <small>(BB)</small>
179
+
180
+ </li>
181
+
182
+ </ul>
183
+ </ul>
184
+
170
185
  </td>
171
186
  </tr>
172
187
  </table>
@@ -176,7 +191,7 @@
176
191
  </div>
177
192
 
178
193
  <div id="footer">
179
- Generated on Sat May 14 23:58:48 2016 by
194
+ Generated on Mon Jun 13 02:13:49 2016 by
180
195
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
181
196
  0.8.7.6 (ruby-2.3.1).
182
197
  </div>
@@ -50,7 +50,7 @@
50
50
 
51
51
  <ul id="full_list" class="class">
52
52
  <li><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></li>
53
- <li><a class='toggle'></a> <span class='object_link'><a href="BB.html" title="BB (module)">BB</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="BB/Crypto.html" title="BB::Crypto (module)">Crypto</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Gem.html" title="BB::Gem (module)">Gem</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Hash.html" title="BB::Hash (module)">Hash</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Number.html" title="BB::Number (module)">Number</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/String.html" title="BB::String (module)">String</a></span><small class='search_info'>BB</small></li></ul>
53
+ <li><a class='toggle'></a> <span class='object_link'><a href="BB.html" title="BB (module)">BB</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="BB/Crypto.html" title="BB::Crypto (module)">Crypto</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Gem.html" title="BB::Gem (module)">Gem</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Hash.html" title="BB::Hash (module)">Hash</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Number.html" title="BB::Number (module)">Number</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/String.html" title="BB::String (module)">String</a></span><small class='search_info'>BB</small></li><li><span class='object_link'><a href="BB/Unix.html" title="BB::Unix (module)">Unix</a></span><small class='search_info'>BB</small></li></ul>
54
54
 
55
55
  </ul>
56
56
  </div>
@@ -61,7 +61,7 @@
61
61
 
62
62
  <iframe id="search_frame"></iframe>
63
63
 
64
- <div id="content"><div id='filecontents'><h1>Blackbox <a href="https://travis-ci.org/busyloop/blackbox"><img src="https://travis-ci.org/busyloop/blackbox.png?branch=master" alt="Build Status"></a> <a href="https://gemnasium.com/github.com/busyloop/blackbox"><img src="https://gemnasium.com/badges/github.com/busyloop/blackbox.svg" alt="Dependency Status"></a></h1>
64
+ <div id="content"><div id='filecontents'><h1>Blackbox <a href="https://travis-ci.org/busyloop/blackbox"><img src="https://travis-ci.org/busyloop/blackbox.png?branch=master" alt="Build Status"></a> <a href="https://gemnasium.com/github.com/busyloop/blackbox"><img src="https://gemnasium.com/badges/github.com/busyloop/blackbox.svg" alt="Dependency Status"></a> <a href="https://badge.fury.io/rb/blackbox"><img src="https://badge.fury.io/rb/blackbox.svg" alt="Gem Version"></a></h1>
65
65
 
66
66
  <p>Various little helpers.</p>
67
67
 
@@ -95,7 +95,7 @@ BB::String.strip_ansi( ... )
95
95
  </div></div>
96
96
 
97
97
  <div id="footer">
98
- Generated on Sat May 14 23:58:48 2016 by
98
+ Generated on Mon Jun 13 02:13:49 2016 by
99
99
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
100
100
  0.8.7.6 (ruby-2.3.1).
101
101
  </div>
@@ -61,7 +61,7 @@
61
61
 
62
62
  <iframe id="search_frame"></iframe>
63
63
 
64
- <div id="content"><div id='filecontents'><h1>Blackbox <a href="https://travis-ci.org/busyloop/blackbox"><img src="https://travis-ci.org/busyloop/blackbox.png?branch=master" alt="Build Status"></a> <a href="https://gemnasium.com/github.com/busyloop/blackbox"><img src="https://gemnasium.com/badges/github.com/busyloop/blackbox.svg" alt="Dependency Status"></a></h1>
64
+ <div id="content"><div id='filecontents'><h1>Blackbox <a href="https://travis-ci.org/busyloop/blackbox"><img src="https://travis-ci.org/busyloop/blackbox.png?branch=master" alt="Build Status"></a> <a href="https://gemnasium.com/github.com/busyloop/blackbox"><img src="https://gemnasium.com/badges/github.com/busyloop/blackbox.svg" alt="Dependency Status"></a> <a href="https://badge.fury.io/rb/blackbox"><img src="https://badge.fury.io/rb/blackbox.svg" alt="Gem Version"></a></h1>
65
65
 
66
66
  <p>Various little helpers.</p>
67
67
 
@@ -95,7 +95,7 @@ BB::String.strip_ansi( ... )
95
95
  </div></div>
96
96
 
97
97
  <div id="footer">
98
- Generated on Sat May 14 23:58:48 2016 by
98
+ Generated on Mon Jun 13 02:13:49 2016 by
99
99
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
100
100
  0.8.7.6 (ruby-2.3.1).
101
101
  </div>
@@ -94,36 +94,42 @@
94
94
 
95
95
 
96
96
  <li class="r2 ">
97
+ <span class='object_link'><a href="BB/Unix.html#run_each-class_method" title="BB::Unix.run_each (method)">run_each</a></span>
98
+ <small>BB::Unix</small>
99
+ </li>
100
+
101
+
102
+ <li class="r1 ">
97
103
  <span class='object_link'><a href="BB/String.html#strip_ansi-class_method" title="BB::String.strip_ansi (method)">strip_ansi</a></span>
98
104
  <small>BB::String</small>
99
105
  </li>
100
106
 
101
107
 
102
- <li class="r1 ">
108
+ <li class="r2 ">
103
109
  <span class='object_link'><a href="BB/Hash.html#symbolize_keys-class_method" title="BB::Hash.symbolize_keys (method)">symbolize_keys</a></span>
104
110
  <small>BB::Hash</small>
105
111
  </li>
106
112
 
107
113
 
108
- <li class="r2 ">
114
+ <li class="r1 ">
109
115
  <span class='object_link'><a href="BB/Number.html#to_human_size-class_method" title="BB::Number.to_human_size (method)">to_human_size</a></span>
110
116
  <small>BB::Number</small>
111
117
  </li>
112
118
 
113
119
 
114
- <li class="r1 ">
120
+ <li class="r2 ">
115
121
  <span class='object_link'><a href="BB/Gem.html#version_info-class_method" title="BB::Gem.version_info (method)">version_info</a></span>
116
122
  <small>BB::Gem</small>
117
123
  </li>
118
124
 
119
125
 
120
- <li class="r2 ">
126
+ <li class="r1 ">
121
127
  <span class='object_link'><a href="BB/Number.html#with_delimiter-class_method" title="BB::Number.with_delimiter (method)">with_delimiter</a></span>
122
128
  <small>BB::Number</small>
123
129
  </li>
124
130
 
125
131
 
126
- <li class="r1 ">
132
+ <li class="r2 ">
127
133
  <span class='object_link'><a href="BB/Number.html#with_precision-class_method" title="BB::Number.with_precision (method)">with_precision</a></span>
128
134
  <small>BB::Number</small>
129
135
  </li>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sat May 14 23:58:48 2016 by
106
+ Generated on Mon Jun 13 02:13:49 2016 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.6 (ruby-2.3.1).
109
109
  </div>
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+ require 'lolcat/lol'
3
+ require 'thread'
4
+ require 'open3'
5
+ require 'pty'
6
+ require 'rainbow/ext/string'
7
+
8
+ module BB
9
+ # Unix utilities.
10
+ module Unix
11
+ class << self
12
+ # Run each line of a script in a shell.
13
+ #
14
+ # @param [Hash] script Script
15
+ # @return [Hash] Exit status (depends on mode)
16
+ def run_each(script, opts = {})
17
+ opts = {
18
+ quiet: false,
19
+ failfast: true,
20
+ spinner: nil,
21
+ stream: false
22
+ }.merge(opts)
23
+
24
+ @minispinlock ||= Mutex.new
25
+ script.lines.each_with_index do |line, i|
26
+ line.chomp!
27
+ case line[0]
28
+ when '#'
29
+ puts "\n" + line.bright unless opts[:quiet]
30
+ when ':'
31
+ opts[:quiet] = true if line == ':quiet'
32
+ opts[:failfast] = false if line == ':return'
33
+ opts[:spinner] = nil if line == ':nospinner'
34
+ if line == ':stream'
35
+ opts[:stream] = true
36
+ opts[:quiet] = false
37
+ end
38
+ end
39
+ next if line.empty? || ['#', ':'].include?(line[0])
40
+
41
+ status = nil
42
+ if opts[:stream]
43
+ puts "\n> ".color(:green) + line.color(:black).bright
44
+ rows, cols = STDIN.winsize
45
+ @minispin_disable = false
46
+ @minispin_last_char_at = Time.now
47
+ @tspin ||= Thread.new do
48
+ i = 0
49
+ loop do
50
+ break if @minispin_last_char_at == :end
51
+ if 0.23 > Time.now - @minispin_last_char_at || @minispin_disable
52
+ sleep 0.1
53
+ next
54
+ end
55
+ @minispinlock.synchronize do
56
+ next if @minispin_disable
57
+ print "\e[?25l"
58
+ print Paint[' ', '#000', Lol.rainbow(1, i / 3.0)]
59
+ sleep 0.12
60
+ print 8.chr
61
+ print ' '
62
+ print 8.chr
63
+ i += 1
64
+ print "\e[?25h"
65
+ end
66
+ end
67
+ end
68
+
69
+ PTY.spawn("stty rows #{rows} cols #{cols}; " + line) do |r, _w, pid|
70
+ begin
71
+ until r.eof?
72
+ c = r.getc
73
+ @minispinlock.synchronize do
74
+ print c
75
+ @minispin_last_char_at = Time.now
76
+ c = c.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: "\e") # barf.
77
+ # hold on when we are (likely) inside an escape sequence
78
+ @minispin_disable = true if c.ord == 27 || c.ord < 9
79
+ @minispin_disable = false if c =~ /[A-Za-z]/ || [13, 10].include?(c.ord)
80
+ end
81
+ end
82
+ rescue Errno::EIO
83
+ # Linux raises EIO on EOF, cf.
84
+ # https://github.com/ruby/ruby/blob/57fb2199059cb55b632d093c2e64c8a3c60acfbb/ext/pty/pty.c#L519
85
+ nil
86
+ end
87
+
88
+ _pid, status = Process.wait2(pid)
89
+ @minispin_last_char_at = :end
90
+ @tspin.join
91
+ @tspin = nil
92
+ end
93
+ else
94
+ opts[:spinner].call(true) if opts[:spinner]
95
+ output, status = Open3.capture2e(line)
96
+ opts[:spinner].call(false) if opts[:spinner]
97
+ color = (status.exitstatus == 0) ? :green : :red
98
+ if status.exitstatus != 0 || !opts[:quiet]
99
+ puts "\n> ".color(color) + line.color(:black).bright
100
+ puts output
101
+ end
102
+ end
103
+ next unless status.exitstatus != 0
104
+ puts "Error, exit #{status.exitstatus}: #{line} (L#{i})".color(:red).bright
105
+
106
+ exit status.exitstatus if opts[:failfast]
107
+ return status.exitstatus
108
+ end
109
+ 0
110
+ end
111
+ end
112
+ end
113
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module BB
3
- VERSION = '3.1.4'
3
+ VERSION = '3.2.0'
4
4
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require 'blackbox/unix'
4
+
5
+ describe BB::Unix do
6
+ describe '.run_each' do
7
+ it 'exits on failure by default' do
8
+ expect do
9
+ expect do
10
+ BB::Unix.run_each('false')
11
+ end.to output.to_stdout
12
+ end.to raise_error(SystemExit)
13
+ end
14
+
15
+ it 'echos to stdout by default' do
16
+ expect do
17
+ BB::Unix.run_each('true')
18
+ end.to output(/true/).to_stdout
19
+ end
20
+
21
+ it 'quiet success in quiet mode' do
22
+ expect do
23
+ BB::Unix.run_each(":return\n:quiet\ntrue")
24
+ end.to output('').to_stdout
25
+ end
26
+
27
+ it 'loud failure in quiet mode' do
28
+ expect do
29
+ BB::Unix.run_each(":return\n:quiet\nfalse")
30
+ end.to output(/exit 1: false/).to_stdout
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-14 00:00:00.000000000 Z
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -178,6 +178,34 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: lolcat
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rainbow
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
181
209
  description: Various little helpers
182
210
  email:
183
211
  - moe@busyloop.net
@@ -272,6 +300,7 @@ files:
272
300
  - doc/BB/Hash.html
273
301
  - doc/BB/Number.html
274
302
  - doc/BB/String.html
303
+ - doc/BB/Unix.html
275
304
  - doc/_index.html
276
305
  - doc/class_list.html
277
306
  - doc/css/common.css
@@ -292,6 +321,7 @@ files:
292
321
  - lib/blackbox/hash.rb
293
322
  - lib/blackbox/number.rb
294
323
  - lib/blackbox/string.rb
324
+ - lib/blackbox/unix.rb
295
325
  - lib/blackbox/version.rb
296
326
  - spec/blackbox_spec.rb
297
327
  - spec/crypto_spec.rb
@@ -300,6 +330,7 @@ files:
300
330
  - spec/number_spec.rb
301
331
  - spec/spec_helper.rb
302
332
  - spec/string_spec.rb
333
+ - spec/unix_spec.rb
303
334
  homepage: https://github.com/busyloop/blackbox
304
335
  licenses:
305
336
  - MPL 2.0
@@ -332,4 +363,5 @@ test_files:
332
363
  - spec/number_spec.rb
333
364
  - spec/spec_helper.rb
334
365
  - spec/string_spec.rb
366
+ - spec/unix_spec.rb
335
367
  has_rdoc: