hjkl_engine/lib.rs
1//! Vim-mode editor engine built on top of [`hjkl_buffer`].
2//!
3//! Exposes an [`Editor`] you can drop into a ratatui layout, a command
4//! grammar that covers the bulk of vim's normal / insert / visual /
5//! visual-line / visual-block modes, text-object operators, dot-repeat,
6//! and ex-command handling (`:s/foo/bar/g`, `:w`, `:q`, `:noh`, ...).
7//! Rendering goes through `hjkl_buffer::BufferView`; selection / gutter
8//! highlights are painted in the same single-pass as text.
9//!
10//! Imported wholesale from sqeel-vim with full git history. The trait
11//! extraction (Selection / SelectionSet / Buffer + Host sub-traits per
12//! [`SPEC.md`][spec]) lands progressively under [`crate::types`]. Pre-1.0
13//! churn — the public surface may change in patch bumps.
14//!
15//! [spec]: https://github.com/kryptic-sh/hjkl/blob/main/crates/hjkl-engine/SPEC.md
16//!
17//! The legacy public surface is intentionally narrow:
18//!
19//! - [`Editor`] — the editor widget.
20//! - [`KeybindingMode`] / [`VimMode`] — mode enums used by host apps.
21//! - [`ex::run`] / [`ex::ExEffect`] — drive ex-mode commands.
22
23mod editor;
24mod input;
25mod registers;
26pub mod types;
27mod vim;
28
29pub use editor::{Editor, LspIntent};
30pub use input::{Input, Key};
31pub use registers::{Registers, Slot};
32
33// Internal vim FSM entry points — promoted to pub so ex commands
34// (which now live in `hjkl-editor`) can reach them across the crate
35// boundary. Sealed at 0.1.0 trait extraction.
36pub use types::{
37 Attrs, BufferId, Color, CursorShape, Edit as EditOp, EditorSnapshot, EngineError, Highlight,
38 HighlightKind, Host, Input as PlannedInput, Mode, Modifiers, MouseEvent, MouseKind, Options,
39 Pos, RenderFrame, Selection, SelectionKind, SelectionSet, SnapshotMode, SpecialKey, Style,
40 Viewport as PlannedViewport,
41};
42pub use vim::SearchPrompt;
43#[doc(hidden)]
44pub use vim::{do_redo, do_undo};
45
46/// Which keyboard discipline the editor uses. Currently vim-only, but
47/// kept as an enum so future emacs / plain bindings can slot in without
48/// touching the public signature.
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
50pub enum KeybindingMode {
51 #[default]
52 Vim,
53}
54
55#[cfg(feature = "serde")]
56impl serde::Serialize for KeybindingMode {
57 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
58 s.serialize_str("vim")
59 }
60}
61
62#[cfg(feature = "serde")]
63impl<'de> serde::Deserialize<'de> for KeybindingMode {
64 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
65 let _ = String::deserialize(d)?;
66 Ok(KeybindingMode::Vim)
67 }
68}
69
70/// Coarse vim-mode a host app can display in its status line.
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
72pub enum VimMode {
73 #[default]
74 Normal,
75 Insert,
76 Visual,
77 VisualLine,
78 VisualBlock,
79}