From de047ddf1a6757a290a5b498ce9a59879e803366 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Tue, 7 Apr 2026 00:48:22 -0700 Subject: [PATCH] feat(effect): add changes_mode method to Effect trait and use it in ExecuteCommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a `changes_mode` method to the `Effect` trait with a default implementation returning `false` . Implement this method for the `ChangeMode` effect to return `true` . Update the command execution logic to use `e.changes_mode()` instead of string matching on formatted output. Adjust the corresponding test to assert the presence of a mode‑changing effect directly via the new method, removing the temporary debug string. This change introduces a clear, typed way to detect mode‑changing effects, improving readability and reducing reliance on string inspection. Co-Authored-By: fiddlerwoaroof/git-smart-commit (bartowski/nvidia_Nemotron-Cascade-2-30B-A3B-GGUF) --- src/command/cmd.rs | 7 +++---- src/ui/effect.rs | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/command/cmd.rs b/src/command/cmd.rs index 6a2e96d..c09ff38 100644 --- a/src/command/cmd.rs +++ b/src/command/cmd.rs @@ -1632,7 +1632,7 @@ impl Cmd for ExecuteCommand { effects.extend(cmd.execute(ctx)); } // Return to Normal unless a command already changed mode - if !effects.iter().any(|e| format!("{e:?}").contains("ChangeMode")) { + if !effects.iter().any(|e| e.changes_mode()) { effects.push(effect::change_mode(AppMode::Normal)); } effects @@ -2955,10 +2955,9 @@ mod tests { ctx.buffers = &bufs; let cmd = ExecuteCommand; let effects = cmd.execute(&ctx); - let dbg = format!("{:?}", effects); assert!( - dbg.contains("ChangeMode"), - "Expected ChangeMode, got: {dbg}" + effects.iter().any(|e| e.changes_mode()), + "Expected a mode-changing effect" ); } diff --git a/src/ui/effect.rs b/src/ui/effect.rs index f141291..7186095 100644 --- a/src/ui/effect.rs +++ b/src/ui/effect.rs @@ -10,6 +10,10 @@ use super::app::{App, AppMode}; /// Effects know how to apply themselves to the App. pub trait Effect: Debug { fn apply(&self, app: &mut App); + /// Whether this effect changes the app mode. + fn changes_mode(&self) -> bool { + false + } } // ── Model mutations ────────────────────────────────────────────────────────── @@ -328,6 +332,9 @@ impl Effect for ChangeMode { fn apply(&self, app: &mut App) { app.mode = self.0.clone(); } + fn changes_mode(&self) -> bool { + true + } } #[derive(Debug)]