ruby-progress 1.3.4 → 1.3.5
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/.rubocop_todo.yml +26 -13
- data/CHANGELOG.md +29 -49
- data/DAEMON_MODE.md +127 -0
- data/Gemfile +7 -1
- data/Gemfile.lock +19 -18
- data/JOB_CLI_REFACTOR.md +67 -0
- data/README.md +90 -94
- data/bin/prg +10 -16
- data/examples/daemon_job_example.sh +8 -10
- data/lib/ruby-progress/cli/fill_options.rb +2 -6
- data/lib/ruby-progress/cli/job_cli.rb +170 -131
- data/lib/ruby-progress/cli/ripple_cli.rb +13 -55
- data/lib/ruby-progress/cli/ripple_options.rb +14 -3
- data/lib/ruby-progress/cli/twirl_cli.rb +3 -1
- data/lib/ruby-progress/cli/twirl_options.rb +0 -4
- data/lib/ruby-progress/cli/twirl_runner.rb +0 -36
- data/lib/ruby-progress/cli/worm_cli.rb +2 -51
- data/lib/ruby-progress/cli/worm_options.rb +0 -6
- data/lib/ruby-progress/cli/worm_runner.rb +7 -1
- data/lib/ruby-progress/daemon.rb +2 -64
- data/lib/ruby-progress/fill_cli.rb +2 -72
- data/lib/ruby-progress/output_capture.rb +7 -2
- data/lib/ruby-progress/utils.rb +11 -6
- data/lib/ruby-progress/version.rb +5 -5
- data/ruby-progress.gemspec +41 -0
- data/scripts/coverage_analysis.rb +49 -0
- data/test_daemon.sh +20 -0
- metadata +6 -15
data/lib/ruby-progress/daemon.rb
CHANGED
|
@@ -4,6 +4,8 @@ require 'json'
|
|
|
4
4
|
require 'fileutils'
|
|
5
5
|
|
|
6
6
|
module RubyProgress
|
|
7
|
+
# Daemon helpers for backgrounding progress indicators.
|
|
8
|
+
# Provides minimal daemonization, PID file management, and simple control-message signaling.
|
|
7
9
|
module Daemon
|
|
8
10
|
module_function
|
|
9
11
|
|
|
@@ -15,70 +17,6 @@ module RubyProgress
|
|
|
15
17
|
"#{pid_file}.msg"
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
# Resolve a job directory for the daemon based on pid_file or name.
|
|
19
|
-
# If pid_file is '/tmp/ruby-progress/mytask.pid' -> jobs dir '/tmp/ruby-progress/mytask.jobs'
|
|
20
|
-
def job_dir_for_pid(pid_file)
|
|
21
|
-
base = File.basename(pid_file, '.*')
|
|
22
|
-
File.join(File.dirname(pid_file), "#{base}.jobs")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Process available job files in job_dir. Each job is a JSON file with {"id","command","meta"}.
|
|
26
|
-
# This method polls the directory and yields each parsed job hash to the provided block.
|
|
27
|
-
def process_jobs(job_dir, poll_interval: 0.2)
|
|
28
|
-
FileUtils.mkdir_p(job_dir)
|
|
29
|
-
|
|
30
|
-
loop do
|
|
31
|
-
# Accept any job file ending in .json (UUID filenames are common)
|
|
32
|
-
# Ignore processed-* archives and temporary files (e.g., .tmp)
|
|
33
|
-
files = Dir.children(job_dir).select do |f|
|
|
34
|
-
f.end_with?('.json') && !f.start_with?('processed-')
|
|
35
|
-
end.sort
|
|
36
|
-
|
|
37
|
-
files.each do |f|
|
|
38
|
-
path = File.join(job_dir, f)
|
|
39
|
-
processing = "#{path}.processing"
|
|
40
|
-
|
|
41
|
-
# Claim the file atomically
|
|
42
|
-
begin
|
|
43
|
-
File.rename(path, processing)
|
|
44
|
-
rescue StandardError
|
|
45
|
-
next
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
job = begin
|
|
49
|
-
JSON.parse(File.read(processing))
|
|
50
|
-
rescue StandardError
|
|
51
|
-
FileUtils.rm_f(processing)
|
|
52
|
-
next
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
begin
|
|
56
|
-
yielded = yield(job)
|
|
57
|
-
|
|
58
|
-
# on success, write .result info and merge any returned info
|
|
59
|
-
result = { 'id' => job['id'], 'status' => 'done', 'time' => Time.now.to_i }
|
|
60
|
-
if yielded.is_a?(Hash)
|
|
61
|
-
# ensure string keys
|
|
62
|
-
extra = yielded.transform_keys(&:to_s)
|
|
63
|
-
result.merge!(extra)
|
|
64
|
-
end
|
|
65
|
-
File.write("#{processing}.result", result.to_json)
|
|
66
|
-
rescue StandardError => e
|
|
67
|
-
result = { 'id' => job['id'], 'status' => 'error', 'error' => e.message }
|
|
68
|
-
File.write("#{processing}.result", result.to_json)
|
|
69
|
-
ensure
|
|
70
|
-
begin
|
|
71
|
-
FileUtils.mv(processing, File.join(job_dir, "processed-#{f}"))
|
|
72
|
-
rescue StandardError
|
|
73
|
-
FileUtils.rm_f(processing)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
sleep(poll_interval)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
20
|
def show_status(pid_file)
|
|
83
21
|
if File.exist?(pid_file)
|
|
84
22
|
pid = File.read(pid_file).strip
|
|
@@ -58,12 +58,8 @@ module RubyProgress
|
|
|
58
58
|
pid_file = resolve_pid_file(options, :daemon_name)
|
|
59
59
|
options[:pid_file] = pid_file
|
|
60
60
|
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
PrgCLI.backgroundize
|
|
64
|
-
else
|
|
65
|
-
PrgCLI.daemonize
|
|
66
|
-
end
|
|
61
|
+
# Background without detaching so progress bar remains visible in current terminal
|
|
62
|
+
PrgCLI.backgroundize
|
|
67
63
|
|
|
68
64
|
run_daemon_mode(options, parsed_style)
|
|
69
65
|
elsif options[:current]
|
|
@@ -120,72 +116,6 @@ module RubyProgress
|
|
|
120
116
|
begin
|
|
121
117
|
fill_bar.render # Show initial empty bar
|
|
122
118
|
|
|
123
|
-
# Start job processor thread for fill (so daemon can accept jobs)
|
|
124
|
-
job_dir = RubyProgress::Daemon.job_dir_for_pid(pid_file)
|
|
125
|
-
Thread.new do
|
|
126
|
-
RubyProgress::Daemon.process_jobs(job_dir) do |job|
|
|
127
|
-
jid = job['id'] || SecureRandom.uuid
|
|
128
|
-
log_path = begin
|
|
129
|
-
File.join(File.dirname(job_dir), "#{jid}.log")
|
|
130
|
-
rescue StandardError
|
|
131
|
-
nil
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
if job['command']
|
|
135
|
-
oc = RubyProgress::OutputCapture.new(
|
|
136
|
-
command: job['command'],
|
|
137
|
-
lines: options[:output_lines] || 3,
|
|
138
|
-
position: options[:output_position] || :above,
|
|
139
|
-
log_path: log_path,
|
|
140
|
-
stream: options[:stdout_live]
|
|
141
|
-
)
|
|
142
|
-
oc.start
|
|
143
|
-
|
|
144
|
-
fill_bar.instance_variable_set(:@output_capture, oc)
|
|
145
|
-
oc.wait
|
|
146
|
-
captured = oc.lines.join("\n")
|
|
147
|
-
exit_status = oc.exit_status
|
|
148
|
-
fill_bar.instance_variable_set(:@output_capture, nil)
|
|
149
|
-
|
|
150
|
-
success = exit_status.to_i.zero?
|
|
151
|
-
if job['message']
|
|
152
|
-
RubyProgress::Utils.display_completion(
|
|
153
|
-
job['message'],
|
|
154
|
-
success: success,
|
|
155
|
-
show_checkmark: job['checkmark'] || false,
|
|
156
|
-
output_stream: :stdout,
|
|
157
|
-
icons: { success: options[:success_icon], error: options[:error_icon] }
|
|
158
|
-
)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
{ 'exit_status' => exit_status, 'output' => captured, 'log_path' => log_path }
|
|
162
|
-
|
|
163
|
-
elsif job['action']
|
|
164
|
-
case job['action']
|
|
165
|
-
when 'advance'
|
|
166
|
-
fill_bar.advance
|
|
167
|
-
{ 'status' => 'done', 'action' => 'advance' }
|
|
168
|
-
when 'percent'
|
|
169
|
-
val = job['value'] || job['percent'] || 0
|
|
170
|
-
fill_bar.percent = val.to_f
|
|
171
|
-
{ 'status' => 'done', 'action' => 'percent', 'value' => val }
|
|
172
|
-
when 'complete'
|
|
173
|
-
fill_bar.complete
|
|
174
|
-
{ 'status' => 'done', 'action' => 'complete' }
|
|
175
|
-
when 'cancel'
|
|
176
|
-
fill_bar.cancel
|
|
177
|
-
{ 'status' => 'done', 'action' => 'cancel' }
|
|
178
|
-
else
|
|
179
|
-
{ 'status' => 'error', 'error' => 'unknown action' }
|
|
180
|
-
end
|
|
181
|
-
else
|
|
182
|
-
{ 'status' => 'error', 'error' => 'no command or action provided' }
|
|
183
|
-
end
|
|
184
|
-
rescue StandardError
|
|
185
|
-
nil
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
119
|
# Set up signal handlers for daemon control
|
|
190
120
|
stop_requested = false
|
|
191
121
|
Signal.trap('INT') { stop_requested = true }
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'pty'
|
|
4
4
|
require 'io/console'
|
|
5
|
-
require '
|
|
5
|
+
require 'English'
|
|
6
6
|
require 'fileutils'
|
|
7
7
|
|
|
8
8
|
begin
|
|
@@ -176,7 +176,12 @@ module RubyProgress
|
|
|
176
176
|
debug_log("spawned pid=#{pid} cmd=#{@command}")
|
|
177
177
|
|
|
178
178
|
until reader.eof? || @stop
|
|
179
|
-
|
|
179
|
+
ready = if reader.respond_to?(:wait_readable)
|
|
180
|
+
reader.wait_readable(0.1)
|
|
181
|
+
else
|
|
182
|
+
IO.select([reader], nil, nil, 0.1)
|
|
183
|
+
end
|
|
184
|
+
next unless ready
|
|
180
185
|
|
|
181
186
|
chunk = reader.read_nonblock(4096, exception: false)
|
|
182
187
|
next if chunk.nil? || chunk.empty?
|
data/lib/ruby-progress/utils.rb
CHANGED
|
@@ -41,12 +41,17 @@ module RubyProgress
|
|
|
41
41
|
def self.display_completion(message, success: true, show_checkmark: false, output_stream: :warn, icons: {})
|
|
42
42
|
return unless message
|
|
43
43
|
|
|
44
|
-
mark
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
# Determine the mark to show. If checkmarks are enabled, prefer the
|
|
45
|
+
# default icons but allow overrides via icons hash. If checkmarks are not
|
|
46
|
+
# enabled, still show a custom icon when provided via CLI options.
|
|
47
|
+
mark = ''
|
|
48
|
+
if show_checkmark
|
|
49
|
+
icon = success ? (icons[:success] || '✅') : (icons[:error] || '🛑')
|
|
50
|
+
mark = "#{icon} "
|
|
51
|
+
else
|
|
52
|
+
custom_icon = success ? icons[:success] : icons[:error]
|
|
53
|
+
mark = custom_icon ? "#{custom_icon} " : ''
|
|
54
|
+
end
|
|
50
55
|
|
|
51
56
|
formatted_message = "#{mark}#{message}"
|
|
52
57
|
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyProgress
|
|
4
4
|
# Main gem version
|
|
5
|
-
VERSION = '1.3.
|
|
5
|
+
VERSION = '1.3.5'
|
|
6
6
|
|
|
7
7
|
# Component-specific versions (patch bumps)
|
|
8
|
-
WORM_VERSION = '1.1.
|
|
9
|
-
TWIRL_VERSION = '1.1.
|
|
10
|
-
RIPPLE_VERSION = '1.1.
|
|
11
|
-
FILL_VERSION = '1.0.
|
|
8
|
+
WORM_VERSION = '1.1.5'
|
|
9
|
+
TWIRL_VERSION = '1.1.5'
|
|
10
|
+
RIPPLE_VERSION = '1.1.5'
|
|
11
|
+
FILL_VERSION = '1.0.5'
|
|
12
12
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/ruby-progress/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'ruby-progress'
|
|
7
|
+
spec.version = RubyProgress::VERSION
|
|
8
|
+
spec.authors = ['Brett Terpstra']
|
|
9
|
+
spec.email = ['me@brettterpstra.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Animated terminal progress indicators'
|
|
12
|
+
spec.description = 'Animated progress indicators for Ruby: Ripple (text ripple effects), Worm (Unicode wave animations), and Twirl (spinner indicators)'
|
|
13
|
+
spec.homepage = 'https://github.com/ttscoff/ruby-progress'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 2.5.0'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
19
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = 'bin'
|
|
28
|
+
spec.executables = %w[prg ripple worm twirl fill]
|
|
29
|
+
spec.require_paths = ['lib']
|
|
30
|
+
|
|
31
|
+
# Runtime dependencies
|
|
32
|
+
spec.add_dependency 'tty-cursor', '~> 0.7'
|
|
33
|
+
spec.add_dependency 'tty-screen', '~> 0.8'
|
|
34
|
+
|
|
35
|
+
# Development dependencies
|
|
36
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
38
|
+
# rubocop managed in Gemfile with version-specific constraints
|
|
39
|
+
spec.add_development_dependency 'simplecov', '~> 0.21'
|
|
40
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
41
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
# Read the SimpleCov results
|
|
7
|
+
data = JSON.parse(File.read('coverage/.resultset.json'))
|
|
8
|
+
files = data['RSpec']['coverage']
|
|
9
|
+
|
|
10
|
+
results = []
|
|
11
|
+
files.each do |path, coverage|
|
|
12
|
+
next unless path.include?('lib/ruby-progress') && !path.include?('/bin/')
|
|
13
|
+
|
|
14
|
+
lines = coverage['lines'] || []
|
|
15
|
+
total = lines.compact.count
|
|
16
|
+
next if total.zero?
|
|
17
|
+
|
|
18
|
+
covered = lines.count { |l| l&.positive? }
|
|
19
|
+
pct = (covered * 100.0 / total).round(1)
|
|
20
|
+
short_path = path.split('ruby-progress/').last
|
|
21
|
+
results << { path: short_path, pct: pct, covered: covered, total: total }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
puts "\n=== Coverage Analysis by File ===\n\n"
|
|
25
|
+
puts "Files with lowest coverage (need attention):\n\n"
|
|
26
|
+
|
|
27
|
+
results.sort_by { |r| r[:pct] }.first(10).each do |r|
|
|
28
|
+
color = if r[:pct] < 30
|
|
29
|
+
"\e[31m"
|
|
30
|
+
else
|
|
31
|
+
r[:pct] < 60 ? "\e[33m" : "\e[32m"
|
|
32
|
+
end
|
|
33
|
+
reset = "\e[0m"
|
|
34
|
+
puts format("#{color}%6.1f%%#{reset} (%4d/%4d) %s", r[:pct], r[:covered], r[:total], r[:path])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
puts "\n\nFiles with highest coverage:\n\n"
|
|
38
|
+
results.sort_by { |r| -r[:pct] }.first(10).each do |r|
|
|
39
|
+
color = "\e[32m"
|
|
40
|
+
reset = "\e[0m"
|
|
41
|
+
puts format("#{color}%6.1f%%#{reset} (%4d/%4d) %s", r[:pct], r[:covered], r[:total], r[:path])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
total_lines = results.sum { |r| r[:total] }
|
|
45
|
+
total_covered = results.sum { |r| r[:covered] }
|
|
46
|
+
overall_pct = (total_covered * 100.0 / total_lines).round(2)
|
|
47
|
+
|
|
48
|
+
puts "\n\n=== Overall Coverage ===\n"
|
|
49
|
+
puts format('Total: %.2f%% (%d/%d lines)', overall_pct, total_covered, total_lines)
|
data/test_daemon.sh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Test daemon mode
|
|
4
|
+
echo "Starting twirl daemon..."
|
|
5
|
+
./bin/prg twirl --daemon-as test_twirl &
|
|
6
|
+
sleep 2
|
|
7
|
+
|
|
8
|
+
echo "Checking if daemon is running..."
|
|
9
|
+
ps aux | grep "[p]rg twirl" || echo "No daemon found"
|
|
10
|
+
|
|
11
|
+
echo "Checking PID files..."
|
|
12
|
+
ls -la ~/.prg/*.pid 2>/dev/null || echo "No PID files found"
|
|
13
|
+
|
|
14
|
+
echo "Stopping daemon..."
|
|
15
|
+
./bin/prg job send --daemon-name test_twirl
|
|
16
|
+
sleep 1
|
|
17
|
+
|
|
18
|
+
echo "Checking if daemon stopped..."
|
|
19
|
+
ps aux | grep "[p]rg twirl" || echo "Daemon stopped successfully"
|
|
20
|
+
ls -la ~/.prg/*.pid 2>/dev/null || echo "PID files cleaned up"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-progress
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brett Terpstra
|
|
@@ -65,20 +65,6 @@ dependencies:
|
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '3.0'
|
|
68
|
-
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: rubocop
|
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - "~>"
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: '1.21'
|
|
75
|
-
type: :development
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - "~>"
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: '1.21'
|
|
82
68
|
- !ruby/object:Gem::Dependency
|
|
83
69
|
name: simplecov
|
|
84
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -112,9 +98,11 @@ files:
|
|
|
112
98
|
- ".rubocop.yml"
|
|
113
99
|
- ".rubocop_todo.yml"
|
|
114
100
|
- CHANGELOG.md
|
|
101
|
+
- DAEMON_MODE.md
|
|
115
102
|
- DEMO_SCRIPTS.md
|
|
116
103
|
- Gemfile
|
|
117
104
|
- Gemfile.lock
|
|
105
|
+
- JOB_CLI_REFACTOR.md
|
|
118
106
|
- LICENSE
|
|
119
107
|
- README.md
|
|
120
108
|
- Rakefile
|
|
@@ -154,9 +142,12 @@ files:
|
|
|
154
142
|
- lib/ruby-progress/worm.rb
|
|
155
143
|
- quick_demo.rb
|
|
156
144
|
- readme_demo.rb
|
|
145
|
+
- ruby-progress.gemspec
|
|
157
146
|
- screencast
|
|
158
147
|
- screencast.svg
|
|
148
|
+
- scripts/coverage_analysis.rb
|
|
159
149
|
- scripts/run_matrix_mise.fish
|
|
150
|
+
- test_daemon.sh
|
|
160
151
|
- test_daemon_interruption.rb
|
|
161
152
|
- test_daemon_orphan.rb
|
|
162
153
|
- test_worm_flags.rb
|