Skip to content

Commit f532cba

Browse files
committed
docs(README): add custom writer usage example and clarify output options
1 parent 88272b1 commit f532cba

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ defer cancel()
3838
p.Stop("Done!")
3939
```
4040

41+
## Custom Output Writer
42+
43+
You can direct spinner output to an alternative writer (for example, `os.Stderr`) using the `WithWriter` option:
44+
45+
```go
46+
p := pin.New("Processing...",
47+
pin.WithSpinnerColor(pin.ColorCyan),
48+
pin.WithTextColor(pin.ColorYellow),
49+
pin.WithWriter(os.Stderr), // output will be written to stderr
50+
)
51+
cancel := p.Start(context.Background())
52+
defer cancel()
53+
// perform your work
54+
p.Stop("Done!")
55+
```
56+
4157
## Non-interactive Behavior
4258

4359
When the spinner detects that `stdout` is not connected to an interactive terminal (for example, when output is piped), it disables animations and outputs messages as plain text. In this mode:

pin.go

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@
4545
// defer cancel()
4646
// // ... do some work ...
4747
// p.Fail("Error occurred")
48+
//
49+
// Example with custom output writer:
50+
//
51+
// p := pin.New("Saving Data",
52+
// WithSpinnerColor(ColorMagenta),
53+
// WithWriter(os.Stderr), // send output to stderr
54+
// )
55+
// cancel := p.Start(context.Background())
56+
// defer cancel()
57+
// // ... do some work ...
58+
// p.Stop("Saved!")
4859
package pin
4960

5061
import (

0 commit comments

Comments
 (0)