mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-30 09:05:54 +00:00
Document the main loop
This commit is contained in:
1 parent
828fb210ce
commit
0caab15255
1 file changed
+13
+13
@@ -483,8 +483,10 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
|||||||
|
|
||||||
self.print_header()?;
|
self.print_header()?;
|
||||||
let leftover = loop {
|
let leftover = loop {
|
||||||
|
// read a maximum of 8 * self.panels bytes from the reader
|
||||||
if let Ok(n) = buf.read(&mut self.line_buf) {
|
if let Ok(n) = buf.read(&mut self.line_buf) {
|
||||||
if n > 0 && n < 8 * self.panels as usize {
|
if n > 0 && n < 8 * self.panels as usize {
|
||||||
|
// if less are read, that indicates end of file after
|
||||||
is_empty = false;
|
is_empty = false;
|
||||||
|
|
||||||
// perform second check on read
|
// perform second check on read
|
||||||
@@ -493,7 +495,9 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
|||||||
break Some(n);
|
break Some(n);
|
||||||
};
|
};
|
||||||
} else if n == 0 {
|
} else if n == 0 {
|
||||||
|
// if no bytes are read, that indicates end of file
|
||||||
if self.squeezer == Squeezer::Delete {
|
if self.squeezer == Squeezer::Delete {
|
||||||
|
// empty the last line when ending is squeezed
|
||||||
self.line_buf.clear();
|
self.line_buf.clear();
|
||||||
break Some(0);
|
break Some(0);
|
||||||
}
|
}
|
||||||
@@ -502,6 +506,8 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
|||||||
}
|
}
|
||||||
is_empty = false;
|
is_empty = false;
|
||||||
|
|
||||||
|
// squeeze is active, check if the line is the same
|
||||||
|
// skip print if still squeezed, otherwise print and deactivate squeeze
|
||||||
if matches!(self.squeezer, Squeezer::Print | Squeezer::Delete) {
|
if matches!(self.squeezer, Squeezer::Print | Squeezer::Delete) {
|
||||||
if self
|
if self
|
||||||
.line_buf
|
.line_buf
|
||||||
@@ -516,6 +522,8 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
|||||||
self.squeezer = Squeezer::Ignore;
|
self.squeezer = Squeezer::Ignore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print the line
|
||||||
self.print_position_panel()?;
|
self.print_position_panel()?;
|
||||||
self.print_bytes()?;
|
self.print_bytes()?;
|
||||||
if self.show_char_panel {
|
if self.show_char_panel {
|
||||||
@@ -523,12 +531,17 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
|||||||
}
|
}
|
||||||
self.writer.write_all(b"\n")?;
|
self.writer.write_all(b"\n")?;
|
||||||
|
|
||||||
|
// increment index to next line
|
||||||
self.idx += 8 * self.panels;
|
self.idx += 8 * self.panels;
|
||||||
|
|
||||||
|
// change from print to delete if squeeze is still active
|
||||||
if self.squeezer == Squeezer::Print {
|
if self.squeezer == Squeezer::Print {
|
||||||
self.squeezer = Squeezer::Delete;
|
self.squeezer = Squeezer::Delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// repeat the first byte in the line until it's a usize
|
||||||
|
// compare that usize with each usize chunk in the line
|
||||||
|
// if they are all the same, change squeezer to print
|
||||||
let repeat_byte = (self.line_buf[0] as usize) * (usize::MAX / 255);
|
let repeat_byte = (self.line_buf[0] as usize) * (usize::MAX / 255);
|
||||||
if !matches!(self.squeezer, Squeezer::Disabled | Squeezer::Delete)
|
if !matches!(self.squeezer, Squeezer::Disabled | Squeezer::Delete)
|
||||||
&& self
|
&& self
|
||||||
|
|||||||
Reference in new issue
Block a user