inprovise 0.2.8 → 0.2.9

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWIzZmMxNTQzOTY1MjAxNTZiYjE2ZjQwNzZjZDg1ZDQwMDA3MWMxMg==
4
+ ZGIxYjZiN2VkYTY2OTEwNjVjMDg3OTBiMmUyYzM4YzVmZTZlZmIxMQ==
5
5
  data.tar.gz: !binary |-
6
- YzYzYjJlYzc2MmYxOTFkYTJjY2Q0ZmY3Njg5MWFlYzc0NDU0MGUzNw==
6
+ NWRjZTgzZTY1ZGEzN2NiZTU2NWRjYTBkODIxNzA0YTA5MGQxMTVjNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDljNzdlYTgwNTEyM2I4YmNkMzE0Y2NlYTJhMWRhMjJiYzUyNGRiMjQ4YmEx
10
- NmViZmRmMTUzNGJiMWRkNDg4YmEzYjNjMDAyMzI1OWVhMmNiMGU1MjBiYmJl
11
- ZjU1YTZkYzUzZTk0ZjdlNDMzNzExMGM1MTYwNWI4MjZiZTI1ZTA=
9
+ N2I3Yzc5M2ZlOGVjZTJmMDUzNjcxODRhZWIwNjk3OTg0YjUwMzM2Y2EwZWI0
10
+ OGI0ZDQzNzBmZjU5YzBkNzZiN2ZhMGRlNzkxMDZlNDM0NzhlMTg3NjZiOWJj
11
+ YzIyMzcwODEyY2I2NWIzNDAwMzg0YTJmYzA3YzU3YTdhMjJjMDc=
12
12
  data.tar.gz: !binary |-
13
- YTc2YjdjYzc3MGFkMGM3NDgwNGRjOWI2OGE0MTA4NjVkMDNjOTA0NDgyMDZi
14
- ZWQ0NWMyMjcyMWYyNzliM2JlMzk0ZmFlZDhkMjMzNDQzMWFiMzk0MjI5YzVj
15
- YmI4MGRiYWJmMDY2ZGJkNmE3ZTA1OGZjMWRiNjc2MWNhYWI2MWU=
13
+ ZTg4ZTc3MTA1Y2NkMDkwODE2YWNmMjdjZWQzYjQzNTY4ZjZkZTdjMDNiMDNk
14
+ ZjFiY2QwOWQ5OGNiOWM5ZTkwNWQ2MTQ1MjNiOGQ0ZGIwZGQ2Yzg2OGNjMTkz
15
+ MmY3Y2VkNjQwOWI5NWU1YjVlYzZkZjM2M2YwYTkwYzQ0MDI4MTY=
@@ -19,10 +19,6 @@ class Inprovise::Logger
19
19
  end
20
20
 
21
21
  def initialize(node, task)
22
- @streams = {
23
- :stdout => { :ios => $stdout, :buffer => [{col: nil, ln: '', cr: false}] },
24
- :stderr => { :ios => $stderr, :buffer => [{col: nil, ln: '', cr: false}] }
25
- }
26
22
  @node = node
27
23
  set_task(task)
28
24
  end
@@ -84,6 +80,17 @@ class Inprovise::Logger
84
80
  end
85
81
  private :buffer
86
82
 
83
+ def next_line(stream)
84
+ lnbuf = buffer(stream).shift || {}
85
+ [lnbuf[:col], lnbuf[:ln], lnbuf[:cr]]
86
+ end
87
+ private :next_line
88
+
89
+ def push_line(stream, col, ln, cr)
90
+ buffer(stream) << {col: col, ln: ln, cr: cr ? true : false}
91
+ end
92
+ private :push_line
93
+
87
94
  def put(msg, color=nil, stream=:stdout)
88
95
  streambuf = buffer(stream)
89
96
  streambuf.last[:col] ||= color
@@ -98,30 +105,26 @@ class Inprovise::Logger
98
105
  private :puts
99
106
 
100
107
  def do_print(stream=:stdout)
101
- streambuf = buffer(stream)
102
- while lnbuf = streambuf.shift
103
- clear_to_eol = lnbuf[:cr]
104
- lnbuf[:ln].scan(/([^\r]*)(\r)?/) do |txt, cr|
105
- # do we have a (full) line to print?
106
- if cr || !streambuf.empty?
107
- out = lnbuf[:col] ? txt.to_s.send(lnbuf[:col]) : txt
108
+ until buffer(stream).empty?
109
+ col, ln, cr_at_start = next_line(stream)
110
+ ln.scan(/([^\r]*)(\r)?/) do |txt, cr|
111
+ nl = buffer(stream).size > 0
112
+ if cr || nl
108
113
  unless txt.empty?
109
- ios(stream).print "\r".to_eol if clear_to_eol
110
- ios(stream).print "#{@node.to_s} [#{@task.bold}] #{out}"
114
+ out = col ? txt.to_s.send(col) : txt
115
+ ios(stream).print "\r".to_eol if cr_at_start
116
+ ios(stream).print "#{@node} [#{@task.bold}] #{out}"
111
117
  end
112
- ios(stream).flush if cr
113
- ios(stream).puts unless cr || (txt.empty? && !clear_to_eol)
114
- clear_to_eol = cr ? true : false
115
- break unless cr # next line or cr?
116
- else
117
- streambuf << if txt.empty?
118
- # restart with empty line
119
- {col:nil,ln:'',cr:clear_to_eol}
118
+ if cr
119
+ ios(stream).flush
120
120
  else
121
- # stuff the remaining text back for a next round
122
- {col:lnbuf[:col],ln:txt,cr:clear_to_eol}
121
+ ios(stream).puts unless txt.empty? && !cr_at_start
123
122
  end
124
- return
123
+ cr_at_start = cr
124
+ else
125
+ # cache for later
126
+ push_line(stream, txt.empty? ? nil : col, txt, cr_at_start)
127
+ return # done printing for now
125
128
  end
126
129
  end
127
130
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Inprovise
7
7
 
8
- VERSION = '0.2.8'
8
+ VERSION = '0.2.9'
9
9
 
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inprovise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-11 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored