A minimal, zero-dependency C++23 terminal text editor built on standardized ANSI / ECMA-48 + modern xterm protocols (no ncurses), structured around a strict Smalltalk-80 Model / View / Controller architecture and the Principle of Local Certainty.
POSIX TTY (RawTerminal RAII)
│ raw bytes
▼
AnsiDecoder (pure) ──► Event (Key / Paste / Resize)
│
▼
Controller / Editor (Symbol / Macro / Token)
│ mutations + UndoLog
▼
Model (Document + per-line GapBuffer)
│ const borrow
▼
View (pure render -> CellGrid: mark / show / hide)
│ prev vs next CellGrid
▼
AnsiEncoder (pure diff -> synchronized ANSI + OSC 52)
│ single buffered write
▼
POSIX TTY
- Standardized ANSI, zero curses: Uses alternate screen (
?1049h/l), synchronized updates (?2026h/l), bracketed paste (?2004h/l), xtermmodifyOtherKeys+ Kitty CSI-u, and OSC 52 clipboard. - Structural nesting colorization (optional,
F4): Colors()(expressions / Lisp lists),{}(statement blocks), and[](subscripts/vectors) by independent per-kind nesting depth, cycling a 6-color ANSI palette with no depth limit (built for deeply nested Lisp as well as C/C++), and highlights mismatched/unmatched closers in red. Skips strings and comments (including Lisp',;,#\(char literals, and nested#| ... |#block comments). Defaults on for code files, off for plain text/Markdown, and toggles live anytime withF4or--color/--no-color. - Local Certainty: Value semantics,
std::expectedfor fallible file I/O and terminal initialization,std::span/std::string_viewborrows, RAII POSIX handles (RawTerminal,UniqueFd,TempFileGuard), zero rawnew/delete, and zero external libraries. - Paper-like data safety: Refuses non-regular files (directories, FIFOs, devices), NUL-byte binary files, and size/memory limits; saves atomically via sibling temp file +
fchmod+fsync+renamewhile following symlinks; writes crash-recovery files (.<name>.mod.recovery) on periodic autosave andSIGTERM/SIGHUP(restorable withF6); persists undo/redo across sessions in a0700per-user directory verified by content fingerprint.
- On Haiku OS the arrow keys are corrupt and select is disfunctional. It is an Error in Haiku terminal with non-ANSI to some extent.
Requires a C++23 compiler (GCC 14+ or Clang 18+) and GNU Make.
make # build ./mod
make test # build and run headless ./mod_test
make sanitize # build and run ./mod_test with ASan + UBSan
make fuzz # build and run randomized property-based fuzzer (build/mod_fuzz)
make fuzz-san # build and run fuzzer under ASan + UBSan (pass FUZZ_ARGS="--seed ... --iters ...")
make install # install mod to $(PREFIX)/bin (default /usr/local/bin)
make doc # install man page mod.1 to $(PREFIX)/share/man/man1
make cleanRead the manual page directly with man -l mod.1 (or man mod after make doc).
./mod [--color | --no-color] [--wrap | --no-wrap] [--config FILE] [file[:line[:col]]] [+line]| Key | Action |
|---|---|
Ctrl+S |
Save (atomic write) |
Ctrl+Q |
Quit (press twice if modified) |
Ctrl+Z / Ctrl+Y |
Undo / Redo |
Ctrl+A |
Select all |
Shift+Arrows / Home / End |
Extend selection |
Ctrl+Left / Ctrl+Right |
Word left / right |
Ctrl+Home / Ctrl+End |
Top / bottom of document |
Ctrl+C / Ctrl+X / Ctrl+V |
Copy (OSC 52 / external cmd) / Cut / Lossless paste |
Ctrl+/ or Ctrl+F |
Regex search (F3 for next match) |
Ctrl+R |
Regex replace all (one atomic undo step) |
Ctrl+G |
Go to line or line:col |
Ctrl+K |
Toggle line comment (//, ; in Lisp, # in shell/Python) |
Ctrl+W |
Delete previous word |
Ctrl+] |
Jump to matching () / {} / [] |
F2 |
Toggle line numbers |
F4 |
Toggle nesting colorization on/off |
F5 |
Toggle soft word wrap on/off |
F6 |
Restore unsaved buffer from crash recovery file (undoable) |
Tab / Shift+Tab |
Indent / unindent (respects spaces_for_tab & tab_width) |
Enter |
Smart indent (keeps indent, adds a level after {, (, [) |
Esc |
Cancel prompt or clear selection |
On first run, mod writes a commented default ~/.config/mod/mod.conf (or $XDG_CONFIG_HOME/mod/mod.conf) without overwriting an existing file. Pass --config FILE to use a different config file.
tab_width=4
spaces_for_tab=0
show_line_numbers=0 # 0, 1, or auto
colorize=auto # 0, 1, or auto
word_wrap=0
show_version=1
persistent_undo=1 # save/restore undo history across sessions
autosave_edits=50 # write recovery file every N edits (0 disables)
autosave_seconds=60 # write recovery file after N idle seconds (0 disables)
system_clipboard=1 # 0 disables outgoing OSC 52
clipboard_copy= # e.g. wl-copy, xclip -selection clipboard, pbcopy
clipboard_paste= # e.g. wl-paste --no-newline, xclip -selection clipboard -o, pbpaste
# Nesting delimiter palette (names, LIGHT_* / BRIGHT_*, DEFAULT, or 0-255)
nest1_fg=LIGHT_BLUE
nest2_fg=LIGHT_CYAN
nest3_fg=LIGHT_GREEN
nest4_fg=LIGHT_YELLOW
nest5_fg=LIGHT_MAGENTA
nest6_fg=LIGHT_RED
mismatch_fg=LIGHT_WHITE
mismatch_bg=RED- Completed: Core MVC + standardized ANSI terminal engine, per-line
GapBuffer, safe atomic I/O, crash-recovery autosave (SIGTERM/SIGHUP+F6restore), persistent undo across sessions, UTF-8 editing, grouped undo/redo, selection, OSC 52 + external clipboard commands + lossless bracketed paste, regex search & replace (Ctrl+R),Ctrl+Kcomments,Ctrl+W, smart indent, soft word wrap (F5), optional structural nesting colorization (F4) with independent{}/()/[]depth &Ctrl+]jump,~/.config/mod/mod.conf,mod.1man page, headless + ASan/UBSan tests, and deterministic seed-reproducible randomized fuzz testing harness (make fuzz/make fuzz-san).