Asif Iqbal_
← Projects

Featured

Rust Terminal Editor

A lightweight, terminal-based text editor written in Rust with syntax highlighting, file operations, and full Unicode support.

Stack
RustCrosstermUnicode Segmentation
Topics
RustSystems ProgrammingCLI ToolsText Processing

The problem

Most text editors are either heavy IDEs or minimal line editors—nothing strikes a balance between functionality and simplicity. Building a feature-complete editor requires handling terminal manipulation, Unicode text processing, and interactive input/output. These are easy to get wrong and hard to debug.

Approach

The editor takes a modular component-based architecture:

  • Terminal abstraction via crossterm handles cross-platform ANSI escape sequences
  • Unicode-aware text handling using unicode-segmentation and unicode-width for proper grapheme cluster support
  • Plugin-style syntax highlighting system that's easy to extend with new file type support
  • Separate concerns for View (display/editing), Buffer (file content), StatusBar, MessageBar, and CommandBar

Key features

Text Editing — Full insert, delete, and newline operations with arrow key navigation, page up/down, and home/end support.

File Operations — Open, save, and save-as functionality without external dependencies.

Search & Navigation — Search through text with highlighted matches and arrow key navigation between results.

Syntax Highlighting — Built-in support for Rust files with keyword, type, number, string, and comment coloring. Extensible for other languages.

Unicode Support — Handles international text and emoji correctly through proper grapheme cluster segmentation.

What was interesting

Grapheme clusters. The simple approach is to split text by individual bytes or even Unicode code points, but that breaks with composed characters (accents, emoji with variation selectors, etc.). Using unicode-segmentation to split properly means cursor movement and text deletion work correctly in all languages.

Terminal state management. Raw mode toggling, screen state, and signal handling interact in subtle ways. The architecture isolates terminal concerns so they don't leak into editing logic.

Streaming editing. The view can scroll, selections can span screen boundaries, and search results can be off-screen. Managing the viewport while editing keeps performance constant regardless of file size.

Architecture

src/
├── main.rs                 # Entry point
├── editor/
│   ├── terminal/          # Low-level terminal control
│   ├── command/           # Command parsing
│   ├── line/              # Text line handling
│   └── uicomponents/      # View, StatusBar, MessageBar, CommandBar

Each component has minimal coupling — the editor can use a different terminal backend or highlighting engine without changing the core logic.

Result

A feature-complete, 2000-line text editor that handles real Unicode correctly and runs in any terminal supporting ANSI sequences. The codebase is small enough to understand in an afternoon but structured to grow.