1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::utils::render::CliRender;
use comfy_table::{Cell, Table};
use wasmer_backend_api::types::AppRegion;

impl CliRender for AppRegion {
    fn render_item_table(&self) -> String {
        let mut table = Table::new();
        let AppRegion {
            name,
            city,
            country,
            ..
        }: &AppRegion = self;

        table.load_preset(comfy_table::presets::NOTHING);
        table.set_content_arrangement(comfy_table::ContentArrangement::Dynamic);

        table.add_rows([
            vec![
                Cell::new("Name".to_string()).add_attribute(comfy_table::Attribute::Bold),
                Cell::new("City".to_string()).add_attribute(comfy_table::Attribute::Bold),
                Cell::new("Country code".to_string()).add_attribute(comfy_table::Attribute::Bold),
            ],
            vec![
                Cell::new(name.to_string()).add_attribute(comfy_table::Attribute::Bold),
                Cell::new(city.to_string()),
                Cell::new(country.to_string()),
            ],
        ]);
        table.to_string()
    }

    fn render_list_table(items: &[Self]) -> String {
        if items.is_empty() {
            return String::new();
        }
        let mut table = Table::new();
        table.load_preset(comfy_table::presets::NOTHING);
        //table.set_content_arrangement(comfy_table::ContentArrangement::Dynamic);

        table.set_header(vec![
            Cell::new("Name".to_string()).add_attribute(comfy_table::Attribute::Bold),
            Cell::new("City".to_string()).add_attribute(comfy_table::Attribute::Bold),
            Cell::new("Country code".to_string()).add_attribute(comfy_table::Attribute::Bold),
        ]);
        table.add_rows(items.iter().map(|s| {
            vec![
                Cell::new(s.name.to_string()).add_attribute(comfy_table::Attribute::Bold),
                Cell::new(s.city.to_string()),
                Cell::new(s.country.to_string()),
            ]
        }));
        table.to_string()
    }
}