diff --git a/Cargo.lock b/Cargo.lock index 0e5348c..2ac5165 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.280" +version = "0.1.281" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.280" +version = "0.1.281" dependencies = [ "anyhow", "async-trait", @@ -325,7 +325,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.280" +version = "0.1.281" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 9114793..76a3c16 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.280" +version = "0.1.281" edition = "2021" [dependencies] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index e06fb9c..a0c287a 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.280" +version = "0.1.281" edition = "2021" [dependencies] diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index 2447c20..21ead0e 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -503,7 +503,7 @@ impl TuiApp { // Calculate hosts panel height dynamically based on available width let hosts_inner_width = content_chunks[0].width.saturating_sub(2); - let hosts_content_height = HostsWidget::required_height(self.available_hosts.len(), hosts_inner_width); + let hosts_content_height = HostsWidget::required_height(self.available_hosts.len(), hosts_inner_width, &self.available_hosts); let hosts_height = hosts_content_height + 2; // Add borders // Left side: hosts panel on top, system panel below diff --git a/dashboard/src/ui/widgets/hosts.rs b/dashboard/src/ui/widgets/hosts.rs index 7c9a6f3..b512d00 100644 --- a/dashboard/src/ui/widgets/hosts.rs +++ b/dashboard/src/ui/widgets/hosts.rs @@ -55,17 +55,23 @@ impl HostsWidget { } /// Calculate the required height for hosts panel based on host count and available width - pub fn required_height(num_hosts: usize, available_width: u16) -> u16 { + pub fn required_height(num_hosts: usize, available_width: u16, hostnames: &[String]) -> u16 { if num_hosts == 0 { return 1; } - // Estimate column width: icon(2) + arrow(2) + max_hostname(~12) + padding(2) = ~18 - let col_width = 18u16; + let col_width = Self::calculate_column_width(hostnames); let num_columns = (available_width / col_width).max(1) as usize; let rows_needed = (num_hosts + num_columns - 1) / num_columns; rows_needed.max(1) as u16 } + /// Calculate column width based on longest hostname + fn calculate_column_width(hostnames: &[String]) -> u16 { + // icon(2) + arrow(2) + hostname + asterisk(1) + padding(1) + let max_name_len = hostnames.iter().map(|h| h.len()).max().unwrap_or(8); + (2 + 2 + max_name_len + 1 + 1) as u16 + } + /// Render hosts list in dynamic columns based on available width pub fn render( &mut self, @@ -88,8 +94,8 @@ impl HostsWidget { // Store viewport height for scroll calculations self.last_viewport_height = area.height as usize; - // Calculate column width and number of columns that fit - let col_width = 18u16; + // Calculate column width based on actual hostname lengths + let col_width = Self::calculate_column_width(available_hosts); let num_columns = (area.width / col_width).max(1) as usize; let rows_per_column = (available_hosts.len() + num_columns - 1) / num_columns; diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 65e1aa7..1b64696 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.280" +version = "0.1.281" edition = "2021" [dependencies]