use toml::{Table, Value};
use winit::event::KeyEvent;
use winit::keyboard::{Key, ModifiersState, NamedKey};
use crate::config::{Config, parse_hex};
use crate::keys::{Action, Chord, KeyList, Keymap};
use crate::layout::Rect;
use crate::overlay::Outcome;
use crate::themes;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Page {
Features,
Theme,
Shortcuts,
}
impl Page {
pub const ALL: [Page; 3] = [Page::Features, Page::Theme, Page::Shortcuts];
pub fn label(self) -> &'static str {
match self {
Page::Features => "Features",
Page::Theme => "Theme",
Page::Shortcuts => "Shortcuts",
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Kind {
Toggle,
Number { min: f64, max: f64, step: f64, decimals: usize },
Text,
Color,
Preset(usize),
Shortcut(Action),
Hotkey,
}
#[derive(Clone, Debug)]
pub struct Row {
pub label: String,
pub key: String,
pub kind: Kind,
pub restart: bool,
pub help: &'static str,
}
fn row(key: &str, label: &str, kind: Kind, restart: bool, help: &'static str) -> Row {
Row { label: label.to_string(), key: key.to_string(), kind, restart, help }
}
fn num(min: f64, max: f64, step: f64, decimals: usize) -> Kind {
Kind::Number { min, max, step, decimals }
}
fn feature_rows() -> Vec<Row> {
use Kind::{Text, Toggle};
vec![
row("glass", "Glass window", Toggle, true, "A see-through window with the desktop blurred behind it."),
row("glass_opacity", "Glass opacity", num(0.2, 1.0, 0.05, 2), false, "How solid the panes are. Lower shows more of the desktop."),
row("animation_speed", "Animation speed", num(0.0, 3.0, 0.25, 2), false, "0 turns animations off."),
row("cursor_blink", "Blinking cursor", Toggle, false, ""),
row("copy_on_select", "Copy on select", Toggle, false, "Copy to the clipboard as soon as text is selected."),
row("font_family", "Font", Text, false, "A font installed on this PC, like Cascadia Mono."),
row("font_size", "Font size", num(6.0, 40.0, 1.0, 0), false, "In points."),
row("line_height", "Line height", num(1.0, 2.0, 0.05, 2), false, "A multiple of the font size."),
row("padding", "Pane padding", num(0.0, 40.0, 1.0, 0), false, ""),
row("gap", "Gap between panes", num(0.0, 30.0, 1.0, 0), false, ""),
row("radius", "Corner radius", num(0.0, 30.0, 1.0, 0), false, ""),
row("scrollback", "Scrollback lines", num(1000.0, 200_000.0, 5000.0, 0), false, "How much history a pane keeps for scrolling and search."),
row("shell_integration", "Shell integration", Toggle, true, "The prompt, folder tracking, bare names, open, and the Claude picker (Git Bash)."),
row("shell", "Shell program", Text, true, "Leave empty for Git Bash."),
row("notify_after_secs", "Notify after (seconds)", num(0.0, 300.0, 5.0, 0), false, "Flash the taskbar when a background command or Claude finishes after this long. 0 is off."),
row("links_need_ctrl", "Links need Ctrl", Toggle, false, "Open links, files and folders on Ctrl+click instead of a plain click."),
row("editor", "Editor command", Text, false, "Opens src/main.rs:12:5 from errors. {file}, {line} and {col} are filled in; empty uses the default app."),
row("restore_session", "Restore the last session", Toggle, false, "Reopen the panes and folders you had, when started without a folder."),
row("hotkey", "Show/hide hotkey", Kind::Hotkey, false, "A global key that shows and hides rustimal from anywhere. Needs Ctrl, Alt or Shift."),
row("dropdown", "Drop-down mode", Toggle, false, "The hotkey docks the window across the top of the screen."),
row("dropdown_height", "Drop-down height", num(0.2, 1.0, 0.05, 2), false, "As a fraction of the screen."),
]
}
const COLOR_NAMES: [&str; 8] = ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"];
fn theme_rows() -> Vec<Row> {
let mut rows: Vec<Row> = themes::names()
.into_iter()
.enumerate()
.map(|(i, name)| row("", &format!("Preset: {name}"), Kind::Preset(i), false, "Apply this set of colors."))
.collect();
for (key, label) in [
("background", "Background"),
("surface", "Pane surface"),
("border", "Border"),
("foreground", "Text"),
("cursor", "Cursor"),
("accent", "Accent"),
("selection", "Selection"),
] {
rows.push(row(&format!("theme.{key}"), label, Kind::Color, false, "A color as #rrggbb."));
}
for i in 0..16 {
let name = if i < 8 { COLOR_NAMES[i].to_string() } else { format!("Bright {}", COLOR_NAMES[i - 8].to_lowercase()) };
rows.push(row(&format!("theme.ansi.{i}"), &name, Kind::Color, false, "One of the 16 terminal colors, as #rrggbb."));
}
rows
}
fn shortcut_rows() -> Vec<Row> {
Action::all()
.map(|a| row(a.id(), a.label(), Kind::Shortcut(a), false, "Enter, then press the new keys. Delete restores the default."))
.collect()
}
pub fn lookup<'a>(table: &'a Table, path: &str) -> Option<&'a Value> {
let mut parts = path.split('.');
let mut cur = table.get(parts.next()?)?;
for part in parts {
cur = match cur {
Value::Table(t) => t.get(part)?,
Value::Array(a) => a.get(part.parse::<usize>().ok()?)?,
_ => return None,
};
}
Some(cur)
}
pub fn assign(table: &mut Table, path: &str, value: Value) -> Option<()> {
let mut parts = path.split('.');
let mut cur = table.entry(parts.next()?.to_string()).or_insert_with(|| Value::Table(Table::new()));
for part in parts {
cur = match cur {
Value::Table(t) => t.entry(part.to_string()).or_insert_with(|| Value::Table(Table::new())),
Value::Array(a) => a.get_mut(part.parse::<usize>().ok()?)?,
_ => return None,
};
}
*cur = value;
Some(())
}
fn fmt_num(v: f64, decimals: usize) -> String {
let s = format!("{v:.decimals$}");
if s.contains('.') { s.trim_end_matches('0').trim_end_matches('.').to_string() } else { s }
}
#[derive(Clone, Debug, PartialEq)]
pub enum Input {
Escape,
Enter,
Space,
Up,
Down,
Left,
Right,
PageUp,
PageDown,
Home,
End,
Tab,
BackTab,
Delete,
Backspace,
ClearAll,
Text(String),
Chord(Chord),
}
impl Input {
pub fn from_event(event: &KeyEvent, mods: ModifiersState) -> Option<Input> {
Some(match &event.logical_key {
Key::Named(NamedKey::Escape) => Input::Escape,
Key::Named(NamedKey::Enter) => Input::Enter,
Key::Named(NamedKey::ArrowUp) => Input::Up,
Key::Named(NamedKey::ArrowDown) => Input::Down,
Key::Named(NamedKey::ArrowLeft) => Input::Left,
Key::Named(NamedKey::ArrowRight) => Input::Right,
Key::Named(NamedKey::PageUp) => Input::PageUp,
Key::Named(NamedKey::PageDown) => Input::PageDown,
Key::Named(NamedKey::Home) => Input::Home,
Key::Named(NamedKey::End) => Input::End,
Key::Named(NamedKey::Tab) if mods.shift_key() => Input::BackTab,
Key::Named(NamedKey::Tab) => Input::Tab,
Key::Named(NamedKey::Delete) => Input::Delete,
Key::Named(NamedKey::Backspace) if mods.control_key() => Input::ClearAll,
Key::Named(NamedKey::Backspace) => Input::Backspace,
_ => {
let text = event.text.as_deref().unwrap_or("");
if !mods.control_key() && !mods.alt_key() && !text.is_empty() && !text.chars().any(char::is_control) {
if text == " " { Input::Space } else { Input::Text(text.to_string()) }
} else {
return Chord::from_event(event, mods).map(Input::Chord);
}
}
})
}
}
pub struct Settings {
pub page: Page,
pub table: Table,
defaults: Table,
pub selected: usize,
pub scroll: usize,
pub edit: Option<String>,
pub capturing: bool,
pub message: String,
changed: bool,
pub card: Rect,
pub tabs: [Rect; 3],
pub list: Rect,
pub row_h: f32,
pub visible: usize,
pub controls: Vec<(usize, [Rect; 3])>,
}
impl Settings {
pub fn new(config: &Config) -> Self {
Self {
page: Page::Features,
table: config.to_table(),
defaults: Config::default().to_table(),
selected: 0,
scroll: 0,
edit: None,
capturing: false,
message: String::new(),
changed: false,
card: Rect::default(),
tabs: [Rect::default(); 3],
list: Rect::default(),
row_h: 1.0,
visible: 10,
controls: Vec::new(),
}
}
pub fn rows(&self) -> Vec<Row> {
match self.page {
Page::Features => feature_rows(),
Page::Theme => theme_rows(),
Page::Shortcuts => shortcut_rows(),
}
}
fn row(&self) -> Option<Row> {
self.rows().into_iter().nth(self.selected)
}
pub fn take_changed(&mut self) -> Option<Table> {
std::mem::take(&mut self.changed).then(|| self.table.clone())
}
fn keys_in_table(&self) -> std::collections::BTreeMap<String, KeyList> {
let mut keys = std::collections::BTreeMap::new();
if let Some(Value::Table(t)) = self.table.get("keys") {
for (action, value) in t {
if let Ok(list) = value.clone().try_into::<KeyList>() {
keys.insert(action.clone(), list);
}
}
}
keys
}
pub fn keymap(&self) -> Keymap {
Keymap::build(&self.keys_in_table()).0
}
pub fn is_custom(&self, row: &Row) -> bool {
lookup(&self.table, &row.key) != lookup(&self.defaults, &row.key)
|| matches!(row.kind, Kind::Shortcut(_)) && self.keys_in_table().contains_key(&row.key)
}
pub fn number(&self, row: &Row) -> Option<f64> {
match lookup(&self.table, &row.key)? {
Value::Float(f) => Some(*f),
Value::Integer(i) => Some(*i as f64),
_ => None,
}
}
pub fn toggled(&self, row: &Row) -> bool {
lookup(&self.table, &row.key).and_then(Value::as_bool).unwrap_or(false)
}
pub fn text(&self, row: &Row) -> String {
lookup(&self.table, &row.key).and_then(Value::as_str).unwrap_or("").to_string()
}
pub fn display(&self, row: &Row) -> String {
match &row.kind {
Kind::Toggle => if self.toggled(row) { "on" } else { "off" }.to_string(),
Kind::Number { decimals, .. } => self.number(row).map(|v| fmt_num(v, *decimals)).unwrap_or_default(),
Kind::Text | Kind::Color => self.text(row),
Kind::Preset(_) => String::new(),
Kind::Shortcut(action) => {
let keys = self.keymap().describe(*action);
if keys.is_empty() { "none".to_string() } else { keys }
}
Kind::Hotkey => {
let text = self.text(row);
if text.is_empty() {
"none".to_string()
} else {
Chord::parse(&text).map(|c| c.pretty()).unwrap_or(text)
}
}
}
}
pub fn preset_active(&self, i: usize) -> bool {
let Some(p) = themes::preset(i) else { return false };
let get = |path: &str| lookup(&self.table, path).and_then(Value::as_str).unwrap_or("").to_lowercase();
get("theme.background") == p.background
&& get("theme.accent") == p.accent
&& get("theme.foreground") == p.foreground
&& (0..16).all(|n| get(&format!("theme.ansi.{n}")) == p.ansi[n])
}
fn set(&mut self, path: &str, value: Value) {
if assign(&mut self.table, path, value).is_some() {
self.changed = true;
}
}
fn set_number(&mut self, row: &Row, v: f64) {
let Kind::Number { min, max, step, decimals } = row.kind else { return };
let snapped = (v.clamp(min, max) / step).round() * step;
let scale = 10f64.powi(decimals as i32);
let v = ((snapped * scale).round() / scale).clamp(min, max);
let value = match lookup(&self.table, &row.key) {
Some(Value::Integer(_)) => Value::Integer(v.round() as i64),
_ => Value::Float(v),
};
self.set(&row.key, value);
}
fn reset(&mut self, row: &Row) {
match &row.kind {
Kind::Shortcut(_) => {
if let Some(Value::Table(keys)) = self.table.get_mut("keys")
&& keys.remove(&row.key).is_some()
{
self.changed = true;
}
}
Kind::Preset(_) => {}
_ => {
if let Some(d) = lookup(&self.defaults, &row.key).cloned() {
self.set(&row.key, d);
}
}
}
self.message = format!("{} restored to its default", row.label);
}
fn apply_preset(&mut self, i: usize) {
let Some(t) = themes::preset(i) else { return };
for (key, value) in [
("background", &t.background),
("surface", &t.surface),
("border", &t.border),
("foreground", &t.foreground),
("cursor", &t.cursor),
("accent", &t.accent),
("selection", &t.selection),
] {
self.set(&format!("theme.{key}"), Value::String(value.clone()));
}
for (n, color) in t.ansi.iter().enumerate() {
self.set(&format!("theme.ansi.{n}"), Value::String(color.clone()));
}
self.message = format!("Applied {}", themes::names()[i]);
}
fn commit_text(&mut self, row: &Row, text: String) {
match &row.kind {
Kind::Number { .. } => match text.trim().parse::<f64>() {
Ok(v) if v.is_finite() => self.set_number(row, v),
_ => self.message = format!("{text:?} is not a number"),
},
Kind::Color => {
let hex = if text.trim().starts_with('#') { text.trim().to_lowercase() } else { format!("#{}", text.trim().to_lowercase()) };
if parse_hex(&hex).is_some() {
self.set(&row.key, Value::String(hex));
} else {
self.message = format!("{text:?} is not a color; use #rrggbb");
}
}
_ => self.set(&row.key, Value::String(text.trim().to_string())),
}
}
fn capture(&mut self, row: &Row, chord: Chord) {
match &row.kind {
Kind::Shortcut(action) => {
let taken_from = self.keymap().get(&chord).filter(|a| a != action);
let config = chord.to_config();
self.set(&format!("keys.{}", row.key), Value::String(config));
self.message = match taken_from {
Some(other) => format!("{} now does this; it was {}", chord.pretty(), other.label()),
None => format!("{} set to {}", row.label, chord.pretty()),
};
}
Kind::Hotkey => {
let text = chord.to_config();
if crate::hotkey::parse(&text).is_some() {
self.set("hotkey", Value::String(text));
self.message = format!("The hotkey is {}", chord.pretty());
} else {
self.message = "A global hotkey needs Ctrl, Alt or Shift with another key".to_string();
return;
}
}
_ => {}
}
self.capturing = false;
}
fn move_selection(&mut self, by: isize) {
let n = self.rows().len() as isize;
self.selected = (self.selected as isize + by).clamp(0, (n - 1).max(0)) as usize;
if self.selected < self.scroll {
self.scroll = self.selected;
} else if self.selected >= self.scroll + self.visible {
self.scroll = self.selected + 1 - self.visible;
}
self.message.clear();
}
fn switch_page(&mut self, forward: bool) {
let i = Page::ALL.iter().position(|p| *p == self.page).unwrap_or(0);
let n = Page::ALL.len();
self.show_page(Page::ALL[if forward { (i + 1) % n } else { (i + n - 1) % n }]);
}
pub fn show_page(&mut self, page: Page) {
self.page = page;
self.selected = 0;
self.scroll = 0;
self.edit = None;
self.capturing = false;
self.message.clear();
}
fn nudge(&mut self, row: &Row, dir: f64) {
match &row.kind {
Kind::Number { step, .. } => {
if let Some(v) = self.number(row) {
self.set_number(row, v + dir * step);
}
}
Kind::Toggle => {
let on = dir > 0.0;
if self.toggled(row) != on {
self.set(&row.key, Value::Boolean(on));
}
}
_ => {}
}
}
pub fn activate(&mut self, row: &Row) {
match &row.kind {
Kind::Toggle => {
let on = !self.toggled(row);
self.set(&row.key, Value::Boolean(on));
if row.restart {
self.message = "This takes effect the next time rustimal starts".to_string();
}
}
Kind::Preset(i) => self.apply_preset(*i),
Kind::Shortcut(_) | Kind::Hotkey => {
self.capturing = true;
self.message = "Press the new keys (Esc cancels)".to_string();
}
Kind::Number { .. } | Kind::Text | Kind::Color => self.edit = Some(self.display(row)),
}
}
pub fn input(&mut self, input: Input) -> Outcome<()> {
let Some(row) = self.row() else { return if input == Input::Escape { Outcome::Close } else { Outcome::Stay } };
if self.capturing {
match input {
Input::Escape => {
self.capturing = false;
self.message.clear();
}
Input::Chord(chord) => self.capture(&row, chord),
Input::Text(_) | Input::Enter | Input::Space => {
self.message = "Hold Ctrl, Alt or Shift while pressing the key".to_string();
}
_ => {}
}
return Outcome::Stay;
}
if let Some(text) = self.edit.as_mut() {
match input {
Input::Escape => self.edit = None,
Input::Enter => {
let text = self.edit.take().unwrap_or_default();
self.commit_text(&row, text);
}
Input::Backspace => {
text.pop();
}
Input::ClearAll => text.clear(),
Input::Space => text.push(' '),
Input::Text(t) => text.push_str(&t),
_ => {}
}
return Outcome::Stay;
}
match input {
Input::Escape => return Outcome::Close,
Input::Up => self.move_selection(-1),
Input::Down => self.move_selection(1),
Input::PageUp => self.move_selection(-(self.visible as isize)),
Input::PageDown => self.move_selection(self.visible as isize),
Input::Home => self.move_selection(isize::MIN / 2),
Input::End => self.move_selection(isize::MAX / 2),
Input::Tab => self.switch_page(true),
Input::BackTab => self.switch_page(false),
Input::Left => self.nudge(&row, -1.0),
Input::Right => self.nudge(&row, 1.0),
Input::Enter | Input::Space => self.activate(&row),
Input::Delete | Input::Backspace => self.reset(&row),
_ => {}
}
Outcome::Stay
}
pub fn key(&mut self, event: &KeyEvent, mods: ModifiersState) -> Outcome<()> {
match Input::from_event(event, mods) {
Some(input) => self.input(input),
None => Outcome::Stay,
}
}
pub fn click(&mut self, x: f32, y: f32) -> Outcome<()> {
if !self.card.contains(x, y) {
return Outcome::Close;
}
if let Some(i) = self.tabs.iter().position(|t| t.contains(x, y)) {
self.show_page(Page::ALL[i]);
return Outcome::Stay;
}
let rows = self.rows();
let Some((index, [minus, plus, main])) = self.controls.iter().find(|(_, r)| r.iter().any(|c| c.contains(x, y))).copied()
else {
if self.list.contains(x, y) && self.row_h > 0.0 {
let i = self.scroll + ((y - self.list.y) / self.row_h) as usize;
if i < rows.len() {
self.selected = i;
self.edit = None;
self.capturing = false;
}
}
return Outcome::Stay;
};
self.edit = None;
self.capturing = false;
self.selected = index;
let Some(row) = rows.get(index) else { return Outcome::Stay };
if minus.contains(x, y) && matches!(row.kind, Kind::Number { .. }) {
self.nudge(row, -1.0);
} else if plus.contains(x, y) && matches!(row.kind, Kind::Number { .. }) {
self.nudge(row, 1.0);
} else if main.contains(x, y) {
if matches!(row.kind, Kind::Number { .. }) {
self.activate(row);
} else {
self.activate(row);
}
}
Outcome::Stay
}
pub fn wheel(&mut self, lines: f32) {
let max = self.rows().len().saturating_sub(self.visible);
let by = if lines > 0.0 { -3 } else { 3 };
self.scroll = (self.scroll as isize + by).clamp(0, max as isize) as usize;
}
}
#[cfg(test)]
mod tests {
use super::*;
fn settings() -> Settings {
Settings::new(&Config::default())
}
fn select(s: &mut Settings, key: &str) -> Row {
let i = s.rows().iter().position(|r| r.key == key).unwrap_or_else(|| panic!("no row {key}"));
s.selected = i;
s.rows()[i].clone()
}
fn ctrl_shift(key: &str) -> Chord {
Chord::parse(&format!("ctrl+shift+{key}")).unwrap()
}
#[test]
fn paths_reach_into_tables_and_arrays() {
let mut t = Config::default().to_table();
assert_eq!(lookup(&t, "theme.ansi.1").and_then(Value::as_str), Some("#ef7a7f"));
assert!(assign(&mut t, "theme.ansi.1", Value::String("#112233".into())).is_some());
assert_eq!(lookup(&t, "theme.ansi.1").and_then(Value::as_str), Some("#112233"));
assert!(lookup(&t, "theme.ansi.99").is_none() && lookup(&t, "nope.x").is_none());
assert!(assign(&mut t, "keys.find", Value::String("f3".into())).is_some());
assert_eq!(lookup(&t, "keys.find").and_then(Value::as_str), Some("f3"));
}
#[test]
fn toggles_numbers_and_text_edit_and_report_changes() {
let mut s = settings();
assert!(s.take_changed().is_none());
let row = select(&mut s, "cursor_blink");
assert!(s.toggled(&row));
s.input(Input::Enter);
assert!(!s.toggled(&row));
assert!(s.take_changed().is_some(), "a change is reported once");
assert!(s.take_changed().is_none());
let row = select(&mut s, "glass_opacity");
assert_eq!(s.display(&row), "0.66");
s.input(Input::Right);
assert_eq!(s.display(&row), "0.7", "snapped to the step");
for _ in 0..20 {
s.input(Input::Right);
}
assert_eq!(s.display(&row), "1", "stops at the maximum");
s.input(Input::Enter);
s.input(Input::ClearAll);
s.input(Input::Text("0.05".into()));
s.input(Input::Enter);
assert_eq!(s.display(&row), "0.2");
s.input(Input::Enter);
s.input(Input::ClearAll);
s.input(Input::Text("lots".into()));
s.input(Input::Enter);
assert!(s.message.contains("not a number"), "{}", s.message);
assert_eq!(s.display(&row), "0.2", "a bad value changes nothing");
let row = select(&mut s, "scrollback");
s.input(Input::Right);
assert_eq!(lookup(&s.table, "scrollback"), Some(&Value::Integer(25_000)));
let row2 = select(&mut s, "editor");
s.input(Input::Enter);
s.input(Input::ClearAll);
s.input(Input::Text("notepad {file}".into()));
s.input(Input::Enter);
assert_eq!(s.text(&row2), "notepad {file}");
let _ = row;
}
#[test]
fn delete_restores_the_default() {
let mut s = settings();
let row = select(&mut s, "font_size");
for _ in 0..3 {
s.input(Input::Right);
}
assert_eq!(s.display(&row), "14");
assert!(s.is_custom(&row));
s.input(Input::Delete);
assert_eq!(s.display(&row), "11");
assert!(!s.is_custom(&row));
}
#[test]
fn colors_are_checked_and_presets_apply_whole_themes() {
let mut s = settings();
s.show_page(Page::Theme);
let row = select(&mut s, "theme.accent");
s.input(Input::Enter);
s.input(Input::ClearAll);
s.input(Input::Text("ff8800".into()));
s.input(Input::Enter);
assert_eq!(s.text(&row), "#ff8800", "the # is added");
s.input(Input::Enter);
s.input(Input::ClearAll);
s.input(Input::Text("#zzz".into()));
s.input(Input::Enter);
assert!(s.message.contains("not a color"));
assert_eq!(s.text(&row), "#ff8800");
assert!(!s.preset_active(0), "the accent was changed");
s.selected = 1; s.input(Input::Enter);
assert!(s.preset_active(1));
let background = select(&mut s, "theme.background");
assert_eq!(s.text(&background), "#f5f6f8");
let bright_white = select(&mut s, "theme.ansi.15");
assert_eq!(s.text(&bright_white), "#8c959f");
assert!(Config::from_table(s.table.clone()).is_ok());
}
#[test]
fn shortcuts_are_captured_and_can_be_reset() {
let mut s = settings();
s.show_page(Page::Shortcuts);
let row = select(&mut s, "find");
assert_eq!(s.display(&row), "Ctrl+Shift+F");
s.input(Input::Enter);
assert!(s.capturing);
s.input(Input::Text("x".into()));
assert!(s.capturing && s.message.contains("Hold Ctrl"));
s.input(Input::Chord(ctrl_shift("z")));
assert!(!s.capturing);
assert_eq!(s.display(&row), "Ctrl+Shift+Z");
assert!(s.message.contains("Zoom the pane"), "{}", s.message);
let zoom = select(&mut s, "zoom");
assert_eq!(s.display(&zoom), "none", "zoom lost its key");
assert_eq!(lookup(&s.table, "keys.find").and_then(Value::as_str), Some("ctrl+shift+z"));
assert!(s.is_custom(&row));
select(&mut s, "find");
s.input(Input::Enter);
s.input(Input::Escape);
assert!(!s.capturing);
assert_eq!(s.display(&row), "Ctrl+Shift+Z");
s.input(Input::Delete);
assert_eq!(s.display(&row), "Ctrl+Shift+F");
assert_eq!(lookup(&s.table, "keys.find"), None);
}
#[test]
fn the_hotkey_needs_a_modifier_and_pages_cycle() {
let mut s = settings();
let row = select(&mut s, "hotkey");
assert_eq!(s.display(&row), "none");
s.input(Input::Enter);
s.input(Input::Chord(Chord::parse("f9").unwrap()));
assert!(s.message.contains("needs Ctrl"), "{}", s.message);
s.input(Input::Chord(Chord::parse("ctrl+alt+space").unwrap()));
assert_eq!(s.text(&row), "ctrl+alt+space");
assert_eq!(s.display(&row), "Ctrl+Alt+Space");
assert_eq!(s.page, Page::Features);
s.input(Input::Tab);
assert_eq!(s.page, Page::Theme);
s.input(Input::BackTab);
s.input(Input::BackTab);
assert_eq!(s.page, Page::Shortcuts, "wraps around");
assert_eq!(s.input(Input::Escape), Outcome::Close);
}
#[test]
fn every_row_points_at_a_real_setting() {
let s = settings();
for page in Page::ALL {
let mut s2 = Settings::new(&Config::default());
s2.show_page(page);
for row in s2.rows() {
match row.kind {
Kind::Preset(_) | Kind::Shortcut(_) => {}
_ => assert!(lookup(&s.table, &row.key).is_some(), "{} is not a setting", row.key),
}
if let Kind::Number { min, max, step, .. } = row.kind {
let v = s.number(&row).unwrap();
assert!(v >= min && v <= max && step > 0.0, "{}: {v} outside {min}..{max}", row.key);
}
}
}
}
}