flush flushes the output buffer to the program output.
()
| 1219 | |
| 1220 | // flush flushes the output buffer to the program output. |
| 1221 | func (p *Program) flush() error { |
| 1222 | p.mu.Lock() |
| 1223 | defer p.mu.Unlock() |
| 1224 | |
| 1225 | if p.outputBuf.Len() == 0 { |
| 1226 | return nil |
| 1227 | } |
| 1228 | if p.logger != nil { |
| 1229 | p.logger.Printf("output: %q", p.outputBuf.String()) |
| 1230 | } |
| 1231 | _, err := p.output.Write(p.outputBuf.Bytes()) |
| 1232 | p.outputBuf.Reset() |
| 1233 | if err != nil { |
| 1234 | return fmt.Errorf("error writing to output: %w", err) |
| 1235 | } |
| 1236 | return nil |
| 1237 | } |
| 1238 | |
| 1239 | // shutdown performs operations to free up resources and restore the terminal |
| 1240 | // to its original state. |
no test coverage detected