starlined 0.1.2 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d9ab3da983ad9f964ebb269a39173a8399167d485d8e01beea227677a9040a8
4
- data.tar.gz: fe0167c40eada1ac3944504db6caf3039db6f092a888f64fbb58fa46ce1dc358
3
+ metadata.gz: '08105cc16591e81bcd8f4b04173b0fb16154753fc2386433760fdc075444d797'
4
+ data.tar.gz: 2051129391c16c7eec09b2f676b119e7c76307f17c93a7d43213105c98af1f3e
5
5
  SHA512:
6
- metadata.gz: b121573babef094896871fa3a7542dbef69084616d6ff514314d994ce0aa3309cd5c4fbe1cc3ee34a0339ec42bc386aeeb251f29d04df33f83665869eca4503d
7
- data.tar.gz: 9005aeeca2e28607cb2eac4829401e28a2203a4f82d860fb90c2e5a6dc9975eb8a0b5af3d5df648e51d2c763e4dfc08123f1ad2a7d216abc0d098d08b6febe0a
6
+ metadata.gz: ec265f48d253cdb7bb169aec85e898307d9e4b32c75e46b8edac283fe2aee8c1af437ad6a343c7aaddacd9fd7c828da80dca2d7269f202193ff3155bf9aafb96
7
+ data.tar.gz: 1edc1a126b7efd1b8dbf7e975c1e1f34e33cd10e0ea02b30692ad5635287c58a46c3f4e60ca243dae9df8d0a257aaaaf85a8bc328c54ae0db180943d176904b0
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # especificación del gemspec
6
6
  gemspec
7
7
 
8
8
  group :development do
9
- gem "pry"
10
- gem "yard"
9
+ gem 'pry'
10
+ gem 'yard'
11
11
  end
data/README.md CHANGED
@@ -52,28 +52,11 @@ threads.each(&:join)
52
52
  runner.stop
53
53
  ```
54
54
 
55
- ### animation manipulation/control
56
-
57
- ```ruby
58
- animation = Starlined::Animation.new("Processing", steps: 100)
59
- animation.start
60
-
61
- 100.times do |i|
62
- # do work
63
- animation.increment_step
64
- animation.add_alias("file_#{i}.txt")
65
- sleep 0.1
66
- animation.remove_alias("file_#{i}.txt")
67
- end
68
-
69
- animation.stop
70
- ```
71
-
72
55
  ### custom configuration
73
56
 
74
57
  ```ruby
75
58
  Starlined.configure do |config|
76
- config.vrbose = true # show verbose messages
59
+ config.verbose = true # show verbose messages
77
60
  config.sleep_time = 0.5 # animation speed
78
61
  config.msg_ljust = 40 # message padding
79
62
  end
data/Rakefile CHANGED
@@ -1,31 +1,137 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require_relative 'lib/starlined/version'
5
5
 
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
6
+ begin
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ task default: :spec
10
+ rescue LoadError
11
+ # rspec not available
12
+ end
9
13
 
10
- desc "Run all examples"
14
+ desc 'Run all examples'
11
15
  task :examples do
12
- Dir["examples/*.rb"].each do |example|
16
+ Dir['examples/*.rb'].each do |example|
13
17
  puts "\n📝 Running: #{example}"
14
- puts "=" * 50
18
+ puts '=' * 50
15
19
  system("ruby #{example}")
16
- puts "=" * 50
20
+ puts '=' * 50
17
21
  end
18
22
  end
19
23
 
20
- desc "Open an interactive console with the gem loaded"
24
+ desc 'Open an interactive console with the gem loaded'
21
25
  task :console do
22
- require "pry"
23
- require_relative "lib/starlined"
26
+ require 'pry'
27
+ require_relative 'lib/starlined'
24
28
  include Starlined::Messages
25
29
  runner = Starlined::Runner.new
26
- puts "Starlined loaded! Available:"
27
- puts " - Messages module included (info, warn, error, success, etc.)"
28
- puts " - runner = Starlined::Runner.new"
29
- puts " - Starlined::Animation"
30
+ puts 'Starlined loaded! Available:'
31
+ puts ' - Messages module included (info, warn, error, success, etc.)'
32
+ puts ' - runner = Starlined::Runner.new'
33
+ puts ' - Starlined::Animation'
30
34
  Pry.start
