Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exposing the internal writer of AutoFlushingWriter #30

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spinner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func assertSpinnerCharSequence(t *testing.T, outBuffer *bytes.Buffer) {
startTime := time.Now()
for {
s, _ := outBuffer.ReadString(TermControlEraseLine[len(TermControlEraseLine)-1]) // read everything you got
if strippedString := strings.Trim(s, TermControlEraseLine + "\x00"); strippedString != "" {
if strippedString := strings.Trim(s, TermControlEraseLine+"\x00"); strippedString != "" {
return strippedString
}

Expand Down
10 changes: 4 additions & 6 deletions stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ func init() {

// AutoFlushingWriter an implementation of an io.Writer and io.StringWriter with auto-flush semantics.
type AutoFlushingWriter struct {
io.StringWriter
io.Writer
writer *bufio.Writer
Writer *bufio.Writer
}

// NewAutoFlushingWriter creates a new io.Writer that uses a buffer internally and flushes after every write.
// This writer should be used on top of Stdout and Stderr for components that require frequent screen updates.
func NewAutoFlushingWriter(w io.Writer) *AutoFlushingWriter {
return &AutoFlushingWriter{
writer: bufio.NewWriter(w),
Writer: bufio.NewWriter(w),
}
}

func (sw *AutoFlushingWriter) Write(b []byte) (int, error) {
defer sw.writer.Flush()
return sw.writer.Write(b)
defer sw.Writer.Flush()
return sw.Writer.Write(b)
}

// WriteString uses io.WriteString to write the specified string to the underlying writer.
Expand Down