ZRUPLBBTT4S6S7A3LOAHG4ONYEGPA5CFO4L2XBCNFKK45MWX3BDAC
OJZWJUF2TCGZ7RFVY6FPKBS5P3C4BGHZDPVH775OHVNVFMJICKNQC
SLJ3OHD4F6GJGZ3SV2D7DMR3PXYHPSI64X77KZ3RJ24EGEX6ZNQAC
GLRGFBCWZYQEP6BG2IXYMXVZ5ETPWKNA2YJSIRHBCAAOAHJYT2YQC
5YDI33C4QRHATA6H3HHMBYFOBLAMXLLHWSDGJAH57DR6AMWO7AAQC
2K7JLB4Z7BS5VFNWD4DO3MKYU7VNPA5MTVHVSDI3FQZ5ICM6XM6QC
SXEYMYF7P4RZMZ46WPL4IZUTSQ2ATBWYZX7QNVMS3SGOYXYOHAGQC
5DVRL6MFXQOCPOZMYSKBERMRRVUTYRL2SRGRTU2MH4IEOFCDKM3QC
SE4RJYBZBNU6I3URBUMWP6T27CGGXLBEWWDB7WWX3W3AYSU6AFAAC
Q4SVMHAEZQQCBFGPJMWS5H4VXB2HFQREZ3AWGOHFWHLFARUQVPBAC
VIHXB7SGRETFPHPYZFSRGOFRXEO4RZY57WDZSU6IAUEJRU3HPKQAC
Q45QHPO4HDTEZF2W4UDZSYYQ46BPEIWSW4GJILZR5HTJNLKXJABQC
VO5OQW4W2656DIYYRNZ3PO7TQ4JOKQ3GVWE5ALUTYVMX3WMXJOYQC
}
pub struct Colored<W> {
pub w: W,
pub colors: bool,
}
impl<W: std::io::Write> std::io::Write for Colored<W> {
fn write(&mut self, s: &[u8]) -> Result<usize, std::io::Error> {
self.w.write(s)
}
fn flush(&mut self) -> Result<(), std::io::Error> {
self.w.flush()
}
}
use termcolor::*;
impl<W: termcolor::WriteColor> libpijul::change::WriteChangeLine for Colored<W> {
fn write_change_line(&mut self, pref: &str, contents: &str) -> Result<(), std::io::Error> {
if self.colors {
let col = if pref == "+" {
Color::Green
} else {
Color::Red
};
self.w.set_color(ColorSpec::new().set_fg(Some(col)))?;
write!(self.w, "{} {}", pref, contents)?;
self.w.reset()
} else {
write!(self.w, "{} {}", pref, contents)
}
}
fn write_change_line_binary(
&mut self,
pref: &str,
contents: &[u8],
) -> Result<(), std::io::Error> {
if self.colors {
let col = if pref == "+" {
Color::Green
} else {
Color::Red
};
self.w.set_color(ColorSpec::new().set_fg(Some(col)))?;
write!(
self.w,
"{}b{}",
pref,
data_encoding::BASE64.encode(contents)
)?;
self.w.reset()
} else {
write!(
self.w,
"{}b{}",
pref,
data_encoding::BASE64.encode(contents)
)
}
}
let o = std::io::stdout();
let mut o = o.lock();
super::pager();
change.write(&changes, Some(hash), file_name, true, &mut o)?;
let pager_is_colored = super::pager();
change.write(
&changes,
Some(hash),
file_name,
true,
super::diff::Colored {
w: termcolor::StandardStream::stdout(termcolor::ColorChoice::Auto),
colors: atty::is(atty::Stream::Stdout) || pager_is_colored,
},
)?;
print_change_contents(&mut w, changes, change, change_contents)?;
print_change_contents(&mut w, changes, replacement, change_contents)?;
print_change_contents(w, changes, change, change_contents)?;
print_change_contents(w, changes, replacement, change_contents)?;
pub fn print_contents<W: std::io::Write>(
pub trait WriteChangeLine: std::io::Write {
fn write_change_line(&mut self, pref: &str, contents: &str) -> Result<(), std::io::Error> {
write!(self, "{} {}", pref, contents)
}
fn write_change_line_binary(&mut self, pref: &str, contents: &[u8]) -> Result<(), std::io::Error> {
write!(self, "{}b{}", pref, data_encoding::BASE64.encode(contents))
}
}
impl WriteChangeLine for &mut Vec<u8> {}
pub fn print_contents<W: WriteChangeLine>(