starlined 0.2.4 → 0.2.7

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: d8752698ed43ee158c8555688abd26f748631e99e9cbb3f07be23ee9712a281d
4
- data.tar.gz: f58a4a33b3850c8ba79b2d06ef32ad5d6d88850b5995127b349e8ebc87e7d977
3
+ metadata.gz: e1d1051ec7e3bbb187be26b08945792e7838eba17a02a8e7ac99d740d2d1ee3b
4
+ data.tar.gz: 95ca8766b86583470c000f8c487f5d7798371329eaf428cd0af208c20449287b
5
5
  SHA512:
6
- metadata.gz: 45635e40d8f6bc8902de2f7c5200d555340946af45484c0af94d7198066a48a2f7061ef785f9093712939c146e799f5abbaa50ef4570caf4ead623f04c9f6af4
7
- data.tar.gz: 6ebbb8ed5b0d494c6c1162dfd6eba6bd33e4e86616925bb115de53ba9631342583dd076580ca2368e7fecf98ba71b3cf715ea05b836d76affa6d3cc8c5d5d05e
6
+ metadata.gz: 42405d2736503fe09ed8c8b778a577d4dfe206e257c9e0bc0d7082fa8bdbc5b5c6e435ccdbd3db05c8186c26b5ad34fa59fb1ab50a36e5eea353ccf49eb62187
7
+ data.tar.gz: 6c637fd92646be7c03a02c0e60b35ad25a9fdd48765c4e0b7d8749b8dc1d7bb8cb94d2508ce827266d236a28064d1d2bdeb5384db9822257c3d0894ea961f393
@@ -1,12 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'colorize'
4
+ require 'io/console'
4
5
 
5
6
  module Starlined
6
7
  class Animation
7
- attr_reader :thread, :message, :start_time, :steps, :current_steps
8
+ attr_reader :thread, :message, :start_time, :steps, :current_steps, :last_lines
8
9
  attr_accessor :aliases
9
10
 
11
+ # líneas pendientes de limpiar (persiste entre instancias para que Messages pueda acceder)
12
+ @pending_clear_lines = 1
13
+ class << self
14
+ attr_accessor :pending_clear_lines
15
+ end
16
+
10
17
  def initialize(message = 'Booting up', steps = 0)
11
18
  @message = message
12
19
  @start_time = Time.now
@@ -26,6 +33,9 @@ module Starlined
26
33
  # semáforo para pasos
27
34
  @steps_semaphore = Mutex.new
28
35
 
36
+ # líneas visuales que ocupa la última impresión
37
+ @last_lines = 1
38
+
29
39
  @running = false
30
40
  @thread = nil
31
41
  end
@@ -81,7 +91,10 @@ module Starlined
81
91
  extra = build_extra_info
82
92
 
83
93
  clear_line
84
- print "\r[#{stars}] #{@message.ljust(config.msg_ljust)} #{extra}"
94
+ output = "[#{stars}] #{@message.ljust(config.msg_ljust)} #{extra}"
95
+ print "\r#{output}"
96
+ @last_lines = visible_line_count(output)
97
+ self.class.pending_clear_lines = @last_lines
85
98
 
86
99
  move_stars
87
100
  update_alias_timer
@@ -159,7 +172,25 @@ module Starlined
159
172
  end
160
173
 
161
174
  def clear_line
162
- print "\r#{Starlined.configuration.clear_line_string}"
175
+ clear = Starlined.configuration.clear_line_string
176
+ # limpiar cada línea visual que ocupó la última impresión
177
+ (@last_lines - 1).times { print "\e[1A#{clear}" }
178
+ print "\r#{clear}"
179
+ end
180
+
181
+ def visible_line_count(str)
182
+ cols = terminal_columns
183
+ return 1 if cols <= 0
184
+
185
+ # longitud visible sin escape sequences ANSI
186
+ visible = str.gsub(/\e\[[0-9;]*m/, '')
187
+ [(visible.length.to_f / cols).ceil, 1].max
188
+ end
189
+
190
+ def terminal_columns
191
+ IO.console&.winsize&.last || 80
192
+ rescue StandardError
193
+ 80
163
194
  end
164
195
  end
165
196
  end
@@ -49,7 +49,11 @@ module Starlined
49
49
  private
50
50
 
51
51
  def clear_line
52
- print "\r#{Starlined.configuration.clear_line_string}"
52
+ clear = Starlined.configuration.clear_line_string
53
+ lines = Animation.pending_clear_lines || 1
54
+ (lines - 1).times { print "\e[1A#{clear}" }
55
+ print "\r#{clear}"
56
+ Animation.pending_clear_lines = 1
53
57
  end
54
58
  end
55
59
  end
@@ -37,6 +37,13 @@ module Starlined
37
37
  )
38
38
  end
39
39
 
40
+ def progress(aka: nil, no_count: false)
41
+ start_step(aka: aka)
42
+ yield
43
+ ensure
44
+ end_step(aka: aka, no_count: no_count)
45
+ end
46
+
40
47
  def pass_step
41
48
  @animation&.increment_step
42
49
  end
@@ -87,7 +94,7 @@ module Starlined
87
94
  needs_password = !system('sudo -n true &>/dev/null')
88
95
  return unless needs_password || RUBY_PLATFORM.include?('darwin')
89
96
 
90
- stop_animation
97
+ @animation&.stop
91
98
 
92
99
  if needs_password
93
100
  # alertar al usuario con diferentes métodos
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Starlined
4
- VERSION = '0.2.4'
4
+ VERSION = '0.2.7'
5
5
  end
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 = 'CC-NC-BY-4.0'
13
+ spec.license = 'CC-BY-NC-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.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - mier
@@ -116,7 +116,7 @@ files:
116
116
  - starlined.gemspec
117
117
  homepage: https://github.com/miermontoto/starlined
118
118
  licenses:
119
- - CC-NC-BY-4.0
119
+ - CC-BY-NC-4.0
120
120
  metadata:
121
121
  homepage_uri: https://github.com/miermontoto/starlined
122
122
  source_code_uri: https://github.com/miermontoto/starlined