Lines
100 %
Functions
50 %
Branches
//! Templates tab: the user's templates, from `form-options "templates"`.
use ratatui::layout::Constraint;
use scripting::nomiscript::{Value, format_value};
use crate::tabs::plist::plist_text;
use crate::tabs::select_list::{SelectList, SelectRow};
/// One template as the server lists it: its id and unique name.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TemplateRow {
pub id: String,
pub name: String,
}
/// The templates view: exactly the templates the user holds.
pub type TemplatesTab = SelectList<TemplateRow>;
impl SelectRow for TemplateRow {
const HEADERS: &'static [&'static str] = &["Name"];
const WIDTHS: &'static [Constraint] = &[Constraint::Fill(1)];
fn parse(plist: &Value) -> Result<Self, String> {
let malformed = || format!("malformed template: {}", format_value(plist));
let text = |name| plist_text(plist, name).ok_or_else(malformed);
Ok(Self {
id: text(":id")?,
name: text(":label")?,
})
fn key(&self) -> &str {
&self.id
fn cells(&self) -> Vec<String> {
vec![self.name.clone()]
#[cfg(test)]
mod tests;