interactive-logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/interactive-logger.rb +62 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72a04135369c640aab4c63048eafb80e669ed895
|
4
|
+
data.tar.gz: 8b983336a11ced1edbd6ff4624505c90e3801c32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87f61383fff19a07ec26acaa805b3f05cfc10c283bdc9d68fdd85710f7c6a08b3760d0106724c280cdb423eeb0d36cbccece45ce759403f3b89df030f4a1ec4e
|
7
|
+
data.tar.gz: 60fa6e6384f7d20ee5dde568723b90cb5a3102aaa5a942dc094ac0c7505ef736956ee4562db33eccc8e80e925cf677546aa3b6612cff170184c2809c9157625c
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'colorize'
|
3
|
+
require 'ruby-duration'
|
4
|
+
|
5
|
+
# A logger that shows activity for each step without spamming to stdout.
|
6
|
+
class InteractiveLogger
|
7
|
+
class Step
|
8
|
+
PROGRESS_SYMBOLS = %w(- \\ | /)
|
9
|
+
FAILURE_SYMBOL = '✗'.red
|
10
|
+
SUCCESS_SYMBOL = '✓'.green
|
11
|
+
LB = '['.light_black
|
12
|
+
RB = ']'.light_black
|
13
|
+
|
14
|
+
def initialize(str, show_time: true)
|
15
|
+
@orig_str = str
|
16
|
+
@start = Time.now
|
17
|
+
@show_time = show_time
|
18
|
+
@pos = 0
|
19
|
+
print_msg(in_progress_prefix << str)
|
20
|
+
end
|
21
|
+
|
22
|
+
def continue(str = nil)
|
23
|
+
@pos += 1
|
24
|
+
print_msg("\r" << in_progress_prefix << (str || @orig_str))
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure(str = nil)
|
28
|
+
print_msg("\r" << prefix(FAILURE_SYMBOL) << (str || @orig_str))
|
29
|
+
end
|
30
|
+
|
31
|
+
def success(str = nil)
|
32
|
+
print_msg("\r" << prefix(SUCCESS_SYMBOL) << (str || @orig_str))
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def in_progress_prefix
|
38
|
+
prefix(PROGRESS_SYMBOLS[@pos % PROGRESS_SYMBOLS.size].yellow)
|
39
|
+
end
|
40
|
+
|
41
|
+
def prefix(str)
|
42
|
+
show_time = ''
|
43
|
+
if @show_time
|
44
|
+
show_time = Duration.new(Time.now.to_i - @start.to_i)
|
45
|
+
.format(" #{LB} %tmm %ss #{RB}")
|
46
|
+
end
|
47
|
+
"#{LB} #{str} #{RB}#{show_time} "
|
48
|
+
end
|
49
|
+
|
50
|
+
def print_msg(str)
|
51
|
+
@max_str = [str.uncolorize.size, @max_str || 0].max
|
52
|
+
str << ' ' * (@max_str - str.uncolorize.size)
|
53
|
+
print str
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Start a step.
|
58
|
+
def start(str)
|
59
|
+
yield Step.new(str)
|
60
|
+
print "\n"
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interactive-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Smith <askreet@gmail.com>
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-duration
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 3.2.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.2.1
|
47
|
+
description: A colorful, interactive logger for tracking progress of an operation.
|
48
|
+
email: askreet@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/interactive-logger.rb
|
54
|
+
homepage: https://github.com/askreet/interactive-logger
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5.1
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: A colorful, interactive logger.
|
78
|
+
test_files: []
|
79
|
+
has_rdoc:
|