starlined 0.1.1 → 0.1.2

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: a3f888548f69dc89b4370d0e53b5519de9801aea7c80b0afa082bd8e1b8eea7d
4
- data.tar.gz: c98ca5605a8fcfd7964dd83c092a6a4adc9099c46f45d98851e73a0347f74471
3
+ metadata.gz: 9d9ab3da983ad9f964ebb269a39173a8399167d485d8e01beea227677a9040a8
4
+ data.tar.gz: fe0167c40eada1ac3944504db6caf3039db6f092a888f64fbb58fa46ce1dc358
5
5
  SHA512:
6
- metadata.gz: 531927461b447b1def71be1a7fb01a4fd7776251edb6959a7a285cc9df91fecab449c2e891f07d21724f16180c7971e075d44e5e05e6a26567f7ad2868f4b3e6
7
- data.tar.gz: 6b2668fb896d46fb9824fb982a2f039bc6be83495c7d40dbde14d75df662601439306425bc8df9848006ac0e0976fd284a1663f1e9b780c5bc2ab2bb085297a1
6
+ metadata.gz: b121573babef094896871fa3a7542dbef69084616d6ff514314d994ce0aa3309cd5c4fbe1cc3ee34a0339ec42bc386aeeb251f29d04df33f83665869eca4503d
7
+ data.tar.gz: 9005aeeca2e28607cb2eac4829401e28a2203a4f82d860fb90c2e5a6dc9975eb8a0b5af3d5df648e51d2c763e4dfc08123f1ad2a7d216abc0d098d08b6febe0a
data/LICENSE.txt CHANGED
@@ -1,21 +1 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2024 Mier
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ Juan Mier <mier@mier.info>, CC-NC-BY-4.0
data/README.md CHANGED
@@ -1,148 +1,84 @@
1
- # Starlined
1
+ # starlined 🌟
2
2
 
3
- A Ruby gem that provides beautiful terminal output utilities with animated star progress indicators, colored messages, and command execution with visual feedback.
3
+ terminal output gem with animated stars, colored messages, and progress tracking.
4
4
 
5
- ## Features
6
-
7
- - 🌟 **Animated Progress Indicators** - Beautiful star animations that move while commands execute
8
- - 🎨 **Colored Messages** - Error, info, warning, and success messages with appropriate colors
9
- - 🔄 **Thread-Safe Operations** - Safe to use with parallel command execution
10
- - ⚡ **Command Runner** - Execute shell commands with automatic progress animation
11
- - 🔧 **Highly Configurable** - Customize animation speed, message formatting, and more
12
-
13
- ## Installation
14
-
15
- Add this line to your application's Gemfile:
5
+ ## install
16
6
 
17
7
  ```ruby
18
8
  gem 'starlined'
19
9
  ```
20
10
 
21
- And then execute:
22
-
23
- ```bash
24
- bundle install
25
- ```
26
-
27
- Or install it yourself as:
28
-
29
- ```bash
30
- gem install starlined
31
- ```
32
-
33
- ## Usage
11
+ ## usage
34
12
 
35
- ### Basic Message Output
13
+ ### basic messages
36
14
 
37
15
  ```ruby
38
16
  require 'starlined'
39
-
40
- # include the messages module for easy access
41
17
  include Starlined::Messages
42
18
 
43
- # display various message types
44
- info("Starting application...")
45
- warn("Configuration file not found, using defaults")
46
- error("Connection failed", "Database timeout")
47
- success("Build completed", 3.5) # with elapsed time
48
- verbose("Debug information") # only shown if verbose mode is enabled
19
+ info "Starting deployment"
20
+ warn "Config file missing"
21
+ error "Connection failed"
22
+ success "Build complete", 3.5 # with elapsed time
49
23
  ```
50
24
 
51
- ### Animated Command Execution
25
+ ### run with animation (sequentially)
52
26
 
