termstatus: flush output before returning OutputRaw() writer

This prevents mangling the output due to delayed messages.
This commit is contained in:
Michael Eischer 2025-10-04 23:08:48 +02:00
parent f17027eeaa
commit 30ed992af9
2 changed files with 3 additions and 1 deletions

View file

@ -180,6 +180,7 @@ func (t *Terminal) OutputWriter() io.Writer {
// other option. Must not be used in combination with Print, Error, SetStatus
// or any other method that writes to the terminal.
func (t *Terminal) OutputRaw() io.Writer {
t.Flush()
return t.wr
}

View file

@ -124,7 +124,8 @@ func TestReadPasswordTerminal(t *testing.T) {
func TestRawInputOutput(t *testing.T) {
input := io.NopCloser(strings.NewReader("password"))
var output bytes.Buffer
term := New(input, &output, io.Discard, false)
term, cancel := Setup(input, &output, io.Discard, false)
defer cancel()
rtest.Equals(t, input, term.InputRaw())
rtest.Equals(t, false, term.InputIsTerminal())
rtest.Equals(t, &output, term.OutputRaw())