From 0db89b1e3a612a4cb6cc014e9b0d5f2cc0ca3534 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Sat, 4 Apr 2026 09:59:01 -0700 Subject: [PATCH] chore: clippy + fmt --- src/command/cmd.rs | 21 ++++---- src/command/keymap.rs | 108 ++++++++++++++++++++++++++++++++---------- src/draw.rs | 4 +- src/ui/app.rs | 3 +- src/ui/tile_bar.rs | 8 +++- 5 files changed, 104 insertions(+), 40 deletions(-) diff --git a/src/command/cmd.rs b/src/command/cmd.rs index fd41698..14882d4 100644 --- a/src/command/cmd.rs +++ b/src/command/cmd.rs @@ -424,7 +424,9 @@ impl Cmd for EnterEditMode { name: "edit".to_string(), 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() { effects.push(Box::new(effect::ClearCell(key))); } else if let Ok(n) = buf.parse::() { - effects.push(Box::new(effect::SetCell( - key, - CellValue::Number(n), - ))); + effects.push(Box::new(effect::SetCell(key, CellValue::Number(n)))); } else { - effects.push(Box::new(effect::SetCell( - key, - CellValue::Text(buf), - ))); + effects.push(Box::new(effect::SetCell(key, CellValue::Text(buf)))); } effects.push(effect::mark_dirty()); } @@ -1184,7 +1180,12 @@ impl Cmd for CommitFormula { } fn execute(&self, ctx: &CmdContext) -> Vec> { 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> = Vec::new(); if let Some(cat) = first_cat { effects.push(Box::new(effect::AddFormula { diff --git a/src/command/keymap.rs b/src/command/keymap.rs index 6022c8c..b38f97c 100644 --- a/src/command/keymap.rs +++ b/src/command/keymap.rs @@ -348,22 +348,34 @@ impl KeymapSet { fp.bind_cmd( KeyCode::Up, 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('k'), 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::Down, 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('j'), 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('n'), none, cmd::EnterFormulaEdit); @@ -379,29 +391,43 @@ impl KeymapSet { cp.bind_cmd( KeyCode::Up, 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::Char('k'), 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::Down, 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::Char('j'), 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::Char(' '), none, cmd::CycleAxisAtCursor); cp.bind_cmd( KeyCode::Char('n'), 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('o'), none, cmd::OpenItemAddAtCursor); @@ -414,22 +440,34 @@ impl KeymapSet { vp.bind_cmd( KeyCode::Up, 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::Char('k'), 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::Down, 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::Char('j'), 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::Char('n'), none, cmd::CreateAndSwitchView); @@ -461,9 +499,13 @@ impl KeymapSet { ed.bind_cmd( KeyCode::Backspace, 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)); // ── Formula edit mode ──────────────────────────────────────────── @@ -473,9 +515,13 @@ impl KeymapSet { fe.bind_cmd( KeyCode::Backspace, 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)); // ── Category add mode ──────────────────────────────────────────── @@ -486,9 +532,13 @@ impl KeymapSet { ca.bind_cmd( KeyCode::Backspace, 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)); // ── Item add mode ──────────────────────────────────────────────── @@ -499,9 +549,13 @@ impl KeymapSet { ia.bind_cmd( KeyCode::Backspace, 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)); // ── Export prompt mode ─────────────────────────────────────────── @@ -511,9 +565,13 @@ impl KeymapSet { ep.bind_cmd( KeyCode::Backspace, 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)); // ── Command mode ───────────────────────────────────────────────── @@ -522,7 +580,9 @@ impl KeymapSet { // Enter → execute_command (still handled by old handler for now — // the complex execute_command logic isn't easily a single Cmd) 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)); // ── Search mode ────────────────────────────────────────────────── diff --git a/src/draw.rs b/src/draw.rs index 2f6d806..c961189 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -116,7 +116,7 @@ fn mode_name(mode: &AppMode) -> &'static str { AppMode::CategoryAdd { .. } => "NEW CATEGORY", AppMode::ItemAdd { .. } => "ADD ITEMS", AppMode::ViewPanel => "VIEWS", - AppMode::TileSelect { .. } => "TILES", + AppMode::TileSelect => "TILES", AppMode::ImportWizard => "IMPORT", AppMode::ExportPrompt { .. } => "EXPORT", AppMode::CommandMode { .. } => "COMMAND", @@ -129,7 +129,7 @@ fn mode_style(mode: &AppMode) -> Style { match mode { AppMode::Editing { .. } => Style::default().fg(Color::Black).bg(Color::Green), 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), } } diff --git a/src/ui/app.rs b/src/ui/app.rs index 96a88a9..24b21a1 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -385,7 +385,6 @@ impl App { Ok(()) } - fn handle_wizard_key(&mut self, key: KeyEvent) -> Result<()> { if let Some(wizard) = &mut self.wizard { match &wizard.step.clone() { @@ -536,7 +535,7 @@ impl App { 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::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::ImportWizard => "Space:toggle c:cycle Enter:next Esc:cancel", _ => "", diff --git a/src/ui/tile_bar.rs b/src/ui/tile_bar.rs index 34f4a25..fc27241 100644 --- a/src/ui/tile_bar.rs +++ b/src/ui/tile_bar.rs @@ -26,7 +26,11 @@ pub struct TileBar<'a> { impl<'a> TileBar<'a> { 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 - 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"; if x + hint.len() as u16 <= area.x + area.width { buf.set_string(x, area.y, hint, Style::default().fg(Color::DarkGray));