Compare commits

..

1 Commits

Author SHA1 Message Date
06cd411089 Calculate hosts panel column width based on actual hostname lengths
All checks were successful
Build and Release / build-and-release (push) Successful in 1m51s
2025-12-16 16:52:07 +01:00
6 changed files with 18 additions and 12 deletions

6
Cargo.lock generated
View File

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

View File

@@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-agent"
version = "0.1.280"
version = "0.1.281"
edition = "2021"
[dependencies]

View File

@@ -1,6 +1,6 @@
[package]
name = "cm-dashboard"
version = "0.1.280"
version = "0.1.281"
edition = "2021"
[dependencies]

View File

@@ -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

View File

@@ -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<F>(
&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;

View File

@@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-shared"
version = "0.1.280"
version = "0.1.281"
edition = "2021"
[dependencies]