Skip to main content

hjkl_ex/
effect.rs

1/// Describes what the caller should do after an ex command runs.
2///
3/// Variants that mutate editor state (substitute, goto-line, clear-highlight)
4/// are applied in-place inside the dispatcher; everything else is returned so
5/// the host loop can act on it.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum ExEffect {
8    /// The `:s/pat/rep/c` (or `/gc`) flag triggered interactive confirm-mode.
9    ///
10    /// The caller should enter a per-match prompt loop: display each match,
11    /// ask `y/n/a/q/l`, then apply the accepted subset via
12    /// [`hjkl_engine::apply_collected_matches`].
13    SubstituteConfirm {
14        /// All candidate matches in document order (low row first).
15        matches: Vec<hjkl_engine::SubstituteMatch>,
16    },
17    /// Nothing happened (empty input or no-op effect).
18    None,
19    /// Save the current buffer to the current filename.
20    Save,
21    /// Save to a specific path (`:w <path>`). The caller updates its
22    /// `filename` field so future `:w` writes there.
23    SaveAs(String),
24    /// Quit (`:q`, `:q!`, `:wq`, `:x`).
25    Quit { force: bool, save: bool },
26    /// Unknown command — caller should surface as an error toast.
27    Unknown(String),
28    /// Substitution finished — report replacement count and lines changed.
29    Substituted { count: usize, lines_changed: usize },
30    /// A no-op response for successful commands that don't need a side
31    /// effect but should not be reported as unknown (e.g. `:noh`).
32    Ok,
33    /// Surface an informational message (single-line or unclassified multi-line).
34    Info(String),
35    /// Surface a titled multi-line listing (`:reg`, `:marks`, `:jumps`, `:changes`).
36    ///
37    /// The `title` is a static label used by the host to open a named info
38    /// popup without brittle header-prefix string matching.
39    InfoTitled {
40        /// Short human-readable label for the popup window (e.g. `"registers"`).
41        title: &'static str,
42        /// Full body text, newline-separated.
43        content: String,
44    },
45    /// Surface an error message (syntax error, bad pattern, …).
46    Error(String),
47    /// `:e <path>` / `:edit <path>` — open a different file in the current
48    /// window. An empty `path` means reload the current buffer.
49    EditFile { path: String, force: bool },
50    /// `:bd[!]` / `:bw[!]` — close the current buffer.
51    /// `wipe = true` for `:bwipeout`; `force = true` when `!` was given.
52    BufferDelete { force: bool, wipe: bool },
53    /// `:put [{reg}]` / `:pu [{reg}]` — paste register contents as a new
54    /// line below (or above when `above = true`) the cursor.
55    PutRegister { reg: char, above: bool },
56    /// `:saveas {path}` / `:sav {path}` — write buffer to `path` AND rename
57    /// the buffer identity so future `:w` writes there.
58    /// Distinct from `SaveAs` (`:w <path>`) which writes elsewhere but keeps
59    /// the buffer's own filename unchanged.
60    SaveAndRename { path: String },
61    /// `:file {name}` — rename the current buffer in-memory without writing.
62    RenameBuffer { name: String },
63    /// `:cd [{path}]` — change the working directory. An empty path means
64    /// `$HOME`. The directory change is applied inside the handler; the new
65    /// path is surfaced so the host can update its status-line / title.
66    Cwd(String),
67    /// `:redraw[!]` — signal the host to repaint on the next frame.
68    /// When `clear` is `true` (`:redraw!`) the host should clear the terminal
69    /// before repainting. `:redraw` (no `!`) requests a plain repaint without
70    /// clearing.
71    Redraw { clear: bool },
72    /// `:preserve` — force-write the swap file for the active buffer
73    /// immediately, regardless of the `updatetime` idle timer.
74    Preserve,
75    /// `:recover [file]` — explicitly trigger swap-file recovery.
76    ///
77    /// An empty `path` means recover the current buffer's swap.
78    /// A non-empty `path` means open that file and force recovery on it.
79    Recover(String),
80}