cli/diff: Print cross-platform line endings

This commit is contained in:
Lorenz Leutgeb 2025-10-11 14:26:10 +02:00 committed by Fintan Halpenny
parent d8ab40777d
commit f232acda74
1 changed files with 12 additions and 2 deletions

View File

@ -586,10 +586,20 @@ impl<'a> Writer<'a> {
}
pub fn write(&mut self, s: impl fmt::Display, style: term::Style) -> io::Result<()> {
#[cfg(windows)]
const EOL: &str = "\r\n";
#[cfg(not(windows))]
const EOL: &str = "\n";
if self.styled {
writeln!(self.stream, "{}", term::Paint::new(s).with_style(style))
write!(
self.stream,
"{}{EOL}",
term::Paint::new(s).with_style(style)
)
} else {
writeln!(self.stream, "{s}")
write!(self.stream, "{s}{EOL}")
}
}