This commit is contained in:
Chungsub Kim
2015-02-17 12:02:51 +09:00
parent 1c127e8353
commit abbc8f80c4
3 changed files with 28 additions and 8 deletions
+2
View File
@@ -0,0 +1,2 @@
stdout1: ruby ./stdout.rb
stdout2: ruby ./stdout.rb
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
$stdout.sync = true
puts "a"
sleep 1
puts "a\nb"
sleep 1
puts "a\nb\nc"
sleep 1
puts "a\nb\nc\nd"
sleep 1
puts "finish!"
+13 -8
View File
@@ -40,20 +40,25 @@ func (of *OutletFactory) LineReader(wg *sync.WaitGroup, name string, index int,
for {
buf := make([]byte, 1024)
v, _ := reader.Read(buf)
if v == 0 {
if n, err := reader.Read(buf); err != nil {
return
} else {
buf = buf[:n]
}
idx := bytes.IndexByte(buf, '\n')
if idx >= 0 {
buffer.Write(buf[0:idx])
for {
i := bytes.IndexByte(buf, '\n')
if i < 0 {
break
}
buffer.Write(buf[0:i])
of.WriteLine(name, buffer.String(), color, ct.None, isError)
buffer.Reset()
} else {
buffer.Write(buf)
buf = buf[i+1:]
}
buffer.Write(buf)
}
}