refactoring WithAutoRefresh
Vladimir Bauer
3 years ago
| 120 | 120 |
p := mpb.New(
|
| 121 | 121 |
mpb.WithWidth(100),
|
| 122 | 122 |
mpb.WithOutput(&buf),
|
| 123 | |
mpb.ForceAutoRefresh(),
|
|
123 |
mpb.WithAutoRefresh(),
|
| 124 | 124 |
)
|
| 125 | 125 |
|
| 126 | 126 |
total := 100
|
|
| 152 | 152 |
p := mpb.New(
|
| 153 | 153 |
mpb.WithWidth(80),
|
| 154 | 154 |
mpb.WithOutput(&buf),
|
| 155 | |
mpb.ForceAutoRefresh(),
|
|
155 |
mpb.WithAutoRefresh(),
|
| 156 | 156 |
)
|
| 157 | 157 |
|
| 158 | 158 |
total := 50
|
|
| 180 | 180 |
p := mpb.New(
|
| 181 | 181 |
mpb.WithWidth(80),
|
| 182 | 182 |
mpb.WithOutput(&buf),
|
| 183 | |
mpb.ForceAutoRefresh(),
|
|
183 |
mpb.WithAutoRefresh(),
|
| 184 | 184 |
)
|
| 185 | 185 |
bs := mpb.BarStyle()
|
| 186 | 186 |
bs.Lbound(string(runes[0]))
|
|
| 256 | 256 |
ctx, cancel := context.WithCancel(context.Background())
|
| 257 | 257 |
p := mpb.NewWithContext(ctx,
|
| 258 | 258 |
mpb.WithOutput(io.Discard),
|
| 259 | |
mpb.ForceAutoRefresh(),
|
|
259 |
mpb.WithAutoRefresh(),
|
| 260 | 260 |
mpb.WithShutdownNotifier(shutdown),
|
| 261 | 261 |
)
|
| 262 | 262 |
a := p.AddBar(100)
|
| 77 | 77 |
}
|
| 78 | 78 |
|
| 79 | 79 |
// WithOutput overrides default os.Stdout output. If underlying io.Writer
|
| 80 | |
// is not a terminal then auto refresh is disabled unless ForceAutoRefresh
|
| 81 | |
// option is provided.
|
|
80 |
// is not a terminal then auto refresh is disabled unless WithAutoRefresh
|
|
81 |
// option is set.
|
| 82 | 82 |
func WithOutput(w io.Writer) ContainerOption {
|
| 83 | 83 |
if w == nil {
|
| 84 | 84 |
w = io.Discard
|
|
| 98 | 98 |
}
|
| 99 | 99 |
}
|
| 100 | 100 |
|
| 101 | |
// ForceAutoRefresh force auto refresh even if output is not terminal.
|
|
101 |
// WithAutoRefresh force auto refresh regardless of what output is set to.
|
| 102 | 102 |
// Applicable only if not WithManualRefresh set.
|
| 103 | |
// Useful for testing purposes.
|
| 104 | |
func ForceAutoRefresh() ContainerOption {
|
|
103 |
func WithAutoRefresh() ContainerOption {
|
| 105 | 104 |
return func(s *pState) {
|
| 106 | 105 |
s.autoRefresh = true
|
| 107 | 106 |
}
|
| 50 | 50 |
mpb.WithShutdownNotifier(shutdown),
|
| 51 | 51 |
mpb.WithOutput(io.Discard),
|
| 52 | 52 |
mpb.WithDebugOutput(&debug),
|
| 53 | |
mpb.ForceAutoRefresh(),
|
|
53 |
mpb.WithAutoRefresh(),
|
| 54 | 54 |
)
|
| 55 | 55 |
|
| 56 | 56 |
var errReturnCount int
|
|
| 98 | 98 |
p := mpb.New(
|
| 99 | 99 |
mpb.WithShutdownNotifier(shutdown),
|
| 100 | 100 |
mpb.WithOutput(io.Discard),
|
| 101 | |
mpb.ForceAutoRefresh(),
|
|
101 |
mpb.WithAutoRefresh(),
|
| 102 | 102 |
)
|
| 103 | 103 |
b := p.AddBar(100)
|
| 104 | 104 |
|
|
| 134 | 134 |
p := mpb.New(
|
| 135 | 135 |
mpb.WithShutdownNotifier(shutdown),
|
| 136 | 136 |
mpb.WithOutput(io.Discard),
|
| 137 | |
mpb.ForceAutoRefresh(),
|
|
137 |
mpb.WithAutoRefresh(),
|
| 138 | 138 |
)
|
| 139 | 139 |
b := p.AddBar(100)
|
| 140 | 140 |
|