kyoh86 / richgo

Enrich `go test` outputs with text decorations.
Other
846 stars 25 forks source link

Extraneous newlines are added for some commands #13

Closed ascandella closed 4 years ago

ascandella commented 7 years ago

I wouldn't expect the output of richgo version and go version to be different at all, but they are:

richgo - master! ❯ ./richgo version
go version go1.8.1 darwin/amd64

richgo - master! ❯ go version
go version go1.8.1 darwin/amd64
richgo - master! ❯

This appears to be us manually adding \n characters in Close() on *stream

richgo - master! ❯ git --no-pager diff
diff --git i/editor/editor.go w/editor/editor.go
index e702e15..6074485 100644
--- i/editor/editor.go
+++ w/editor/editor.go
@@ -2,6 +2,7 @@ package editor

 import (
        "bytes"
+       "fmt"
        "io"
 )

@@ -40,6 +41,7 @@ func (s *stream) writeLines(lines [][]byte) error {
 }

 func (s *stream) Write(b []byte) (int, error) {
+       fmt.Println("Write")
        lines := bytes.Split(append(s.buffer, b...), []byte("\n"))
        s.buffer = lines[len(lines)-1]
        lines = lines[:len(lines)-1]
@@ -50,6 +52,7 @@ func (s *stream) Write(b []byte) (int, error) {
 }

 func (s *stream) Close() error {
+       fmt.Println("Close stream")
        lines := bytes.Split(s.buffer, []byte(`\n`))
        s.buffer = nil
        if err := s.writeLines(lines); err != nil {
richgo - master! ❯ ./richgo version
Write
go version go1.8.1 darwin/amd64
Close stream

Close stream

richgo - master! ❯

The double-close seems weird. Not sure if this is already on your radar. Obviously there are a lot of potential solutions, wanted to hear your thoughts before opening a PR.

ascandella commented 7 years ago

Also to clarify: I am volunteering to fix this issue, just wondering if you had already seen/thought about it and have opinions on it. If not, I'll go and do it "my way" :)

kyoh86 commented 7 years ago

Sorry for late reply. Why it prints "Close stream" twice is the Close called to close streams wrapping "stderr" and "stdout". I've no idea to fix it yet... :(

kamronbatman commented 5 years ago

Any fix for this?

kyoh86 commented 5 years ago

I've no idea to fix it.