A comprehensive text editor implementation showcasing two different approaches: a modular C implementation and a modern Rust implementation with safety guarantees and SOLID design principles.
.
├── c-implementation/ # Original C implementation (modularized)
│ ├── README.md # C-specific documentation
│ ├── Makefile # Build system for C version
│ ├── *.h # Header files (interfaces)
│ └── *.c # Implementation files
│
├── rust-implementation/ # Modern Rust implementation
│ ├── README.md # Rust-specific documentation
│ ├── Cargo.toml # Rust dependencies and build config
│ └── src/ # Rust source code
│ ├── core.rs # Core traits and types
│ ├── buffer/ # Memory-safe text buffer
│ ├── display/ # Terminal rendering
│ ├── editor_ops/ # Editor operations
│ ├── file_io/ # File I/O with validation
│ ├── undo/ # Type-safe undo system
│ ├── lib.rs # Library exports
│ └── main.rs # Main application
│
├── README.md # This file (project overview)
└── readme.md # Original detailed technical analysis
This project demonstrates the evolution of software engineering practices by implementing the same text editor functionality in two different languages and paradigms:
- Focus: Low-level control and performance
- Architecture: Modularized C with clear separation of concerns
- Memory Management: Manual allocation/deallocation
- Error Handling: Return codes and careful checking
- Strengths: Direct hardware control, minimal overhead
- Challenges: Memory safety, error-prone manual management
- Focus: Safety, reliability, and maintainability
- Architecture: SOLID principles with trait-based design
- Memory Management: Automatic with ownership system
- Error Handling: Comprehensive
Result<T>types - Strengths: Memory safety, zero-cost abstractions, excellent tooling
- Modern Features: Dependency injection, comprehensive testing
# Clone the repository
git clone <repository-url>
cd textEditorinC
# Run the installation script (installs dependencies and builds both versions)
./install.sh
# Use the editors
teditor filename.txt # Rust version (primary)
teditor-c filename.txt # C version# For interactive build process
./build.sh
# Or build manually:
# C Version
cd c-implementation
sudo apt install libncurses-dev # Install dependencies
make
./your-editor [filename]
# Rust Version
cd rust-implementation
sudo apt install libncurses-dev # Install dependencies
cargo build --release
./target/release/text-editor [filename]After building, install system-wide manually:
# Build first
./build.sh
# Install C version
sudo cp c-implementation/your-editor /usr/local/bin/teditor-c
# Install Rust version
sudo cp rust-implementation/target/release/text-editor /usr/local/bin/teditor
# Make executable (if needed)
sudo chmod +x /usr/local/bin/teditor*
# Now use anywhere
teditor filename.txt
teditor-c filename.txtDownload pre-built binaries from the releases section:
# Extract and install
tar -xzf text-editor-1.0.0-linux-x86_64.tar.gz
cd text-editor-binary
sudo ./install.sh| Feature | C Implementation | Rust Implementation |
|---|---|---|
| Text Editing | ✅ Full featured | ✅ Full featured |
| Syntax Highlighting | ✅ Basic (C keywords) | ✅ Enhanced (Rust keywords) |
| Undo/Redo | ✅ Stack-based | ✅ Type-safe with action history |
| File I/O | ✅ Basic | ✅ With validation and backups |
| Vim Commands | ✅ :e, :w, :q, :wq | ✅ Full vim-like command set |
| Multi-buffer | ❌ Single file | ✅ Multiple files with switching |
| Read-only Mode | ✅ Command-line flag | ✅ Command-line flag |
| Command-line Args | ✅ Basic file opening | ✅ Advanced with clap |
| Memory Safety | ✅ Guaranteed by compiler | |
| Error Handling | ✅ Comprehensive Result types | |
| Testing | ❌ Manual testing | ✅ Unit tests included |
| Modularity | ✅ Header-based | ✅ Trait-based with DI |
| Performance | ✅ Direct control | ✅ Zero-cost abstractions |
- Low-level memory management techniques
- Manual resource handling and cleanup
- Terminal programming with ncurses
- Modular design in C using headers
- Performance optimization strategies
- Memory safety without garbage collection
- SOLID principles in systems programming
- Trait-based architecture and dependency injection
- Comprehensive error handling patterns
- Modern testing practices
// Clean interfaces with header files
typedef struct Buffer Buffer;
void initBuffer(Buffer *buffer);
void insertIntoBuffer(Buffer *buffer, int pos, char ch);// Flexible, testable interfaces
pub trait TextBuffer {
fn insert(&mut self, pos: usize, ch: char) -> Result<()>;
fn delete(&mut self, pos: usize) -> Result<()>;
}
pub trait DisplayManager {
fn render_text(&mut self, text: &str) -> Result<()>;
}Both implementations are designed for:
- Real-time text editing performance
- Efficient memory usage patterns
- Responsive terminal interaction
- Scalability to reasonably large files
The Rust version achieves C-like performance while providing safety guarantees that prevent entire classes of bugs common in C programs.
Both implementations require ncurses development headers:
# Ubuntu/Debian
sudo apt install libncurses-dev
# CentOS/RHEL/Fedora
sudo yum install ncurses-devel
# or
sudo dnf install ncurses-devel
# macOS
brew install ncurses./build.sh # Interactive build scriptcd c-implementation
make clean && make
./your-editor test.txtcd rust-implementation
cargo build --release
cargo test # Run unit tests
./target/release/text-editor test.txt./create-release.sh # Creates distributable packagesBoth implementations now support vim-like commands:
- Arrow keys: Move cursor
- Backspace: Delete character before cursor
- Delete: Delete character at cursor
- Tab: Insert spaces
- Enter: New line
- Escape: Switch to command mode
- Home/End: Line navigation
- :: Start vim command input
- i: Switch to edit mode
- q: Quit (prompts to save if modified)
- s: Save file
- u/r: Undo/Redo
- v: Start/end selection
- x: Cut selection
- p: Paste
- h: Show help
- :: Start vim command input
- :e : Edit/open file
- :o : Open file (same as :e)
- :w: Write/save current file
- :w : Save as different filename
- :wq: Write and quit
- :q: Quit
- :new: Create new buffer (Rust only)
- :ls: List all buffers (Rust only)
- :b : Switch to buffer number (Rust only)
- :bd: Delete current buffer (Rust only)
- For C Development: Start with
c-implementation/README.md - For Rust Development: See
rust-implementation/README.md - For Comparison Study: Build and test both versions side by side
./install.sh- Complete installation with dependencies./build.sh- Interactive build process./create-release.sh- Create distributable packages./verify_implementations.sh- Verify project structure
After installation, the editors are available as:
teditor- Rust implementation (primary command)teditor-c- C implementation
- Linux: Full support (tested on Ubuntu/Debian)
- macOS: Supported with Homebrew
- Windows: Available via WSL or native build (see releases)
The create-release.sh script generates:
- Source distribution (
text-editor-1.0.0-source.tar.gz) - Binary distribution (
text-editor-1.0.0-linux-x86_64.tar.gz) - Windows build instructions
- SHA256 checksums for verification
This project is designed for educational purposes. When contributing:
- Maintain the clear separation between C and Rust implementations
- Ensure both versions maintain feature parity
- Include tests for new Rust features
- Update documentation for architectural changes
This project evolved from a monolithic C implementation to demonstrate:
- Modularization: Breaking down a large C file into focused modules
- Modern Migration: Translating C concepts to Rust with safety improvements
- Architecture Evolution: From procedural to trait-based design
- Safety Progression: From manual memory management to compiler-guaranteed safety