writeWithCarriageReturn writes each line with a carriage return to ensure that each line starts at the beginning of the terminal.
(src io.Reader, dest io.Writer)
| 1335 | // writeWithCarriageReturn writes each line with a carriage return to ensure |
| 1336 | // that each line starts at the beginning of the terminal. |
| 1337 | func writeWithCarriageReturn(src io.Reader, dest io.Writer) error { |
| 1338 | s := bufio.NewScanner(src) |
| 1339 | for s.Scan() { |
| 1340 | _, err := fmt.Fprint(dest, s.Text()+"\r\n") |
| 1341 | if err != nil { |
| 1342 | return xerrors.Errorf("write line: %w", err) |
| 1343 | } |
| 1344 | } |
| 1345 | if err := s.Err(); err != nil { |
| 1346 | return xerrors.Errorf("read line: %w", err) |
| 1347 | } |
| 1348 | return nil |
| 1349 | } |
| 1350 | |
| 1351 | // userHomeDir returns the home directory of the current user, giving |
| 1352 | // priority to the $HOME environment variable. |