mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:31 +00:00
Fixes --no-characters causes output artifacts when squeezing lines #171
This commit is contained in:
1 parent
daa40900bd
commit
1cb346bd13
1 file changed
+24
-2
+24
-2
@@ -448,7 +448,6 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
self.line_buf.clear();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -461,7 +460,6 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
// print the byte
|
||||
self.writer
|
||||
.write_all(self.byte_hex_panel[b as usize].as_bytes())?;
|
||||
self.line_buf.push(b);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -491,6 +489,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
}
|
||||
|
||||
pub fn print_line(&mut self, b: u8) -> io::Result<()> {
|
||||
let old_action = self.squeezer.action();
|
||||
self.squeezer.process(b, self.idx);
|
||||
|
||||
// the header should be the first thing printed
|
||||
@@ -498,6 +497,26 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
self.print_header()?;
|
||||
}
|
||||
|
||||
// flush the rest of the line buffer before continuing to write
|
||||
if old_action == SqueezeAction::Delete && self.squeezer.action() == SqueezeAction::Ignore {
|
||||
self.writer.write_all(
|
||||
self.border_style
|
||||
.outer_sep()
|
||||
.encode_utf8(&mut [0; 4])
|
||||
.as_bytes(),
|
||||
)?;
|
||||
self.print_position_panel()?;
|
||||
let old_idx = self.idx;
|
||||
self.idx -= self.line_buf.len() as u64;
|
||||
for b in self.line_buf.clone() {
|
||||
self.print_byte(b)?;
|
||||
self.idx += 1;
|
||||
}
|
||||
self.idx = old_idx
|
||||
}
|
||||
|
||||
self.line_buf.push(b);
|
||||
|
||||
if !self.squeezer.active() || self.squeezer.action() == SqueezeAction::Print {
|
||||
// print the left border and position panel if there's a new line
|
||||
if self.idx % (8 * self.panels as u64) == 0 {
|
||||
@@ -519,6 +538,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
self.print_char_panel()?;
|
||||
} else {
|
||||
self.writer.write_all(b"\n")?;
|
||||
self.line_buf.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -604,6 +624,8 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
}
|
||||
if self.show_char_panel {
|
||||
self.print_char_panel()?;
|
||||
} else {
|
||||
writeln!(self.writer)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user