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