53
27
  ```ruby
54
28
  runner = Starlined::Runner.new
29
+ runner.start("Installing deps", steps: 3)
55
30
 
56
- # start an animation with a message
57
- runner.start("Installing dependencies", steps: 3)
58
-
59
- # run commands with animation
60
31
  runner.run("bundle install", aka: "bundler")
61
32
  runner.run("npm install", aka: "npm")
62
- runner.run("rake db:migrate", aka: "migrations")
33
+ runner.run("rake db:migrate", aka: "database")
63
34
 
64
- # stop animation and show success
65
35
  runner.stop
66
36
  ```
67
37
 
68
- ### Interactive Input
38
+ The `aka` parameter shows what's currently running in the animation.
69
39
 
70
- ```ruby
71
- include Starlined::Messages
72
-
73
- response = ask("What's your project name?")
74
- puts "Creating project: #{response}"
75
- ```
76
-
77
- ### Configuration
78
-
79
- ```ruby
80
- Starlined.configure do |config|
81
- config.verbose = true # enable verbose output
82
- config.sleep_time = 0.5 # animation speed (seconds)
83
- config.msg_ljust = 40 # message padding
84
- config.stars_range = (0..7) # animation width
85
- end
86
- ```
87
-
88
- ### Advanced Usage with Parallel Execution
40
+ ### run in parallel
89
41
 
90
42
  ```ruby
91
43
  runner = Starlined::Runner.new
92
44
  runner.start("Running tests", steps: 3)
93
45
 
94
46
  threads = []
95
- threads << Thread.new { runner.run("rspec spec/models", aka: "models") }
96
- threads << Thread.new { runner.run("rspec spec/controllers", aka: "controllers") }
97
- threads << Thread.new { runner.run("rspec spec/helpers", aka: "helpers") }
98
-
47
+ threads << Thread.new { runner.run("rspec spec/models") }
48
+ threads << Thread.new { runner.run("rspec spec/controllers") }
49
+ threads << Thread.new { runner.run("rspec spec/features") }
99
50
  threads.each(&:join)
51
+
100
52
  runner.stop
101
53
  ```
102
54
 
103
- ### Using Animation Directly
55
+ ### animation manipulation/control
104
56
 
105
57
  ```ruby
106
- animation = Starlined::Animation.new("Processing files", steps: 100)
58
+ animation = Starlined::Animation.new("Processing", steps: 100)
107
59
  animation.start
108
60
 
109
61
  100.times do |i|
110
- # do some work
111
- sleep(0.1)
62
+ # do work
112
63
  animation.increment_step
113
64
  animation.add_alias("file_#{i}.txt")
114
- # more work
65
+ sleep 0.1
115
66
  animation.remove_alias("file_#{i}.txt")
116
67
  end
117
68
 
118
69
  animation.stop
119
70
  ```
120
71
 
121
- ## Configuration Options
122
-
123
- | Option | Default | Description |
124
- |--------|---------|-------------|
125
- | `sleep_time` | `0.75` | Time between animation frames (seconds) |
126
- | `msg_ljust` | `30` | Left padding for messages |
127
- | `extra_rjust` | `8` | Right padding for extra info |
128
- | `stars_range` | `(0..5)` | Range for star animation positions |
129
- | `verbose` | `false` | Enable verbose output |
130
- | `clear_line_string` | `"\33[2K"` | ANSI code to clear terminal line |
131
-
132
- ## Development
133
-
134
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
72
+ ### custom configuration
135
73
 
136
- To install this gem onto your local machine, run `bundle exec rake install`.
137
-
138
- ## Contributing
139
-
140
- Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/starlined.
141
-
142
- ## License
143
-
144
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+ ```ruby
75
+ Starlined.configure do |config|
76
+ config.vrbose = true # show verbose messages
77
+ config.sleep_time = 0.5 # animation speed
78
+ config.msg_ljust = 40 # message padding
79
+ end
80
+ ```
145
81
 
146
- ## Author
82
+ ## license
147
83
 
