diff --git a/applications/tari_base_node/src/cli.rs b/applications/tari_base_node/src/cli.rs index da696c867c..cab727d892 100644 --- a/applications/tari_base_node/src/cli.rs +++ b/applications/tari_base_node/src/cli.rs @@ -23,10 +23,7 @@ use std::io::stdout; use chrono::{Datelike, Utc}; -use crossterm::{ - execute, - terminal::{size, SetSize}, -}; +use crossterm::{execute, terminal::SetSize}; use tari_app_utilities::consts; /// returns the top or bottom box line of the specified length @@ -108,11 +105,9 @@ fn multiline_find_display_length(lines: &str) -> usize { /// Try to resize terminal to make sure the width is enough. /// In case of error, just simply print out the error. -fn resize_terminal_to_fit_the_box(width: usize) { - if let Ok((_, rows)) = size() { - if let Err(e) = execute!(stdout(), SetSize(width as u16, rows)) { - println!("Can't resize terminal to fit the box. Error: {}", e) - } +fn resize_terminal_to_fit_the_box(width: usize, height: usize) { + if let Err(e) = execute!(stdout(), SetSize(width as u16, height as u16)) { + println!("Can't resize terminal to fit the box. Error: {}", e) } } @@ -158,8 +153,6 @@ pub fn print_banner(commands: Vec, chunk_size: i32) { let banner = include!("../assets/tari_banner.rs"); let target_line_length = multiline_find_display_length(banner); - resize_terminal_to_fit_the_box(target_line_length); - for line in banner.lines() { println!("{}", line); } @@ -187,8 +180,13 @@ pub fn print_banner(commands: Vec, chunk_size: i32) { println!("{}", box_data("~~~~~~~~".to_string(), target_line_length)); println!("{}", box_separator(target_line_length)); let rows = box_tabular_data_rows(command_data, row_cell_size, target_line_length, 10); + // There are 24 fixed rows besides the possible changed "Commands" rows + // and plus 2 more blank rows for better layout. + let height_to_resize = &rows.len() + 24 + 2; for row in rows { println!("{}", row); } println!("{}", box_line(target_line_length, false)); + + resize_terminal_to_fit_the_box(target_line_length, height_to_resize); }