Print the header as a footer when there's a large number of validators to show

This commit is contained in:
Michael Vines 2021-04-19 13:12:45 -07:00
parent 818c3198c1
commit 1824b5a2ce
1 changed files with 11 additions and 8 deletions

View File

@ -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",
@ -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 {
@ -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,