Fix describe_node_list remaining nodes special case

Colmena truncates left over node names when it reaches a certain char limit.
This in it self is a sensible behaivior, but it should only do so if there is more then one node name remaining.
This commit is contained in:
Peter Lehmann 2024-09-02 22:32:59 +02:00
parent cd65ef7a25
commit 569c914f95
No known key found for this signature in database
GPG key ID: C141E17790DC45F7

View file

@ -874,11 +874,17 @@ fn describe_node_list(nodes: &[NodeName]) -> Option<String> {
}
let (idx, next) = next.unwrap();
let remaining = rough_limit - s.len();
let remaining_text = rough_limit - s.len();
let remaining_nodes = total - idx;
if next.len() + other_text.len() >= remaining {
write!(s, ", and {} other nodes", total - idx).unwrap();
if next.len() + other_text.len() >= remaining_text {
if remaining_nodes == 1 {
write!(s, ", and {}", next.as_str()).unwrap();
break;
} else {
write!(s, ", and {} other nodes", remaining_nodes).unwrap();
break;
}
}
}