From 1824b5a2ce9fb98bbe167f21a39527cbe96079f3 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 19 Apr 2021 13:12:45 -0700 Subject: [PATCH] Print the header as a footer when there's a large number of validators to show --- cli-output/src/cli_output.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index 61a9f0fb33..2952ac22fc 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -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,