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