Skip to content

Commit

Permalink
Fix .len() vs .chars().count()
Browse files Browse the repository at this point in the history
`.len()` was not the right method for number of characters in a string,
`.chars().count()` is.
  • Loading branch information
brewingcode committed Feb 17, 2022
1 parent 537275e commit dc7f238
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/lineprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,37 +842,29 @@ impl<'a, 'b, 'c> LinePrinter<'a, 'b, 'c> {
}

let container_type = row.value.container_type().unwrap();
let count_str = format!(
let mut count_str = format!(
"{} {} {}",
container_type.open_str(),
count.to_string(),
container_type.close_str()
);
let short_str = format!(
"{}…{}",
container_type.open_str(),
container_type.close_str()
);

if count_str.len() as isize <= available_space {
self.highlight_str(
&count_str,
Some(self.value_range.start),
highlighting::PREVIEW_STYLES
)?;
let len = count_str.len() as isize;
available_space -= len;
return Ok(len)
if count_str.len() as isize > available_space {
count_str = format!(
"{}…{}",
container_type.open_str(),
container_type.close_str()
);
}
else {
self.highlight_str(
&short_str,
Some(self.value_range.start),
highlighting::PREVIEW_STYLES
)?;
available_space -= 3;
return Ok(3)
}

self.highlight_str(
&count_str,
Some(self.value_range.start),
highlighting::PREVIEW_STYLES
)?;
let len = count_str.chars().count() as isize;
available_space -= len;
Ok(len)
}

// {a…: …, …}
Expand Down

0 comments on commit dc7f238

Please sign in to comment.