Rename --columns to --panels

This commit is contained in:
Sharif Haason authored and David Peter committed 2022-09-11 21:45:06 +02:00
1 parent 6b062ba127
commit 12324d615a
2 files changed
+46 -46

No files matched your search

+26 -26
View File
@@ -153,14 +153,14 @@ fn run() -> Result<(), AnyhowError> {
), ),
) )
.arg( .arg(
Arg::new("columns") Arg::new("panels")
.short('w') .short('p')
.long("columns") .long("panels")
.takes_value(true) .takes_value(true)
.value_name("N") .value_name("N")
.help( .help(
"Sets the number of hex data columns to be displayed. \ "Sets the number of hex data panels to be displayed. \
`--columns=auto` will display the maximum number of hex data columns \ `--panels=auto` will display the maximum number of hex data panels \
based on the current terminal width", based on the current terminal width",
), ),
) )
@@ -170,11 +170,11 @@ fn run() -> Result<(), AnyhowError> {
.long("terminal-width") .long("terminal-width")
.takes_value(true) .takes_value(true)
.value_name("N") .value_name("N")
.conflicts_with("columns") .conflicts_with("panels")
.help( .help(
"Sets the number of terminal columns to be displayed.\nSince the terminal \ "Sets the number of terminal columns to be displayed.\nSince the terminal \
width may not be an evenly divisible by the width per hex data column, this \ width may not be an evenly divisible by the width per hex data column, this \
will use the greatest number of hex data columns that can fit in the requested \ will use the greatest number of hex data panels that can fit in the requested \
width but still leave some space to the right.\nCannot be used with other \ width but still leave some space to the right.\nCannot be used with other \
width-setting options.", width-setting options.",
), ),
@@ -296,7 +296,7 @@ fn run() -> Result<(), AnyhowError> {
.transpose()? .transpose()?
.unwrap_or(0); .unwrap_or(0);
let max_columns_fn = |terminal_width: u16| { let max_panels_fn = |terminal_width: u16| {
let offset = if show_position_panel { 10 } else { 1 }; let offset = if show_position_panel { 10 } else { 1 };
let col_width = if show_char_panel { 35 } else { 26 }; let col_width = if show_char_panel { 35 } else { 26 };
if (terminal_width - offset) / col_width < 1 { if (terminal_width - offset) / col_width < 1 {
@@ -306,32 +306,32 @@ fn run() -> Result<(), AnyhowError> {
} }
}; };
let columns = if matches.value_of("columns") == Some("auto") { let panels = if matches.value_of("panels") == Some("auto") {
max_columns_fn(terminal_size().ok_or_else(|| anyhow!("not a TTY"))?.0 .0) max_panels_fn(terminal_size().ok_or_else(|| anyhow!("not a TTY"))?.0 .0)
} else if let Some(columns) = matches } else if let Some(panels) = matches
.value_of("columns") .value_of("panels")
.map(|s| { .map(|s| {
s.parse::<NonZeroU16>().map(u16::from).context(anyhow!( s.parse::<NonZeroU16>().map(u16::from).context(anyhow!(
"failed to parse `--columns` arg {:?} as unsigned nonzero integer", "failed to parse `--panels` arg {:?} as unsigned nonzero integer",
s s
)) ))
}) })
.transpose()? .transpose()?
{ {
columns panels
} else if let Some(terminal_width) = matches } else if let Some(terminal_width) = matches
.value_of("terminal_width") .value_of("terminal_width")
.map(|s| { .map(|s| {
s.parse::<NonZeroU16>().map(u16::from).context(anyhow!( s.parse::<NonZeroU16>().map(u16::from).context(anyhow!(
"failed to parse `--terminal-width` arg {:?} as unsigned nonzero integer", "failed to parse `--terminal-width` arg {:?} as unsigned nonzero integer",
s s
)) ))
}) })
.transpose()? .transpose()?
{ {
max_columns_fn(terminal_width) max_panels_fn(terminal_width)
} else { } else {
2 2
}; };
let stdout = io::stdout(); let stdout = io::stdout();
@@ -344,7 +344,7 @@ fn run() -> Result<(), AnyhowError> {
show_position_panel, show_position_panel,
border_style, border_style,
squeeze, squeeze,
columns, panels,
); );
printer.display_offset(skip_offset + display_offset); printer.display_offset(skip_offset + display_offset);
printer.print_all(&mut reader).map_err(|e| anyhow!(e))?; printer.print_all(&mut reader).map_err(|e| anyhow!(e))?;
+20 -20
View File
@@ -155,7 +155,7 @@ pub struct Printer<'a, Writer: Write> {
squeezer: Squeezer, squeezer: Squeezer,
display_offset: u64, display_offset: u64,
/// The number of panels to draw. /// The number of panels to draw.
columns: u16, panels: u16,
} }
impl<'a, Writer: Write> Printer<'a, Writer> { impl<'a, Writer: Write> Printer<'a, Writer> {
@@ -166,7 +166,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
show_position_panel: bool, show_position_panel: bool,
border_style: BorderStyle, border_style: BorderStyle,
use_squeeze: bool, use_squeeze: bool,
columns: u16, panels: u16,
) -> Printer<'a, Writer> { ) -> Printer<'a, Writer> {
Printer { Printer {
idx: 1, idx: 1,
@@ -202,9 +202,9 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
.collect() .collect()
}) })
.unwrap_or_default(), .unwrap_or_default(),
squeezer: Squeezer::new(use_squeeze, 8 * columns as u64), squeezer: Squeezer::new(use_squeeze, 8 * panels as u64),
display_offset: 0, display_offset: 0,
columns, panels,
} }
} }
@@ -227,7 +227,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
write!(self.writer, "{}", l).ok(); write!(self.writer, "{}", l).ok();
} }
for _ in 0..self.columns - 1 { for _ in 0..self.panels - 1 {
write!(self.writer, "{h25}{c}", h25 = h25, c = c).ok(); write!(self.writer, "{h25}{c}", h25 = h25, c = c).ok();
} }
if self.show_char_panel { if self.show_char_panel {
@@ -237,7 +237,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
} }
if self.show_char_panel { if self.show_char_panel {
for _ in 0..self.columns - 1 { for _ in 0..self.panels - 1 {
write!(self.writer, "{h8}{c}", h8 = h8, c = c).ok(); write!(self.writer, "{h8}{c}", h8 = h8, c = c).ok();
} }
writeln!(self.writer, "{h8}{r}", h8 = h8, r = r).ok(); writeln!(self.writer, "{h8}{r}", h8 = h8, r = r).ok();
@@ -301,16 +301,16 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
self.byte_char_panel[b as usize] self.byte_char_panel[b as usize]
); );
if idx % 8 == 0 && idx % (u64::from(self.columns) * 8) != 0 { if idx % 8 == 0 && idx % (u64::from(self.panels) * 8) != 0 {
let _ = write!(&mut self.buffer_line, "{}", self.border_style.inner_sep()); let _ = write!(&mut self.buffer_line, "{}", self.border_style.inner_sep());
} }
idx += 1; idx += 1;
} }
if len < usize::from(8 * self.columns) { if len < usize::from(8 * self.panels) {
let _ = write!(&mut self.buffer_line, "{0:1$}", "", 8 - len % 8); let _ = write!(&mut self.buffer_line, "{0:1$}", "", 8 - len % 8);
for _ in 0..(usize::from(8 * self.columns) - (len + (8 - len % 8))) / 8 { for _ in 0..(usize::from(8 * self.panels) - (len + (8 - len % 8))) / 8 {
let _ = write!( let _ = write!(
&mut self.buffer_line, &mut self.buffer_line,
"{2}{0:1$}", "{2}{0:1$}",
@@ -324,7 +324,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
} }
pub fn print_byte(&mut self, b: u8) -> io::Result<()> { pub fn print_byte(&mut self, b: u8) -> io::Result<()> {
if self.idx % (u64::from(self.columns) * 8) == 1 { if self.idx % (u64::from(self.panels) * 8) == 1 {
self.print_header(); self.print_header();
self.print_position_panel(); self.print_position_panel();
} }
@@ -334,7 +334,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
self.squeezer.process(b, self.idx); self.squeezer.process(b, self.idx);
if self.idx % (u64::from(self.columns) * 8) == 0 { if self.idx % (u64::from(self.panels) * 8) == 0 {
self.print_textline()?; self.print_textline()?;
} else if self.idx % 8 == 0 { } else if self.idx % 8 == 0 {
let _ = write!(&mut self.buffer_line, "{} ", self.border_style.inner_sep()); let _ = write!(&mut self.buffer_line, "{} ", self.border_style.inner_sep());
@@ -352,7 +352,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
if self.squeezer.active() { if self.squeezer.active() {
self.print_position_panel(); self.print_position_panel();
write!(&mut self.buffer_line, "{0:1$}", "", 24)?; write!(&mut self.buffer_line, "{0:1$}", "", 24)?;
for _ in 0..self.columns - 1 { for _ in 0..self.panels - 1 {
write!( write!(
&mut self.buffer_line, &mut self.buffer_line,
"{2}{0:1$}", "{2}{0:1$}",
@@ -368,7 +368,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
8, 8,
self.border_style.outer_sep() self.border_style.outer_sep()
)?; )?;
for _ in 0..self.columns - 1 { for _ in 0..self.panels - 1 {
write!( write!(
&mut self.buffer_line, &mut self.buffer_line,
"{2}{0:1$}", "{2}{0:1$}",
@@ -387,9 +387,9 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
// print empty space on last line // print empty space on last line
if squeeze_action != SqueezeAction::Delete { if squeeze_action != SqueezeAction::Delete {
if len < usize::from(8 * self.columns) { if len < usize::from(8 * self.panels) {
write!(&mut self.buffer_line, "{0:1$}", "", 3 * (8 - len % 8))?; write!(&mut self.buffer_line, "{0:1$}", "", 3 * (8 - len % 8))?;
for _ in 0..(usize::from(8 * self.columns) - (len + (8 - len % 8))) / 8 { for _ in 0..(usize::from(8 * self.panels) - (len + (8 - len % 8))) / 8 {
write!( write!(
&mut self.buffer_line, &mut self.buffer_line,
"{2}{0:1$}", "{2}{0:1$}",
@@ -422,18 +422,18 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
self.border_style.outer_sep() self.border_style.outer_sep()
)?; )?;
for i in 0..self.columns { for i in 0..self.panels {
write!(&mut self.buffer_line, "{0:1$}", "", 25)?; write!(&mut self.buffer_line, "{0:1$}", "", 25)?;
if i != self.columns - 1 { if i != self.panels - 1 {
write!(&mut self.buffer_line, "{}", self.border_style.inner_sep())?; write!(&mut self.buffer_line, "{}", self.border_style.inner_sep())?;
} else { } else {
write!(&mut self.buffer_line, "{}", self.border_style.outer_sep())?; write!(&mut self.buffer_line, "{}", self.border_style.outer_sep())?;
} }
} }
for i in 0..self.columns { for i in 0..self.panels {
write!(&mut self.buffer_line, "{0:1$}", "", 8)?; write!(&mut self.buffer_line, "{0:1$}", "", 8)?;
if i != self.columns - 1 { if i != self.panels - 1 {
write!(&mut self.buffer_line, "{}", self.border_style.inner_sep())?; write!(&mut self.buffer_line, "{}", self.border_style.inner_sep())?;
} else { } else {
writeln!(&mut self.buffer_line, "{}", self.border_style.outer_sep())?; writeln!(&mut self.buffer_line, "{}", self.border_style.outer_sep())?;
@@ -585,7 +585,7 @@ mod tests {
} }
#[test] #[test]
fn multiple_columns() { fn multiple_panels() {
let input = io::Cursor::new(b"supercalifragilisticexpialidocioussupercalifragilisticexpialidocioussupercalifragilisticexpialidocious"); let input = io::Cursor::new(b"supercalifragilisticexpialidocioussupercalifragilisticexpialidocioussupercalifragilisticexpialidocious");
let expected_string = "\ let expected_string = "\
┌────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬────────┬────────┬────────┬────────┐ ┌────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬────────┬────────┬────────┬────────┐