chore: clippy + fmt

This commit is contained in:
Edward Langley
2026-04-04 09:59:01 -07:00
parent d8f7d9a501
commit 0db89b1e3a
5 changed files with 104 additions and 40 deletions

View File

@ -424,7 +424,9 @@ impl Cmd for EnterEditMode {
name: "edit".to_string(), name: "edit".to_string(),
value: current, value: current,
}), }),
effect::change_mode(AppMode::Editing { buffer: String::new() }), effect::change_mode(AppMode::Editing {
buffer: String::new(),
}),
] ]
} }
} }
@ -1155,15 +1157,9 @@ impl Cmd for CommitCellEdit {
if buf.is_empty() { if buf.is_empty() {
effects.push(Box::new(effect::ClearCell(key))); effects.push(Box::new(effect::ClearCell(key)));
} else if let Ok(n) = buf.parse::<f64>() { } else if let Ok(n) = buf.parse::<f64>() {
effects.push(Box::new(effect::SetCell( effects.push(Box::new(effect::SetCell(key, CellValue::Number(n))));
key,
CellValue::Number(n),
)));
} else { } else {
effects.push(Box::new(effect::SetCell( effects.push(Box::new(effect::SetCell(key, CellValue::Text(buf))));
key,
CellValue::Text(buf),
)));
} }
effects.push(effect::mark_dirty()); effects.push(effect::mark_dirty());
} }
@ -1184,7 +1180,12 @@ impl Cmd for CommitFormula {
} }
fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> { fn execute(&self, ctx: &CmdContext) -> Vec<Box<dyn Effect>> {
let buf = ctx.buffers.get("formula").cloned().unwrap_or_default(); let buf = ctx.buffers.get("formula").cloned().unwrap_or_default();
let first_cat = ctx.model.category_names().into_iter().next().map(String::from); let first_cat = ctx
.model
.category_names()
.into_iter()
.next()
.map(String::from);
let mut effects: Vec<Box<dyn Effect>> = Vec::new(); let mut effects: Vec<Box<dyn Effect>> = Vec::new();
if let Some(cat) = first_cat { if let Some(cat) = first_cat {
effects.push(Box::new(effect::AddFormula { effects.push(Box::new(effect::AddFormula {

View File

@ -348,22 +348,34 @@ impl KeymapSet {
fp.bind_cmd( fp.bind_cmd(
KeyCode::Up, KeyCode::Up,
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Formula, delta: -1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Formula,
delta: -1,
},
); );
fp.bind_cmd( fp.bind_cmd(
KeyCode::Char('k'), KeyCode::Char('k'),
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Formula, delta: -1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Formula,
delta: -1,
},
); );
fp.bind_cmd( fp.bind_cmd(
KeyCode::Down, KeyCode::Down,
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Formula, delta: 1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Formula,
delta: 1,
},
); );
fp.bind_cmd( fp.bind_cmd(
KeyCode::Char('j'), KeyCode::Char('j'),
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Formula, delta: 1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Formula,
delta: 1,
},
); );
fp.bind_cmd(KeyCode::Char('a'), none, cmd::EnterFormulaEdit); fp.bind_cmd(KeyCode::Char('a'), none, cmd::EnterFormulaEdit);
fp.bind_cmd(KeyCode::Char('n'), none, cmd::EnterFormulaEdit); fp.bind_cmd(KeyCode::Char('n'), none, cmd::EnterFormulaEdit);
@ -379,29 +391,43 @@ impl KeymapSet {
cp.bind_cmd( cp.bind_cmd(
KeyCode::Up, KeyCode::Up,
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Category, delta: -1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Category,
delta: -1,
},
); );
cp.bind_cmd( cp.bind_cmd(
KeyCode::Char('k'), KeyCode::Char('k'),
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Category, delta: -1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Category,
delta: -1,
},
); );
cp.bind_cmd( cp.bind_cmd(
KeyCode::Down, KeyCode::Down,
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Category, delta: 1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Category,
delta: 1,
},
); );
cp.bind_cmd( cp.bind_cmd(
KeyCode::Char('j'), KeyCode::Char('j'),
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::Category, delta: 1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::Category,
delta: 1,
},
); );
cp.bind_cmd(KeyCode::Enter, none, cmd::CycleAxisAtCursor); cp.bind_cmd(KeyCode::Enter, none, cmd::CycleAxisAtCursor);
cp.bind_cmd(KeyCode::Char(' '), none, cmd::CycleAxisAtCursor); cp.bind_cmd(KeyCode::Char(' '), none, cmd::CycleAxisAtCursor);
cp.bind_cmd( cp.bind_cmd(
KeyCode::Char('n'), KeyCode::Char('n'),
none, none,
cmd::EnterMode(AppMode::CategoryAdd { buffer: String::new() }), cmd::EnterMode(AppMode::CategoryAdd {
buffer: String::new(),
}),
); );
cp.bind_cmd(KeyCode::Char('a'), none, cmd::OpenItemAddAtCursor); cp.bind_cmd(KeyCode::Char('a'), none, cmd::OpenItemAddAtCursor);
cp.bind_cmd(KeyCode::Char('o'), none, cmd::OpenItemAddAtCursor); cp.bind_cmd(KeyCode::Char('o'), none, cmd::OpenItemAddAtCursor);
@ -414,22 +440,34 @@ impl KeymapSet {
vp.bind_cmd( vp.bind_cmd(
KeyCode::Up, KeyCode::Up,
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::View, delta: -1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::View,
delta: -1,
},
); );
vp.bind_cmd( vp.bind_cmd(
KeyCode::Char('k'), KeyCode::Char('k'),
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::View, delta: -1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::View,
delta: -1,
},
); );
vp.bind_cmd( vp.bind_cmd(
KeyCode::Down, KeyCode::Down,
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::View, delta: 1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::View,
delta: 1,
},
); );
vp.bind_cmd( vp.bind_cmd(
KeyCode::Char('j'), KeyCode::Char('j'),
none, none,
cmd::MovePanelCursor { panel: crate::ui::effect::Panel::View, delta: 1 }, cmd::MovePanelCursor {
panel: crate::ui::effect::Panel::View,
delta: 1,
},
); );
vp.bind_cmd(KeyCode::Enter, none, cmd::SwitchViewAtCursor); vp.bind_cmd(KeyCode::Enter, none, cmd::SwitchViewAtCursor);
vp.bind_cmd(KeyCode::Char('n'), none, cmd::CreateAndSwitchView); vp.bind_cmd(KeyCode::Char('n'), none, cmd::CreateAndSwitchView);
@ -461,9 +499,13 @@ impl KeymapSet {
ed.bind_cmd( ed.bind_cmd(
KeyCode::Backspace, KeyCode::Backspace,
none, none,
cmd::PopChar { buffer: "edit".to_string() }, cmd::PopChar {
buffer: "edit".to_string(),
},
); );
ed.bind_any_char(cmd::AppendChar { buffer: "edit".to_string() }); ed.bind_any_char(cmd::AppendChar {
buffer: "edit".to_string(),
});
set.insert(ModeKey::Editing, Arc::new(ed)); set.insert(ModeKey::Editing, Arc::new(ed));
// ── Formula edit mode ──────────────────────────────────────────── // ── Formula edit mode ────────────────────────────────────────────
@ -473,9 +515,13 @@ impl KeymapSet {
fe.bind_cmd( fe.bind_cmd(
KeyCode::Backspace, KeyCode::Backspace,
none, none,
cmd::PopChar { buffer: "formula".to_string() }, cmd::PopChar {
buffer: "formula".to_string(),
},
); );
fe.bind_any_char(cmd::AppendChar { buffer: "formula".to_string() }); fe.bind_any_char(cmd::AppendChar {
buffer: "formula".to_string(),
});
set.insert(ModeKey::FormulaEdit, Arc::new(fe)); set.insert(ModeKey::FormulaEdit, Arc::new(fe));
// ── Category add mode ──────────────────────────────────────────── // ── Category add mode ────────────────────────────────────────────
@ -486,9 +532,13 @@ impl KeymapSet {
ca.bind_cmd( ca.bind_cmd(
KeyCode::Backspace, KeyCode::Backspace,
none, none,
cmd::PopChar { buffer: "category".to_string() }, cmd::PopChar {
buffer: "category".to_string(),
},
); );
ca.bind_any_char(cmd::AppendChar { buffer: "category".to_string() }); ca.bind_any_char(cmd::AppendChar {
buffer: "category".to_string(),
});
set.insert(ModeKey::CategoryAdd, Arc::new(ca)); set.insert(ModeKey::CategoryAdd, Arc::new(ca));
// ── Item add mode ──────────────────────────────────────────────── // ── Item add mode ────────────────────────────────────────────────
@ -499,9 +549,13 @@ impl KeymapSet {
ia.bind_cmd( ia.bind_cmd(
KeyCode::Backspace, KeyCode::Backspace,
none, none,
cmd::PopChar { buffer: "item".to_string() }, cmd::PopChar {
buffer: "item".to_string(),
},
); );
ia.bind_any_char(cmd::AppendChar { buffer: "item".to_string() }); ia.bind_any_char(cmd::AppendChar {
buffer: "item".to_string(),
});
set.insert(ModeKey::ItemAdd, Arc::new(ia)); set.insert(ModeKey::ItemAdd, Arc::new(ia));
// ── Export prompt mode ─────────────────────────────────────────── // ── Export prompt mode ───────────────────────────────────────────
@ -511,9 +565,13 @@ impl KeymapSet {
ep.bind_cmd( ep.bind_cmd(
KeyCode::Backspace, KeyCode::Backspace,
none, none,
cmd::PopChar { buffer: "export".to_string() }, cmd::PopChar {
buffer: "export".to_string(),
},
); );
ep.bind_any_char(cmd::AppendChar { buffer: "export".to_string() }); ep.bind_any_char(cmd::AppendChar {
buffer: "export".to_string(),
});
set.insert(ModeKey::ExportPrompt, Arc::new(ep)); set.insert(ModeKey::ExportPrompt, Arc::new(ep));
// ── Command mode ───────────────────────────────────────────────── // ── Command mode ─────────────────────────────────────────────────
@ -522,7 +580,9 @@ impl KeymapSet {
// Enter → execute_command (still handled by old handler for now — // Enter → execute_command (still handled by old handler for now —
// the complex execute_command logic isn't easily a single Cmd) // the complex execute_command logic isn't easily a single Cmd)
cm.bind_cmd(KeyCode::Backspace, none, cmd::CommandModeBackspace); cm.bind_cmd(KeyCode::Backspace, none, cmd::CommandModeBackspace);
cm.bind_any_char(cmd::AppendChar { buffer: "command".to_string() }); cm.bind_any_char(cmd::AppendChar {
buffer: "command".to_string(),
});
set.insert(ModeKey::CommandMode, Arc::new(cm)); set.insert(ModeKey::CommandMode, Arc::new(cm));
// ── Search mode ────────────────────────────────────────────────── // ── Search mode ──────────────────────────────────────────────────

View File

@ -116,7 +116,7 @@ fn mode_name(mode: &AppMode) -> &'static str {
AppMode::CategoryAdd { .. } => "NEW CATEGORY", AppMode::CategoryAdd { .. } => "NEW CATEGORY",
AppMode::ItemAdd { .. } => "ADD ITEMS", AppMode::ItemAdd { .. } => "ADD ITEMS",
AppMode::ViewPanel => "VIEWS", AppMode::ViewPanel => "VIEWS",
AppMode::TileSelect { .. } => "TILES", AppMode::TileSelect => "TILES",
AppMode::ImportWizard => "IMPORT", AppMode::ImportWizard => "IMPORT",
AppMode::ExportPrompt { .. } => "EXPORT", AppMode::ExportPrompt { .. } => "EXPORT",
AppMode::CommandMode { .. } => "COMMAND", AppMode::CommandMode { .. } => "COMMAND",
@ -129,7 +129,7 @@ fn mode_style(mode: &AppMode) -> Style {
match mode { match mode {
AppMode::Editing { .. } => Style::default().fg(Color::Black).bg(Color::Green), AppMode::Editing { .. } => Style::default().fg(Color::Black).bg(Color::Green),
AppMode::CommandMode { .. } => Style::default().fg(Color::Black).bg(Color::Yellow), AppMode::CommandMode { .. } => Style::default().fg(Color::Black).bg(Color::Yellow),
AppMode::TileSelect { .. } => Style::default().fg(Color::Black).bg(Color::Magenta), AppMode::TileSelect => Style::default().fg(Color::Black).bg(Color::Magenta),
_ => Style::default().fg(Color::Black).bg(Color::DarkGray), _ => Style::default().fg(Color::Black).bg(Color::DarkGray),
} }
} }

View File

@ -385,7 +385,6 @@ impl App {
Ok(()) Ok(())
} }
fn handle_wizard_key(&mut self, key: KeyEvent) -> Result<()> { fn handle_wizard_key(&mut self, key: KeyEvent) -> Result<()> {
if let Some(wizard) = &mut self.wizard { if let Some(wizard) = &mut self.wizard {
match &wizard.step.clone() { match &wizard.step.clone() {
@ -536,7 +535,7 @@ impl App {
AppMode::CategoryAdd { .. } => "Enter:add & continue Tab:same Esc:done — type a category name", AppMode::CategoryAdd { .. } => "Enter:add & continue Tab:same Esc:done — type a category name",
AppMode::ItemAdd { .. } => "Enter:add & continue Tab:same Esc:done — type an item name", AppMode::ItemAdd { .. } => "Enter:add & continue Tab:same Esc:done — type an item name",
AppMode::ViewPanel => "jk:nav Enter:switch n:new d:delete Esc:back", AppMode::ViewPanel => "jk:nav Enter:switch n:new d:delete Esc:back",
AppMode::TileSelect { .. } => "hl:select Enter:cycle r/c/p/n:set-axis Esc:back", AppMode::TileSelect => "hl:select Enter:cycle r/c/p/n:set-axis Esc:back",
AppMode::CommandMode { .. } => ":q quit :w save :import :add-cat :formula :show-item :help", AppMode::CommandMode { .. } => ":q quit :w save :import :add-cat :formula :show-item :help",
AppMode::ImportWizard => "Space:toggle c:cycle Enter:next Esc:cancel", AppMode::ImportWizard => "Space:toggle c:cycle Enter:next Esc:cancel",
_ => "", _ => "",

View File

@ -26,7 +26,11 @@ pub struct TileBar<'a> {
impl<'a> TileBar<'a> { impl<'a> TileBar<'a> {
pub fn new(model: &'a Model, mode: &'a AppMode, tile_cat_idx: usize) -> Self { pub fn new(model: &'a Model, mode: &'a AppMode, tile_cat_idx: usize) -> Self {
Self { model, mode, tile_cat_idx } Self {
model,
mode,
tile_cat_idx,
}
} }
} }
@ -67,7 +71,7 @@ impl<'a> Widget for TileBar<'a> {
} }
// Hint // Hint
if matches!(self.mode, AppMode::TileSelect { .. }) { if matches!(self.mode, AppMode::TileSelect) {
let hint = " [Enter] cycle axis [r/c/p] set axis [←→] select [Esc] cancel"; let hint = " [Enter] cycle axis [r/c/p] set axis [←→] select [Esc] cancel";
if x + hint.len() as u16 <= area.x + area.width { if x + hint.len() as u16 <= area.x + area.width {
buf.set_string(x, area.y, hint, Style::default().fg(Color::DarkGray)); buf.set_string(x, area.y, hint, Style::default().fg(Color::DarkGray));