wasmer_cli/commands/app/regions/utils/
render.rs

1use crate::utils::render::CliRender;
2use comfy_table::{Cell, Table};
3use wasmer_backend_api::types::AppRegion;
4
5impl CliRender for AppRegion {
6    fn render_item_table(&self) -> String {
7        let mut table = Table::new();
8        let AppRegion {
9            name,
10            city,
11            country,
12            ..
13        }: &AppRegion = self;
14
15        table.load_preset(comfy_table::presets::NOTHING);
16        table.set_content_arrangement(comfy_table::ContentArrangement::Dynamic);
17
18        table.add_rows([
19            vec![
20                Cell::new("Name".to_string()).add_attribute(comfy_table::Attribute::Bold),
21                Cell::new("City".to_string()).add_attribute(comfy_table::Attribute::Bold),
22                Cell::new("Country code".to_string()).add_attribute(comfy_table::Attribute::Bold),
23            ],
24            vec![
25                Cell::new(name.to_string()).add_attribute(comfy_table::Attribute::Bold),
26                Cell::new(city.to_string()),
27                Cell::new(country.to_string()),
28            ],
29        ]);
30        table.to_string()
31    }
32
33    fn render_list_table(items: &[Self]) -> String {
34        if items.is_empty() {
35            return String::new();
36        }
37        let mut table = Table::new();
38        table.load_preset(comfy_table::presets::NOTHING);
39        //table.set_content_arrangement(comfy_table::ContentArrangement::Dynamic);
40
41        table.set_header(vec![
42            Cell::new("Name".to_string()).add_attribute(comfy_table::Attribute::Bold),
43            Cell::new("City".to_string()).add_attribute(comfy_table::Attribute::Bold),
44            Cell::new("Country code".to_string()).add_attribute(comfy_table::Attribute::Bold),
45        ]);
46        table.add_rows(items.iter().map(|s| {
47            vec![
48                Cell::new(s.name.to_string()).add_attribute(comfy_table::Attribute::Bold),
49                Cell::new(s.city.to_string()),
50                Cell::new(s.country.to_string()),
51            ]
52        }));
53        table.to_string()
54    }
55}