starlined 0.2.3 → 0.2.4
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/examples/basic_messages.rb +7 -7
- data/lib/starlined/messages.rb +11 -10
- data/lib/starlined/runner.rb +13 -13
- data/lib/starlined/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8752698ed43ee158c8555688abd26f748631e99e9cbb3f07be23ee9712a281d
|
|
4
|
+
data.tar.gz: f58a4a33b3850c8ba79b2d06ef32ad5d6d88850b5995127b349e8ebc87e7d977
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45635e40d8f6bc8902de2f7c5200d555340946af45484c0af94d7198066a48a2f7061ef785f9093712939c146e799f5abbaa50ef4570caf4ead623f04c9f6af4
|
|
7
|
+
data.tar.gz: 6ebbb8ed5b0d494c6c1162dfd6eba6bd33e4e86616925bb115de53ba9631342583dd076580ca2368e7fecf98ba71b3cf715ea05b836d76affa6d3cc8c5d5d05e
|
data/examples/basic_messages.rb
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require_relative
|
|
4
|
+
require_relative '../lib/starlined'
|
|
5
5
|
|
|
6
6
|
include Starlined::Messages
|
|
7
7
|
|
|
8
|
-
puts
|
|
8
|
+
puts '=== Basic Message Examples ==='
|
|
9
9
|
puts
|
|
10
10
|
|
|
11
|
-
info(
|
|
11
|
+
info('This is an information message')
|
|
12
12
|
sleep(1)
|
|
13
13
|
|
|
14
|
-
warn(
|
|
14
|
+
warn('This is a warning message')
|
|
15
15
|
sleep(1)
|
|
16
16
|
|
|
17
|
-
success(
|
|
17
|
+
success('Operation completed successfully', 2.5)
|
|
18
18
|
sleep(1)
|
|
19
19
|
|
|
20
20
|
# configurar modo verbose
|
|
@@ -22,7 +22,7 @@ Starlined.configure do |config|
|
|
|
22
22
|
config.verbose = true
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
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)
|
|
@@ -33,4 +33,4 @@ name = ask("What's your name?")
|
|
|
33
33
|
info("Hello, #{name}!")
|
|
34
34
|
|
|
35
35
|
puts
|
|
36
|
-
puts
|
|
36
|
+
puts '=== End of Basic Examples ==='
|
data/lib/starlined/messages.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
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[#{
|
|
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[ #{
|
|
18
|
+
puts "\r[ #{'INFO'.blue} ] #{message}"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def warn(message)
|
|
22
22
|
clear_line
|
|
23
|
-
puts "\r[ #{
|
|
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[ #{
|
|
28
|
+
output = "\r[ #{'OK'.green} ] #{message}"
|
|
29
29
|
if time
|
|
30
|
-
dots =
|
|
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
|
|
36
|
+
def vrbose(message)
|
|
37
37
|
return unless Starlined.configuration.verbose
|
|
38
|
+
|
|
38
39
|
clear_line
|
|
39
|
-
puts "\r[#{
|
|
40
|
+
puts "\r[#{'VRBOSE'.light_black}] #{message}"
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def ask(prompt)
|
|
43
44
|
clear_line
|
|
44
|
-
print "\r[ #{
|
|
45
|
-
|
|
45
|
+
print "\r[ #{'??'.light_blue} ] #{prompt}: "
|
|
46
|
+
$stdin.gets.chomp
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
private
|
data/lib/starlined/runner.rb
CHANGED
|
@@ -41,6 +41,18 @@ module Starlined
|
|
|
41
41
|
@animation&.increment_step
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
def execute(callback, print_err: true, aka: nil, no_count: false, sudo: false)
|
|
45
|
+
handle_sudo if sudo
|
|
46
|
+
|
|
47
|
+
start_step(aka: aka)
|
|
48
|
+
result = callback.call
|
|
49
|
+
end_step(aka: aka, no_count: no_count)
|
|
50
|
+
|
|
51
|
+
handle_error(result, print_err, aka) unless result.last.success?
|
|
52
|
+
|
|
53
|
+
result
|
|
54
|
+
end
|
|
55
|
+
|
|
44
56
|
private
|
|
45
57
|
|
|
46
58
|
def start_step(aka: nil)
|
|
@@ -64,18 +76,6 @@ module Starlined
|
|
|
64
76
|
end
|
|
65
77
|
end
|
|
66
78
|
|
|
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)
|
|
73
|
-
|
|
74
|
-
handle_error(result, print_err, aka) unless result.last.success?
|
|
75
|
-
|
|
76
|
-
result
|
|
77
|
-
end
|
|
78
|
-
|
|
79
79
|
def stop_animation
|
|
80
80
|
return unless @animation
|
|
81
81
|
|
|
@@ -112,7 +112,7 @@ module Starlined
|
|
|
112
112
|
puts result[1] # stderr
|
|
113
113
|
puts result[0] if result[1].empty? # stdout si stderr está vacío
|
|
114
114
|
|
|
115
|
-
Messages.
|
|
115
|
+
Messages.vrbose("Exit code: #{result.last.exitstatus}")
|
|
116
116
|
exit 1
|
|
117
117
|
end
|
|
118
118
|
end
|
data/lib/starlined/version.rb
CHANGED