Skip to content

Commit

Permalink
Print the header as a footer when there's a large number of validator…
Browse files Browse the repository at this point in the history
…s to show
  • Loading branch information
mvines committed Apr 19, 2021
1 parent 818c319 commit 1824b5a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,9 @@ impl fmt::Display for CliValidators {
}

let padding = ((self.validators.len() + 1) as f64).log10().floor() as usize + 1;
write!(f, "{:padding$}", " ", padding = padding)?;
writeln!(
f,
"{}",
style(format!(
" {:<44} {:<38} {} {} {} {:>11} {:^7} {}",
let header = style(format!(
"{:padding$} {:<44} {:<38} {} {} {} {:>11} {:^7} {}",
" ",
"Identity",
"Vote Account",
"Commission",
Expand All @@ -392,9 +389,10 @@ impl fmt::Display for CliValidators {
"Epoch Credits",
"Version",
"Active Stake",
padding = padding
))
.bold()
)?;
.bold();
writeln!(f, "{}", header)?;

let mut sorted_validators = self.validators.clone();
match self.validators_sort_order {
Expand Down Expand Up @@ -438,6 +436,11 @@ impl fmt::Display for CliValidators {
)?;
}

// The actual header has long scrolled away. Print the header once more as a footer
if self.validators.len() > 100 {
writeln!(f, "{}", header)?;
}

writeln!(f)?;
writeln_name_value(
f,
Expand Down

0 comments on commit 1824b5a

Please sign in to comment.