use unicode_width::UnicodeWidthStr;
use super::super::OptionalRepos;
use super::types::{CoreFilterLabels, OptionalReposLabels};
pub(super) fn calculate_optional_repos_width(
repos: &OptionalRepos,
labels: &OptionalReposLabels,
) -> u16 {
let mut width = 0u16;
if repos.has_eos {
width = width.saturating_add(1 + u16::try_from(labels.eos.width()).unwrap_or(u16::MAX));
}
if repos.has_cachyos {
width = width.saturating_add(1 + u16::try_from(labels.cachyos.width()).unwrap_or(u16::MAX));
}
if repos.has_artix {
width = width.saturating_add(1 + u16::try_from(labels.artix.width()).unwrap_or(u16::MAX));
}
if repos.has_artix_omniverse {
width = width
.saturating_add(1 + u16::try_from(labels.artix_omniverse.width()).unwrap_or(u16::MAX));
}
if repos.has_artix_universe {
width = width
.saturating_add(1 + u16::try_from(labels.artix_universe.width()).unwrap_or(u16::MAX));
}
if repos.has_artix_lib32 {
width =
width.saturating_add(1 + u16::try_from(labels.artix_lib32.width()).unwrap_or(u16::MAX));
}
if repos.has_artix_galaxy {
width = width
.saturating_add(1 + u16::try_from(labels.artix_galaxy.width()).unwrap_or(u16::MAX));
}
if repos.has_artix_world {
width =
width.saturating_add(1 + u16::try_from(labels.artix_world.width()).unwrap_or(u16::MAX));
}
if repos.has_artix_system {
width = width
.saturating_add(1 + u16::try_from(labels.artix_system.width()).unwrap_or(u16::MAX));
}
if repos.has_blackarch {
width =
width.saturating_add(1 + u16::try_from(labels.blackarch.width()).unwrap_or(u16::MAX));
}
if repos.has_manjaro {
width = width.saturating_add(1 + u16::try_from(labels.manjaro.width()).unwrap_or(u16::MAX));
}
width
}
pub(super) fn calculate_base_consumed_space(
results_title_text: &str,
sort_button_label: &str,
core_labels: &CoreFilterLabels,
) -> u16 {
u16::try_from(
results_title_text.width()
+ 2 + sort_button_label.width()
+ 2 + core_labels.aur.width()
+ 1 + core_labels.core.width()
+ 1 + core_labels.extra.width()
+ 1 + core_labels.multilib.width(),
)
.unwrap_or(u16::MAX)
}
#[allow(clippy::missing_const_for_fn)] pub(super) fn create_repos_without_specific(optional_repos: &OptionalRepos) -> OptionalRepos {
OptionalRepos {
has_eos: optional_repos.has_eos,
has_cachyos: optional_repos.has_cachyos,
has_artix: optional_repos.has_artix,
has_artix_omniverse: false,
has_artix_universe: false,
has_artix_lib32: false,
has_artix_galaxy: false,
has_artix_world: false,
has_artix_system: false,
has_blackarch: optional_repos.has_blackarch,
has_manjaro: optional_repos.has_manjaro,
}
}
pub(super) fn calculate_consumed_without_specific(
base_consumed: u16,
repos_without_specific: &OptionalRepos,
optional_labels: &OptionalReposLabels,
has_artix: bool,
) -> u16 {
let mut consumed = base_consumed.saturating_add(calculate_optional_repos_width(
repos_without_specific,
optional_labels,
));
if has_artix {
consumed = consumed.saturating_add(3); }
consumed
}