replace globalOptions.stdout with termstatus.OutputWriter

This commit is contained in:
Michael Eischer
2025-09-20 23:06:28 +02:00
parent c293736841
commit 76b2cdd4fb
29 changed files with 79 additions and 85 deletions

View File

@@ -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.