diff options
-rw-r--r-- | src/reader.go | 26 | ||||
-rw-r--r-- | test/test_go.rb | 11 |
2 files changed, 34 insertions, 3 deletions
diff --git a/src/reader.go b/src/reader.go index d4764119..7496b775 100644 --- a/src/reader.go +++ b/src/reader.go @@ -30,9 +30,29 @@ func (r *Reader) ReadSource() { } func (r *Reader) feed(src io.Reader) { - if scanner := bufio.NewScanner(src); scanner != nil { - for scanner.Scan() { - r.pusher(scanner.Text()) + reader := bufio.NewReader(src) + eof := false +Loop: + for !eof { + buf := []byte{} + iter := 0 // TODO: max size? + for { + // "ReadLine either returns a non-nil line or it returns an error, never both" + line, isPrefix, err := reader.ReadLine() + eof = err == io.EOF + if eof { + break + } else if err != nil { + break Loop + } + iter++ + buf = append(buf, line...) + if !isPrefix { + break + } + } + if iter > 0 { + r.pusher(string(buf)) r.eventBox.Set(EvtReadNew, nil) } } diff --git a/test/test_go.rb b/test/test_go.rb index 4c4a77ce..35caea77 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -525,6 +525,17 @@ class TestGoFZF < TestBase tmux.send_keys 'uuu', 'TTT', 'tt', 'uu', 'ttt', 'C-j' assert_equal %w[4 5 6 9], readonce.split($/) end + + def test_long_line + tempname = TEMPNAME + Time.now.to_f.to_s + data = '.' * 256 * 1024 + File.open(tempname, 'w') do |f| + f << data + end + assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp + ensure + File.unlink tempname + end private def writelines path, lines File.unlink path while File.exists? path |