148
- Created by Mier - Extracted from the Okticket builder script utilities.
84
+ CC-NC-BY-4.0, open-sourced from [okticket](https://okticket.es)
@@ -19,10 +19,10 @@ sleep(1)
19
19
 
20
20
  # configurar modo verbose
21
21
  Starlined.configure do |config|
22
- config.verbose = true
22
+ config.vrbose = true
23
23
  end
24
24
 
25
- verbose("This verbose message is now visible")
25
+ vrbose("This verbose message is now visible")
26
26
  sleep(1)
27
27
 
28
28
  # ejemplo con error (comentado para no salir del programa)
@@ -7,7 +7,7 @@ module Starlined
7
7
  attr_reader :thread, :message, :start_time, :steps, :current_steps
8
8
  attr_accessor :aliases
9
9
 
10
- def initialize(message = "Booting up", steps = 0)
10
+ def initialize(message = 'Booting up', steps = 0)
11
11
  @message = message
12
12
  @start_time = Time.now
13
13
  @steps = steps
@@ -17,13 +17,12 @@ module Starlined
17
17
  @pos = [0, 1, 2]
18
18
  @move = 1
19
19
 
20
- # manejo de aliases
20
+ # manejo de alias
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
27
26
  @steps_semaphore = Mutex.new
28
27
 
29
28
  @running = false
@@ -32,12 +31,14 @@ module Starlined
32
31
 
33
32
  def start
34
33
  return if @running
34
+
35
35
  @running = true
36
36
  @thread = Thread.new { animation_loop }
37
37
  end
38
38
 
39
39
  def stop
40
40
  return unless @running
41
+
41
42
  @running = false
42
43
  @thread&.kill
43
44
  @thread = nil
@@ -51,15 +52,17 @@ module Starlined
51
52
 
52
53
  def add_alias(aka)
53
54
  return if aka.nil?
55
+
54
56
  @alias_semaphore.synchronize { @aliases.push(aka) }
55
57
  end
56
58
 
57
59
  def remove_alias(aka)
58
60
  return if aka.nil?
61
+
59
62
  @alias_semaphore.synchronize do
60
63
  @aliases.delete(aka)
61
64
  # ajustar el puntero si se eliminó un elemento antes de la posición actual
62
- @alias_pointer = 0 if @alias_pointer >= @aliases.length && @aliases.length > 0
65
+ @alias_pointer = 0 if @alias_pointer >= @aliases.length && !@aliases.empty?
63
66
  end
64
67
  end
65
68
 
@@ -87,16 +90,16 @@ module Starlined
87
90
  end
88
91
 
89
92
  def build_stars
90
- stars = ""
93
+ stars = ''
91
94
  config = Starlined.configuration
92
95
 
93
96
  config.stars_range.each do |i|
94
- if !@pos.include?(i)
95
- stars += " "
96
- elsif i == @pos[1]
97
- stars += "*".bold.red
98
- else
99
- stars += "*".yellow
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
100
103
  end
101
104
  end
102
105
 
@@ -3,15 +3,16 @@
3
3
  module Starlined
4
4
  class Configuration
5
5
  attr_accessor :sleep_time, :msg_ljust, :extra_rjust, :stars_range,
6
- :verbose, :clear_line_string
6
+ :vrbose, :clear_line_string, :symbol
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
- @verbose = false
13
+ @vrbose = false
14
14
  @clear_line_string = "\33[2K"
15
+ @symbol = '*'
15
16
  end
16
17
  end
17
18
  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,41 +8,42 @@ 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 verbose(message)
37
- return unless Starlined.configuration.verbose
36
+ def vrbose(message)
37
+ return unless Starlined.configuration.vrbose
38
+
38
39
  clear_line
39
- puts "\r[#{"VRBOSE".light_black}] #{message}"
40
+ puts "\r[#{'VRBOSE'.light_black}] #{message}"
40
41
  end
41
42
 
42
43
  def ask(prompt)
43
44
  clear_line
44
- print "\r[ #{"??".light_blue} ] #{prompt}: "
45
- STDIN.gets.chomp
45
+ print "\r[ #{'??'.light_blue} ] #{prompt}: "
46
+ $stdin.gets.chomp
46
47
  end
47
48
 
48
49
  private
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "open3"
4
- require "colorize"
3
+ require 'open3'
4
+ require 'colorize'
5
5
 
6
6
  module Starlined
7
7
  class Runner
@@ -26,40 +26,28 @@ module Starlined
26
26
  stop_animation
27
27
  end
28
28
 
29
- def run(command, print_err = true, aka: nil, no_count: false)
30
- needs_sudo = !!(command =~ /^sudo/)
31
-
32
- execute(
33
- -> { Open3.capture3(command) },
34
- print_err,
35
- aka: aka,
36
- no_count: no_count,
37
- sudo: needs_sudo,
38
- )
39
- end
40
-
41
- def execute(callback, print_err = true, aka: nil, no_count: false, sudo: false)
42
- handle_sudo if sudo
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
+ def run(command, print_err: true, aka: nil, no_count: false)
36
+ handle_sudo if !!(command =~ /^sudo/)
43
37
 
44
38
  @run_semaphore.synchronize do
45
39
  @animation&.add_alias(aka) unless aka.nil?
46
-
47
- if @run_instances == 0 && @animation
48
- @animation.start
49
- end
40
+ @animation.start if @run_instances.zero? && @animation
50
41
  @run_instances += 1
51
42
  end
52
43
 
53
- result = callback.call
44
+ result = -> { Open3.capture3(command) }.call
54
45
 
55
46
  @run_semaphore.synchronize do
56
47
  @run_instances -= 1
57
48
  @animation&.increment_step unless no_count
58
49
  @animation&.remove_alias(aka) unless aka.nil?
59
-
60
- if @run_instances == 0 && @animation
61
- @animation.stop
62
- end
50
+ @animation.stop if @run_instances.zero? && @animation
63
51
  end
64
52
 
65
53
  handle_error(result, print_err) unless result.last.success?
@@ -75,23 +63,22 @@ module Starlined
75
63
  end
76
64
 
77
65
  def handle_sudo
78
- needs_password = !system("sudo -n true &>/dev/null")
66
+ needs_password = !system('sudo -n true &>/dev/null')
67
+ return unless needs_password || RUBY_PLATFORM.include?('darwin')
79
68
 
80
- if needs_password || RUBY_PLATFORM.include?("darwin")
81
- stop_animation
69
+ stop_animation
82
70
 
83
- if needs_password
84
- # alertar al usuario con diferentes métodos
85
- print "\a" # terminal bell
86
- system("tput bel 2>/dev/null") # alternative bell
87
- Messages.info("Password required")
88
- end
71
+ if needs_password
72
+ # alertar al usuario con diferentes métodos
73
+ print "\a" # terminal bell
74
+ system('tput bel 2>/dev/null') # alternative bell
75
+ Messages.info('Password required')
76
+ end
89
77
 
90
- result = system("sudo -v")
91
- raise "Sudo privileges not granted" unless result
78
+ result = system('sudo -v')
79
+ raise 'Sudo privileges not granted' unless result
92
80
 
93
- @animation&.start if @run_instances != 0
94
- end
81
+ @animation&.start if @run_instances != 0
95
82
  end
96
83
 
97
84
  def handle_error(result, print_err)
@@ -99,11 +86,9 @@ module Starlined
99
86
 
100
87
  stop_animation
101
88
  Messages.error(nil, @animation&.message)
89
+ puts result[1].empty? ? result[0] : result[1] # stdout si stderr está vacío
102
90
 
103
- puts result[1] # stderr
104
- puts result[0] if result[1].empty? # stdout si stderr está vacío
105
-
106
- Messages.verbose("Exit code: #{result.last.exitstatus}")
91
+ Messages.vrbose("Exit code: #{result.last.exitstatus}")
107
92
  exit 1
108
93
  end
109
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Starlined
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
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
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "Terminal output utilities with animated progress indicators"
12
12
  spec.homepage = "https://github.com/miermontoto/starlined"
13
- spec.license = "MIT"
13
+ spec.license = "CC-NC-BY-4.0"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mier
@@ -117,7 +117,7 @@ files:
117
117
  - starlined.gemspec
118
118
  homepage: https://github.com/miermontoto/starlined
119
119
  licenses:
120
- - MIT
120
+ - CC-NC-BY-4.0
121
121
  metadata:
122
122
  homepage_uri: https://github.com/miermontoto/starlined
123
123
  source_code_uri: https://github.com/miermontoto/starlined