use crate::common::{
config::Config, list::list::List, print_formatted_error::print_formatted_error,
};
use dialoguer::{console::style, theme::ColorfulTheme};
pub fn table(items: Vec<String>, description: String, empty_message: &str, table_headers: String) {
let theme = ColorfulTheme {
prompt_prefix: style(" ".to_string()),
prompt_suffix: style("".to_string()),
..ColorfulTheme::default()
};
let items_per_page = Config::new().items_per_page;
if items.len() == 0 {
println!("{}", empty_message);
std::process::exit(0);
}
match List::with_theme(&theme)
.with_prompt(format!("{}", table_headers))
.with_description(description)
.max_length(items_per_page)
.items(&items)
.clear(true)
.interact_opt()
{
Ok(_) => {
std::process::exit(0);
}
Err(_) => {
print_formatted_error("Service error. Please try again.");
std::process::exit(1);
}
};
}