herolib-mos 0.3.13

Mycelium Operating System (MOS) - Network and VM abstraction layer
Documentation
use crate::systemfacts::SystemFacts;
use crate::mui::sections::{SystemSection, ResourcesSection, StorageSection};
use comfy_table::{Table, Cell, ContentArrangement, Color, Attribute};
use comfy_table::presets::UTF8_FULL;

pub fn print_dashboard(facts: &SystemFacts) {
    let mut table = Table::new();
    table
        .load_preset(UTF8_FULL)
        .set_content_arrangement(ContentArrangement::Dynamic)
        .set_width(100);

    // Title
    table.set_header(vec![
        Cell::new("MOS - Mycelium Operating System").add_attribute(Attribute::Bold).fg(Color::Cyan)
    ]);

    // System Section
    let system_content = if let Some(os) = &facts.os {
        SystemSection::render(os).join("\n")
    } else {
        "System info unavailable".to_string()
    };
    
    // Hardware sections
    let (resource_content, storage_content, network_content) = if let Some(hw) = &facts.hardware {
        (
            ResourcesSection::render(&hw.cpu, &hw.memory, &hw.gpus).join("\n"),
            StorageSection::render(&hw.disks).join("\n"),
            crate::mui::sections::NetworkSection::render(&hw.network_interfaces).join("\n")
        )
    } else {
        (
            "Hardware info unavailable".to_string(),
            "Storage info unavailable".to_string(),
            "Network info unavailable".to_string()
        )
    };

    // Capabilities Section
    let caps_content = if let Some(caps) = &facts.capabilities {
        crate::mui::sections::CapabilitiesSection::render(caps).join("\n")
    } else {
        "Capabilities info unavailable".to_string()
    };

    // Layout: 2 Columns
    // Left: System, Resources, Storage
    // Right: Capabilities, Network

    let left_col = format!(
        "{}\n\n{}\n\n{}",
        block_title("System", system_content),
        block_title("Resources", resource_content),
        block_title("Storage", storage_content)
    );

    let right_col = format!(
        "{}\n\n{}",
        block_title("Capabilities", caps_content),
        block_title("Network", network_content)
    );

    table.add_row(vec![
        Cell::new(left_col),
        Cell::new(right_col)
    ]);

    println!("{}", table);
}

fn block_title(title: &str, content: String) -> String {
    format!("-- {} --\n{}", title, content)
}