1use ratatui::layout::Constraint;
4use scripting::nomiscript::{Value, format_value};
5
6use crate::tabs::plist::plist_text;
7use crate::tabs::select_list::{SelectList, SelectRow};
8
9#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct TemplateRow {
12 pub id: String,
13 pub name: String,
14}
15
16pub type TemplatesTab = SelectList<TemplateRow>;
18
19impl SelectRow for TemplateRow {
20 const HEADERS: &'static [&'static str] = &["Name"];
21 const WIDTHS: &'static [Constraint] = &[Constraint::Fill(1)];
22
23 fn parse(plist: &Value) -> Result<Self, String> {
24 let malformed = || format!("malformed template: {}", format_value(plist));
25 let text = |name| plist_text(plist, name).ok_or_else(malformed);
26 Ok(Self {
27 id: text(":id")?,
28 name: text(":label")?,
29 })
30 }
31
32 fn key(&self) -> &str {
33 &self.id
34 }
35
36 fn cells(&self) -> Vec<String> {
37 vec![self.name.clone()]
38 }
39}
40
41#[cfg(test)]
42mod tests;