mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
replace globalOptions.stdout with termstatus.OutputWriter
This commit is contained in:
@@ -30,6 +30,9 @@ type Terminal struct {
|
||||
outputIsTerminal bool
|
||||
canUpdateStatus bool
|
||||
|
||||
outputWriter io.WriteCloser
|
||||
outputWriterOnce sync.Once
|
||||
|
||||
// will be closed when the goroutine which runs Run() terminates, so it'll
|
||||
// yield a default value immediately
|
||||
closed chan struct{}
|
||||
@@ -73,6 +76,9 @@ func Setup(stdin io.ReadCloser, stdout, stderr io.Writer, quiet bool) (*Terminal
|
||||
}()
|
||||
|
||||
return term, func() {
|
||||
if term.outputWriter != nil {
|
||||
_ = term.outputWriter.Close()
|
||||
}
|
||||
// shutdown termstatus
|
||||
cancel()
|
||||
wg.Wait()
|
||||
@@ -158,6 +164,13 @@ func (t *Terminal) CanUpdateStatus() bool {
|
||||
return t.canUpdateStatus
|
||||
}
|
||||
|
||||
func (t *Terminal) OutputWriter() io.Writer {
|
||||
t.outputWriterOnce.Do(func() {
|
||||
t.outputWriter = newLineWriter(t.Print)
|
||||
})
|
||||
return t.outputWriter
|
||||
}
|
||||
|
||||
// OutputRaw returns the output writer. Should only be used if there is no
|
||||
// other option. Must not be used in combination with Print, Error, SetStatus
|
||||
// or any other method that writes to the terminal.
|
||||
|
||||
Reference in New Issue
Block a user