$ show micro-editor/micro
Micro is a terminal-based text editor written in Go, designed to be intuitive and feature-rich. It provides a full editing experience with multiple cursors, tabs, splits, syntax highlighting, undo/redo, search/replace, autocomplete, and a built-in command bar. The architecture follows a modular design with clear separation of concerns: the `internal/action` package handles keybindings and event dispatching via a trie-based key tree; `internal/buffer` manages text buffers using an efficient line array and an event-driven undo stack; `internal/display` renders the editor UI through a window abstraction that supports soft wrapping and status lines; and `internal/screen` wraps the tcell library for terminal I/O. The editor supports Lua-based plugins that hook into lifecycle events and expose Go standard library packages, enabling extensibility without recompilation. External dependencies include tcell (terminal control), gopher-lua (scripting), go-diff (diff computation), and several forked libraries for JSON5 parsing and shell quoting. The main entry point is `cmd/micro/micro.go`, which parses CLI flags, initializes configuration, loads plugins, and runs the event loop. Data flows primarily involve file I/O (reading/writing buffers), terminal input events (keyboard/mouse), and plugin callbacks. The codebase is well-tested with unit tests, generated buffer tests from VSCode model tests, and CI pipelines across platforms.
The LLM identified 4 files worth highlighting for reuse:
A standalone syntax highlighting engine that parses YAML-based language definitions into a rule tree (patterns, regions, includes) and applies them to text lines. It supports nested regions, skip rules, and include resolution. The package is self-contained (only depends on Go standard library and internal unicode helpers) and could be extracted for use in other editors or tools that need configurable syntax highlighting.
An efficient line-based text storage using a slice of lines with operations for insert, remove, split, join, and diff computation. It maintains a line array that supports O(1) access by line number and amortized O(n) modifications. The implementation is isolated from the rest of the buffer package and could be reused in any application requiring a mutable sequence of strings with line-oriented operations.
A trie-based keybinding lookup structure that maps sequences of key events to action names, supporting prefix matching, mode constraints, and chaining. It allows efficient resolution of multi-key sequences and is decoupled from the editor's event loop. The pattern is reusable for any system that needs to map input sequences to commands, such as game controls or terminal multiplexers.
A collection of utility functions including SafeWrite (atomic file write with backup and recovery), GetPathAndCursorPosition (parses file paths with optional line/column or regex), home directory expansion, symlink resolution, and zip-slip-safe unzip. These functions are self-contained and solve common file manipulation problems that recur across projects, making them easily extractable.