use ratatui::{style::Style, text::Span};
use crate::theme;
pub struct NodeRef {
pub id: &'static str,
pub label: &'static str,
}
pub const NODES: &[NodeRef] = &[
NodeRef {
id: "0x1",
label: "local",
},
NodeRef {
id: "0xa96f",
label: "main-stage",
},
NodeRef {
id: "0xe9b8",
label: "side-stage",
},
NodeRef {
id: "0xe685",
label: "concert-audio",
},
NodeRef {
id: "0xd4ff",
label: "monitor-mix",
},
NodeRef {
id: "0x3599",
label: "stage-lighting",
},
NodeRef {
id: "0x372b",
label: "ground-station",
},
NodeRef {
id: "0xeba8",
label: "scout-3",
},
NodeRef {
id: "0x82ee",
label: "follower-1",
},
NodeRef {
id: "0xbdda",
label: "ai-gpu-1",
},
NodeRef {
id: "0x6dfb",
label: "ai-gpu-2",
},
NodeRef {
id: "0x3c81",
label: "ai-cache",
},
NodeRef {
id: "0xe068",
label: "robot-arm",
},
NodeRef {
id: "0xbf44",
label: "assembly-line",
},
NodeRef {
id: "0xf206",
label: "chase-truck",
},
NodeRef {
id: "0x6808",
label: "pit-lane",
},
NodeRef {
id: "0xf83d",
label: "edge-drone",
},
NodeRef {
id: "0xfc2",
label: "camera-system",
},
];
pub fn label_of(id: &str) -> Option<&'static str> {
NODES.iter().find(|n| n.id == id).map(|n| n.label)
}
pub fn label_for(id: &str, caps: &std::collections::BTreeSet<String>) -> Option<String> {
if let Some(fixture) = NODES.iter().find(|n| n.id == id) {
return Some(fixture.label.to_string());
}
for cap in caps {
if let Some(rest) = cap.strip_prefix("region:") {
return Some(rest.to_string());
}
if let Some(rest) = cap.strip_prefix("host:") {
return Some(rest.to_string());
}
}
caps.iter().next().cloned()
}
pub fn id_spans_styled(id: &str, id_style: Style) -> Vec<Span<'static>> {
match label_of(id) {
Some(label) => vec![
Span::styled(id.to_string(), id_style),
Span::styled(".", theme::chrome()),
Span::styled(label.to_string(), theme::dim()),
],
None => vec![Span::styled(id.to_string(), id_style)],
}
}
pub fn id_spans(id: &str) -> Vec<Span<'static>> {
id_spans_styled(id, theme::text())
}