Skip to main content

Crate caretline

Crate caretline 

Source
Expand description

caretline: a standalone text-editing engine.

The editing model is Helix’s (vendored under helix): a rope, multi-range Selections of anchor and head, every edit a Transaction that maps selections through its changes, an undo History tree, grapheme-correct motion, and the DocumentFormatter for soft wrap.

Around it is a strict Elm architecture:

  • State holds everything: text, selection (with the goal column), scroll, viewport, clipboard register, history, config. It serializes to JSON and back without loss.
  • Msg is every input, Effect every output. Both are plain values.
  • [update] is pure and deterministic: no clock, randomness or I/O. Time arrives in Msg::Tick.
  • [view] is pure: state in, a cell grid (Frame) out.
  • keymap is a pure function from a key to an optional message.

So a session is its initial state plus its messages, and replaying them reproduces it exactly (trace). Session keeps one (state, revision, trace) and protocol answers JSON requests against it.

Re-exports§

pub use commands::command_msg;
pub use commands::commands;
pub use commands::default_keymap;
pub use commands::Binding;
pub use commands::Category;
pub use commands::CommandInfo;
pub use commands::Platform;
pub use host::Ctx;
pub use host::Deco;
pub use host::Decoration;
pub use host::Edit;
pub use host::Host;
pub use host::MarkOp;
pub use marks::MarkAttrs;
pub use marks::Mark;
pub use marks::MarkId;
pub use marks::Marks;
pub use outline::BlockInfo;
pub use outline::Kind;
pub use outline::NewBlock;
pub use outline::Outline;
pub use outline::OutlineConfig;
pub use keymap::keymap;
pub use keymap::keymap_for;
pub use keymap::outline_keymap;
pub use keymap::parse_keys;
pub use keymap::script_to_msgs;
pub use keymap::script_to_msgs_for;
pub use keymap::Key;
pub use keymap::KeyCode;
pub use keymap::Mods;
pub use external::ExtChange;
pub use msg::By;
pub use msg::Dir;
pub use msg::Effect;
pub use msg::Msg;
pub use session::Session;
pub use state::Config;
pub use state::Document;
pub use state::ExternalUndo;
pub use state::Follow;
pub use state::Scroll;
pub use state::State;
pub use state::View;
pub use state::ViewConfig;
pub use state::Viewport;
pub use update::replay;
pub use update::update;
pub use views::update_doc;
pub use layout::OutlineLayout;
pub use view::view;
pub use view::Frame;

Modules§

commands
The editing vocabulary: every generic editing command with a stable id, a name, a short description and a category, each one message (command_msg), and the default keymap as data (default_keymap): key chord → command id.
diff
The least changes from one text to another, for pushing a whole new text into a live document (crate::Session::set_text, the protocol’s text.set) without disturbing what didn’t change: carets, selections, marks and undo steps outside the changes stay.
external
Changes from outside the editor: another device, a daemon, an agent. Msg::External carries ExtChanges, which the engine turns into transactions and applies to the document outside the undo history:
helix
Helix’s editing core, vendored.
host
What a host adds to the engine: named commands, input rules and a decorator.
keymap
Keys: a terminal-independent key type, the keymap (a pure function from a key to a message), and the key-script notation used by tests and the headless CLI.
layout
Layout on top of Helix’s DocumentFormatter: visual rows, the caret’s place on screen, and keeping it in view. Shared by update (motion, scrolling) and view (drawing).
marks
Block marks: numeric ids pinned to line starts, mapped through every edit.
msg
Messages into update and effects out of it. Both are plain, serializable values.
outline
The outline layer: blocks on top of the text, bounded by marks.
protocol
The state protocol: JSON requests in, JSON responses out, one per line. See docs/caretline/protocol.md for the wire format with examples.
session
An in-process editing session: a State, a revision counter and the trace of what was applied, split into segments. It is the library face of the state protocol (crate::protocol); the caretline binary serves the same operations over stdio and Unix sockets.
state
The editor’s whole state, split in two: a Document (the text, its marks, undo history and outline) and a View of it (selection, scroll, viewport, folds). Several views can share one document (crate::update_doc); State is one document seen through one view, the single-view editor the protocol, traces and the caretline binary use.
trace
Traces: a JSON Lines record of a session. The first line holds the initial state and every later line one message, so folding the messages into the state with update reproduces the session exactly.
update
update: the one place state changes. Pure and deterministic: no clock, no randomness, no I/O. Time arrives in Msg::Tick; work for the outside world leaves as Effects.
view
view: a pure function from the state to a grid of cells, plus text and ANSI renderers for snapshots. A terminal front end copies the grid to the screen.
views
Several views of one document: update_doc, rebasing views through edits made in another, and folds (which belong to a view).