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;
24pub mod ex;
25mod input;
26mod registers;
27pub mod types;
28mod vim;
29
30pub use editor::{Editor, LspIntent};
31pub use input::{Input, Key};
32pub use registers::{Registers, Slot};
33pub use types::{
34 Attrs, Color, CursorShape, Edit as EditOp, Highlight, HighlightKind, Mode, Pos, Selection,
35 SelectionKind, SelectionSet, Style,
36};
37pub use vim::SearchPrompt;
38
39/// Which keyboard discipline the editor uses. Currently vim-only, but
40/// kept as an enum so future emacs / plain bindings can slot in without
41/// touching the public signature.
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
43pub enum KeybindingMode {
44 #[default]
45 Vim,
46}
47
48#[cfg(feature = "serde")]
49impl serde::Serialize for KeybindingMode {
50 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
51 s.serialize_str("vim")
52 }
53}
54
55#[cfg(feature = "serde")]
56impl<'de> serde::Deserialize<'de> for KeybindingMode {
57 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
58 let _ = String::deserialize(d)?;
59 Ok(KeybindingMode::Vim)
60 }
61}
62
63/// Coarse vim-mode a host app can display in its status line.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
65pub enum VimMode {
66 #[default]
67 Normal,
68 Insert,
69 Visual,
70 VisualLine,
71 VisualBlock,
72}