curd-editor 0.3.0

A tiny terminal code editor with line numbers, folding and snippets
curd-editor-0.3.0 is not a library.

curd

A tiny terminal code editor written in Rust with crossterm, built step by step as a learning project.

Package name: curd-editor (curd is taken on crates.io). Command name: curd.

Install

One command, no Rust needed. It downloads the latest release for your system.

Linux and macOS:

curl -fsSL https://raw.githubusercontent.com/vikram5258/crud-editor/main/install.sh | sh

Windows (PowerShell):

irm https://raw.githubusercontent.com/vikram5258/crud-editor/main/install.ps1 | iex

Then run curd some-file.txt.

Other ways to get it:

  • With Rust installed: cargo install curd-editor
  • By hand: download a binary from the releases page

Run

cargo run -- src/main.rs

Keys

Key What it does
Typing, Enter, Tab insert text, a new line, four spaces
Backspace / Delete delete before / under the cursor (joins lines at a line edge)
Arrows, Home, End move the cursor; the view scrolls in both directions
Ctrl+S save
Ctrl+K fold / unfold the { ... } block on, or around, the cursor line
Tab after a trigger word expand a snippet (see below)
Ctrl+Q quit (asks for a second press if there are unsaved changes)

Code editing

  • Line numbers in a column on the left.
  • Folding: Ctrl+K collapses a { ... } block into one row, shown as fn main() { ... } with a + beside its line number. Ctrl+K on that row opens it again. Folding only changes the view, never the file.
  • Auto-indent: Enter keeps the current indentation and adds a level after {, ( or [ (and after : in Python). Typing } on a blank line steps back a level.
  • Paste: pasted text goes in exactly as copied, without auto-indent.
  • Snippets: type a trigger word and press Tab. Which ones exist depends on the file extension:
Language Triggers
Rust (.rs) fn main struct enum impl match if for while loop test tests pl
Python (.py) def class if for while main try
JavaScript / TypeScript fn afn if for while log
C / C++ main if for while inc
Go (.go) fn main if for err

For example, in a .rs file main + Tab becomes:

fn main() {
    |
}

curd new-file.txt starts an empty document and creates the file on the first save. The bottom row is a status bar with the file name, a [modified] marker and the cursor position.

Test

cargo test                # unit tests + end-to-end tests
cargo llvm-cov            # same, with a coverage report (cargo install cargo-llvm-cov)
  • Unit tests sit next to the code in src/document/tests.rs and src/editor/tests.rs.
  • End-to-end tests in tests/e2e.rs start the real curd in a pseudo-terminal, send keys and check the screen (Linux/macOS only).

Test files are left out of the published crate (see include in Cargo.toml).

CI runs the tests on every push and pull request and saves a JUnit test report and a coverage report as artifacts on the run. Pushing a v* tag runs the same checks first and only publishes a release (GitHub binaries, then crates.io) if they pass.

Layout

  • src/main.rs — starts everything up
  • src/terminal.rs — raw mode, alternate screen, screen size (restored on drop)
  • src/document.rs — the text (lines), editing it, opening and saving files
  • src/editor.rs — main loop, keys, scrolling, drawing, status bar
  • src/folds.rs — finding { ... } blocks and tracking which are collapsed
  • src/snippets.rs — snippet tables per language

Progress

  • Step 1: raw mode, read keys, Ctrl+Q
  • Step 2: draw the screen with ~ and a welcome message
  • Step 3: open a file and show it (modular refactor)
  • Step 4: cursor movement and vertical scrolling
  • Step 5: typing and deleting
  • Step 6: save with Ctrl+S, unsaved-changes warning, new files
  • Status bar and horizontal scrolling
  • Line numbers, code folding, snippets, auto-indent, paste
  • Syntax highlighting
  • Challenge: PageUp / PageDown
  • Save as (name a file started without one)
  • Search, undo
  • LSP: diagnostics → hover → go to definition → completion