31
35
  end
36
+
37
+ # Version management tasks
38
+ namespace :version do
39
+ desc 'Show current version'
40
+ task :current do
41
+ puts "Current version: #{Starlined::VERSION}"
42
+ end
43
+
44
+ def bump_version(type)
45
+ version_file = 'lib/starlined/version.rb'
46
+ content = File.read(version_file)
47
+
48
+ current_version = Starlined::VERSION
49
+ major, minor, patch = current_version.split('.').map(&:to_i)
50
+
51
+ case type
52
+ when :major
53
+ new_version = "#{major + 1}.0.0"
54
+ when :minor
55
+ new_version = "#{major}.#{minor + 1}.0"
56
+ when :patch
57
+ new_version = "#{major}.#{minor}.#{patch + 1}"
58
+ end
59
+
60
+ new_content = content.gsub(/VERSION = ['"]#{Regexp.escape(current_version)}['"]/, "VERSION = '#{new_version}'")
61
+ File.write(version_file, new_content)
62
+
63
+ puts "Version bumped from #{current_version} to #{new_version}"
64
+ new_version
65
+ end
66
+
67
+ desc 'Bump major version (x.0.0)'
68
+ task :major do
69
+ bump_version(:major)
70
+ end
71
+
72
+ desc 'Bump minor version (0.x.0)'
73
+ task :minor do
74
+ bump_version(:minor)
75
+ end
76
+
77
+ desc 'Bump patch version (0.0.x)'
78
+ task :patch do
79
+ bump_version(:patch)
80
+ end
81
+ end
82
+
83
+ # Release tasks
84
+ namespace :release do
85
+ def release(type)
86
+ # Bump version
87
+ puts "📝 Bumping #{type} version..."
88
+ new_version = nil
89
+ Rake::Task["version:#{type}"].invoke
90
+
91
+ # Reload version
92
+ load 'lib/starlined/version.rb'
93
+ new_version = Starlined::VERSION
94
+
95
+ # Build gem
96
+ puts "\n📦 Building gem..."
97
+ system('gem build starlined.gemspec') or abort('Build failed!')
98
+
99
+ # Ask for confirmation before pushing
100
+ print "\n🚀 Push starlined-#{new_version}.gem to RubyGems? (y/n): "
101
+ response = STDIN.gets.chomp.downcase
102
+
103
+ if response == 'y'
104
+ puts 'Pushing to RubyGems...'
105
+ system("gem push starlined-#{new_version}.gem") or abort('Push failed!')
106
+ puts "\n✅ Successfully released version #{new_version}!"
107
+ else
108
+ puts '❌ Push cancelled. Gem built but not pushed.'
109
+ puts " You can manually push with: gem push starlined-#{new_version}.gem"
110
+ end
111
+ end
112
+
113
+ desc 'Release new major version (x.0.0)'
114
+ task :major do
115
+ release(:major)
116
+ end
117
+
118
+ desc 'Release new minor version (0.x.0)'
119
+ task :minor do
120
+ release(:minor)
121
+ end
122
+
123
+ desc 'Release new patch version (0.0.x)'
124
+ task :patch do
125
+ release(:patch)
126
+ end
127
+ end
128
+
129
+ # Quick release aliases
130
+ desc 'Release patch version (alias for release:patch)'
131
+ task patch: 'release:patch'
132
+
133
+ desc 'Release minor version (alias for release:minor)'
134
+ task minor: 'release:minor'
135
+
136
+ desc 'Release major version (alias for release:major)'
137
+ task major: 'release:major'
@@ -19,10 +19,10 @@ sleep(1)
19
19
 
20
20
  # configurar modo verbose
21
21
  Starlined.configure do |config|
22
- config.vrbose = true
22
+ config.verbose = true
23
23
  end
24
24
 
25
- vrbose("This verbose message is now visible")
25
+ verbose("This verbose message is now visible")
26
26
  sleep(1)
27
27
 
28
28
  # ejemplo con error (comentado para no salir del programa)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "colorize"
3
+ require 'colorize'
4
4
 
5
5
  module Starlined
6
6
  class Animation
@@ -17,12 +17,13 @@ module Starlined
17
17
  @pos = [0, 1, 2]
18
18
  @move = 1
19
19
 
20
- # manejo de alias
20
+ # manejo de aliases
21
21
  @aliases = []
22
22
  @alias_pointer = 0
23
23
  @alias_timer = 0
24
24
  @alias_semaphore = Mutex.new
25
25
 
26
+ # semáforo para pasos
26
27
  @steps_semaphore = Mutex.new
27
28
 
28
29
  @running = false
@@ -94,13 +95,13 @@ module Starlined
94
95
  config = Starlined.configuration
95
96
 
96
97
  config.stars_range.each do |i|
97
- if !@pos.include?(i) # caso: posición vacía
98
- stars += ' '
99
- elsif i == @pos[1] # caso: estrella central
100
- stars += config.symbol.bold.red
101
- else # caso: estrellas laterales
102
- stars += config.symbol.yellow
103
- end
98
+ stars += if !@pos.include?(i)
99
+ ' '
100
+ elsif i == @pos[1]
101
+ '*'.bold.red
102
+ else
103
+ '*'.yellow
104
+ end
104
105
  end
105
106
 
106
107
  stars
@@ -121,12 +122,12 @@ module Starlined
121
122
 
122
123
  def current_alias_string
123
124
  @alias_semaphore.synchronize do
124
- return "" if @aliases.empty?
125
+ return '' if @aliases.empty?
125
126
 
126
127
  begin
127
128
  @aliases[@alias_pointer].to_s
128
129
  rescue NoMethodError, ArgumentError
129
- @aliases.first.to_s if @aliases.length > 0
130
+ @aliases.first.to_s unless @aliases.empty?
130
131
  end
131
132
  end
132
133
  end
@@ -138,8 +139,11 @@ module Starlined
138
139
  @pos = @pos.map { |p| (p + @move) % config.stars_range.length }
139
140
 
140
141
  # cambiar el sentido de movimiento si se toca alguno de los bordes
141
- @move = @pos.first == config.stars_range.first ? 1 :
142
- @pos.last == config.stars_range.last ? -1 : @move
142
+ @move = if @pos.first == config.stars_range.first
143
+ 1
144
+ else
145
+ @pos.last == config.stars_range.last ? -1 : @move
146
+ end
143
147
  end
144
148
 
145
149
  def update_alias_timer
@@ -3,16 +3,15 @@
3
3
  module Starlined
4
4
  class Configuration
5
5
  attr_accessor :sleep_time, :msg_ljust, :extra_rjust, :stars_range,
6
- :vrbose, :clear_line_string, :symbol
6
+ :verbose, :clear_line_string
7
7
 
8
8
  def initialize
9
9
  @sleep_time = 0.75
10
10
  @msg_ljust = 30
11
11
  @extra_rjust = 8
12
12
  @stars_range = (0..5).to_a
13
- @vrbose = false
13
+ @verbose = false
14
14
  @clear_line_string = "\33[2K"
15
- @symbol = '*'
16
15
  end
17
16
  end
18
17
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'colorize'
3
+ require "colorize"
4
4
 
5
5
  module Starlined
6
6
  module Messages
@@ -8,42 +8,41 @@ module Starlined
8
8
 
9
9
  def error(message = nil, context = nil)
10
10
  clear_line
11
- output = "\r[#{'FAILED'.red}] #{context || 'Operation failed'}"
11
+ output = "\r[#{"FAILED".red}] #{context || "Operation failed"}"
12
12
  output += " (#{message})" unless message.nil?
13
13
  puts output
14
14
  end
15
15
 
16
16
  def info(message)
17
17
  clear_line
18
- puts "\r[ #{'INFO'.blue} ] #{message}"
18
+ puts "\r[ #{"INFO".blue} ] #{message}"
19
19
  end
20
20
 
21
21
  def warn(message)
22
22
  clear_line
23
- puts "\r[ #{'WARN'.yellow} ] #{message}"
23
+ puts "\r[ #{"WARN".yellow} ] #{message}"
24
24
  end
25
25
 
26
26
  def success(message, time = nil)
27
27
  clear_line
28
- output = "\r[ #{'OK'.green} ] #{message}"
28
+ output = "\r[ #{"OK".green} ] #{message}"
29
29
  if time
30
- dots = '.' * [3, 36 - message.length - time.to_s.length].max
30
+ dots = "." * [3, 36 - message.length - time.to_s.length].max
31
31
  output += " #{dots.bold.gray} #{time}s"
32
32
  end
33
33
  puts output
34
34
  end
35
35
 
36
- def vrbose(message)
37
- return unless Starlined.configuration.vrbose
38
-
36
+ def verbose(message)
37
+ return unless Starlined.configuration.verbose
39
38
  clear_line
40
- puts "\r[#{'VRBOSE'.light_black}] #{message}"
39
+ puts "\r[#{"VRBOSE".light_black}] #{message}"
41
40
  end
42
41
 
43
42
  def ask(prompt)
44
43
  clear_line
45
- print "\r[ #{'??'.light_blue} ] #{prompt}: "
46
- $stdin.gets.chomp
44
+ print "\r[ #{"??".light_blue} ] #{prompt}: "
45
+ STDIN.gets.chomp
47
46
  end
48
47
 
49
48
  private
@@ -8,15 +8,14 @@ module Starlined
8
8
  attr_reader :animation
9
9
 
10
10
  def initialize
11
- @run_instances = 0
11
+ @running_instances = 0
12
12
  @run_semaphore = Mutex.new
13
13
  @animation = nil
14
14
  end
15
15
 
16
16
  def start(message, steps: 0)
17
- stop_animation if @animation
17
+ stop_animation
18
18
  @animation = Animation.new(message, steps)
19
- @animation
20
19
  end
21
20
 
22
21
  def stop
@@ -26,38 +25,60 @@ module Starlined
26
25
  stop_animation
27
26
  end
28
27
 
29
- # Función que se encarga de ejecutar comandos y mostrar animaciones por pantalla.
30
- # Utiliza un hilo separado para las animaciones y comprueba el exitcode de los callbacks
31
- # para detectar errores. Si se ejecutan múltiples instancias de manera simultánea
32
- # (como cuando se ejecutan comandos en paralelo), se utiliza un semáforo para controlar
33
- # que no se creen más de un hilo de animación. Si se ejecuta un comando que requiere
34
- # permisos de sudo, detecta si necesita contraseña y para la animación según corresponda.
35
28
  def run(command, print_err: true, aka: nil, no_count: false)
36
- handle_sudo if !!(command =~ /^sudo/)
29
+ needs_sudo = !!(command =~ /^sudo/)
30
+
31
+ execute(
32
+ -> { Open3.capture3(command) },
33
+ print_err,
34
+ aka: aka,
35
+ no_count: no_count,
36
+ sudo: needs_sudo
37
+ )
38
+ end
37
39
 
40
+ def pass_step
41
+ start_step
42
+ end
43
+
44
+ private
45
+
46
+ def start_step(aka: nil)
38
47
  @run_semaphore.synchronize do
39
48
  @animation&.add_alias(aka) unless aka.nil?
40
- @animation.start if @run_instances.zero? && @animation
41
- @run_instances += 1
49
+
50
+ @animation.start if @running_instances.zero? && @animation
51
+ @running_instances += 1
42
52
  end
43
53
 
44
- result = -> { Open3.capture3(command) }.call
54
+ @running_instances
55
+ end
45
56
 
57
+ def end_step(aka: nil, no_count: false)
46
58
  @run_semaphore.synchronize do
47
- @run_instances -= 1
59
+ @running_instances -= 1
48
60
  @animation&.increment_step unless no_count
49
61
  @animation&.remove_alias(aka) unless aka.nil?
50
- @animation.stop if @run_instances.zero? && @animation
62
+
63
+ @animation.stop if @running_instances.zero? && @animation
51
64
  end
65
+ end
66
+
67
+ def execute(callback, print_err: true, aka: nil, no_count: false, sudo: false)
68
+ handle_sudo if sudo
69
+
70
+ start_step(aka: aka)
71
+ result = callback.call
72
+ end_step(aka: aka, no_count: no_count)
52
73
 
53
74
  handle_error(result, print_err) unless result.last.success?
54
75
 
55
76
  result
56
77
  end
57
78
 
58
- private
59
-
60
79
  def stop_animation
80
+ return unless @animation
81
+
61
82
  @animation&.stop
62
83
  @animation = nil
63
84
  end
@@ -78,7 +99,7 @@ module Starlined
78
99
  result = system('sudo -v')
79
100
  raise 'Sudo privileges not granted' unless result
80
101
 
81
- @animation&.start if @run_instances != 0
102
+ @animation&.start unless @running_instances.zero?
82
103
  end
83
104
 
84
105
  def handle_error(result, print_err)
@@ -86,9 +107,11 @@ module Starlined
86
107
 
87
108
  stop_animation
88
109
  Messages.error(nil, @animation&.message)
89
- puts result[1].empty? ? result[0] : result[1] # stdout si stderr está vacío
90
110
 
91
- Messages.vrbose("Exit code: #{result.last.exitstatus}")
111
+ puts result[1] # stderr
112
+ puts result[0] if result[1].empty? # stdout si stderr está vacío
113
+
114
+ Messages.verbose("Exit code: #{result.last.exitstatus}")
92
115
  exit 1
93
116
  end
94
117
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Starlined
4
- VERSION = "0.1.2"
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/starlined.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'open3'
4
- require 'colorize'
3
+ require "open3"
4
+ require "colorize"
5
5
 
6
- require_relative 'starlined/version'
7
- require_relative 'starlined/configuration'
8
- require_relative 'starlined/animation'
9
- require_relative 'starlined/messages'
10
- require_relative 'starlined/runner'
6
+ require_relative "starlined/version"
7
+ require_relative "starlined/configuration"
8
+ require_relative "starlined/animation"
9
+ require_relative "starlined/messages"
10
+ require_relative "starlined/runner"
11
11
 
12
12
  module Starlined
13
13
  class << self
data/starlined.gemspec CHANGED
@@ -1,36 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/starlined/version"
3
+ require_relative 'lib/starlined/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "starlined"
6
+ spec.name = 'starlined'
7
7
  spec.version = Starlined::VERSION
8
- spec.authors = ["mier"]
9
- spec.email = ["ruby@mier.info"]
8
+ spec.authors = ['mier']
9
+ spec.email = ['ruby@mier.info']
10
10
 
11
- spec.summary = "Terminal output utilities with animated progress indicators"
12
- spec.homepage = "https://github.com/miermontoto/starlined"
13
- spec.license = "CC-NC-BY-4.0"
14
- spec.required_ruby_version = ">= 2.6.0"
11
+ spec.summary = 'Terminal output utilities with animated progress indicators'
12
+ spec.homepage = 'https://github.com/miermontoto/starlined'
13
+ spec.license = 'CC-NC-BY-4.0'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
15
 
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
18
 
19
19
  # especificar qué archivos deben incluirse en el gem
20
20
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
21
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
22
22
  end
23
- spec.bindir = "exe"
23
+ spec.bindir = 'exe'
24
24
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
25
+ spec.require_paths = ['lib']
26
26
 
27
27
  # dependencias en tiempo de ejecución
28
- spec.add_dependency "colorize", ">= 0.8"
28
+ spec.add_dependency 'colorize', '>= 0.8'
29
29
 
30
30
  # dependencias de desarrollo
31
- spec.add_development_dependency "bundler", "~> 2.0"
32
- spec.add_development_dependency "rake", "~> 13.0"
33
- spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "rubocop", "~> 1.0"
35
- spec.add_development_dependency "simplecov", "~> 0.21"
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 1.0'
35
+ spec.add_development_dependency 'simplecov', '~> 0.21'
36
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starlined
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mier
@@ -101,7 +101,6 @@ extra_rdoc_files: []
101
101
  files:
102
102
  - ".gitignore"
103
103
  - Gemfile
104
- - LICENSE.txt
105
104
  - README.md
106
105
  - Rakefile
107
106
  - examples/animated_commands.rb
data/LICENSE.txt DELETED
@@ -1 +0,0 @@
1
- Juan Mier <mier@mier.info>, CC-NC-BY-4.0