duat_utils/modes/mod.rs
1//! Additional [`Mode`]s for Duat
2//!
3//! This module adds some very important [`Mode`]s, not only for base
4//! Duat configuration, but also in extending it with a lot of
5//! functionality.
6//!
7//! Chief among the extensible modes in here is the [`Prompt`] and
8//! [`IncSearch`] [`Mode`]s, which can leverage traits to do a wide
9//! variety of things:
10//!
11//! ```rust
12//! use duat_core::{prelude::*, text::Searcher};
13//! use duat_utils::modes::IncSearcher;
14//!
15//! #[derive(Clone, Copy)]
16//! struct KeepMatching;
17//!
18//! impl<U: Ui> IncSearcher<U> for KeepMatching {
19//! fn search(&mut self, pa: &mut Pass, handle: Handle<File<U>, U, Searcher>) {
20//! handle.edit_all(pa, |mut c| {
21//! c.set_caret_on_start();
22//! let [_, end] = c.range();
23//! if c.search_inc_fwd(Some(end)).next().is_none() {
24//! c.destroy();
25//! }
26//! });
27//! }
28//!
29//! fn prompt(&self) -> Text {
30//! txt!("[Prompt]keep matching[Prompt.colon]:").build()
31//! }
32//! }
33//! ```
34//!
35//! The above [`IncSearcher`] will do the incremental search, and keep
36//! only the [`Cursor`]s that matched at some point inside of their
37//! selections.
38//!
39//! [`Mode`]: duat_core::mode::Mode
40//! [`Cursor`]: duat_core::mode::Cursor
41pub use self::{
42 inc_search::{ExtendFwd, ExtendRev, IncSearcher, SearchFwd, SearchRev},
43 prompt::{IncSearch, PipeSelections, Prompt, PromptMode, RunCommands},
44 regular::Regular,
45 pager::{Pager, PagerSearch}
46};
47
48mod inc_search;
49mod prompt;
50mod regular;
51mod pager;