Lines
100 %
Functions
50 %
Branches
//! Config tab: every key of the user with its value, from `list-config`.
use ratatui::layout::Constraint;
use scripting::nomiscript::{Value, format_value};
use crate::tabs::plist::plist_text;
use crate::tabs::select_list::{SelectList, SelectRow};
/// One stored config key with its value.
pub type ConfigEntry = (String, String);
/// The `list-config` view: exactly the user's stored keys.
pub type ConfigTab = SelectList<ConfigEntry>;
impl SelectList<ConfigEntry> {
/// Key and stored value of the selected row.
#[must_use]
pub fn selected_edit(&self) -> Option<ConfigEntry> {
self.selected_row().cloned()
}
impl SelectRow for ConfigEntry {
const HEADERS: &'static [&'static str] = &["Key", "Value"];
const WIDTHS: &'static [Constraint] = &[Constraint::Percentage(40), Constraint::Percentage(60)];
fn parse(plist: &Value) -> Result<Self, String> {
let malformed = || format!("malformed config entry: {}", format_value(plist));
let key = plist_text(plist, ":key").ok_or_else(malformed)?;
let value = plist_text(plist, ":value").ok_or_else(malformed)?;
Ok((key, value))
fn key(&self) -> &str {
&self.0
fn cells(&self) -> Vec<String> {
vec![self.0.clone(), self.1.clone()]
fn has_key(&self, key: &str) -> bool {
self.0.eq_ignore_ascii_case(key)
#[cfg(test)]
mod tests;