diff --git a/README.md b/README.md index ee9574b..8777d9a 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,43 @@ # Koa - A Modal Code Editor -A fully extensible and experimental modal code editor for the terminal. The Zig codebase provides a minimal bootstrap layer while Janet handles all editor logic, enabling maximum extensibility and live customization. +An experimental fully extensible modal code editor for the terminal. The Rust +codebase provides a minimal bootstrap layer while Janet handles all editor +logic, enabling maximum extensibility and live customization. **Key Features:** - **Janet-based Core**: Editor logic written in Janet for ultimate flexibility - **Live Reconfiguration**: Hot-swap key bindings, behaviors, and plugins -- **Zig Bootstrap**: Minimal, efficient native layer for TUI and system integration -- **Tree-sitter Integration**: Syntax highlighting via native bindings (WIP) -- **Unlimited Extensibility**: Complete editor customization without recompilation +- **Rust Bootstrap**: Minimal, efficient native layer for TUI and system + integration +- **Tree-sitter Integration**: Syntax highlighting, indentation and more via + native bindings +- **Unlimited Extensibility**: Complete editor customization without + recompilation ## Current Status -**Bootstrap Foundation** (Zig): -- [x] **Janet Integration**: jzignet library integrated for embedding Janet -- [x] **Janet-Zig Bridge System**: File system, TUI, and syntax bridges implemented -- [x] **Janet Event Loop Foundation**: Event loop infrastructure implemented in Janet -- [x] **Basic TUI Interface**: libvaxis integration for terminal UI -- [x] **File Operations**: Bridge functions for file I/O (placeholders until jzignet string support) -- [x] **Event Loop Handoff**: Control handed from Zig to Janet main loop - -**Editor Core** (Strategic Hybrid): -- [x] **Janet Editor State**: Core state management moved to Janet -- [x] **Modal System Framework**: Basic modal system structure in Janet -- [x] **Janet Event Handling**: Input processing framework in Janet -- [x] **Complete Event Loop**: Implement actual event processing -- [x] **Text Editing in Janet**: Port text operations to Janet -- [x] **High-Level UI Bridge**: Zig renders editor state from Janet +**Bootstrap Foundation**: +- [x] **Janet Integration**: janetrs library integrated for embedding Janet +- [x] **Basic TUI Interface**: ratatui integration for terminal UI +- [ ] **Janet-Rust Bridge System**: File system, TUI, and syntax bridges + (minimal implementation) +- [ ] **Janet Event Loop Foundation**: Event loop infrastructure in Janet (basic + key forwarding only) +- [ ] **File Operations**: Bridge functions for file I/O (not implemented) +- [ ] **Event Loop Handoff**: Control handed from Rust to Janet main loop + (partial) + +**Editor Core**: +- [ ] **Janet Editor State**: Core state management in Janet +- [ ] **Modal System Framework**: Basic modal system structure in Janet +- [ ] **Janet Event Handling**: Input processing framework in Janet +- [ ] **Complete Event Loop**: Actual event processing +- [ ] **Text Editing in Janet**: Text operations in Janet +- [ ] **High-Level UI Bridge**: Rust renders editor state from Janet ## Architecture -**Strategic Hybrid Design:** +**Rust-Janet Hybrid Design:** ``` ┌─────────────────────────────────────────────────────────────┐ │ Janet Layer (Editor Logic) │ @@ -42,60 +50,55 @@ A fully extensible and experimental modal code editor for the terminal. The Zig └─────────────────────────────────────────────────────────────┘ ↕ High-Level Bridge ┌─────────────────────────────────────────────────────────────┐ -│ Zig Layer (UI & System Core) │ +│ Rust Layer (UI & System Core) │ ├─────────────────────────────────────────────────────────────┤ │ • Complete UI rendering │ -│ • TUI operations & child window management │ +│ • TUI operations & terminal management │ │ • File I/O and system calls │ │ • Tree-sitter integration │ │ • Performance-critical operations │ └─────────────────────────────────────────────────────────────┘ ``` -**Current Structure** (strategic hybrid): +**Current Structure**: ``` . -├── src/ # Zig source code -│ ├── main.zig # Bootstrap: Janet init + hybrid event loop -│ ├── runtime.zig # Bootstrap: Janet runtime loader -│ ├── janet_env.zig # Bootstrap: Janet environment management -│ ├── syntax.zig # Tree-sitter bindings (legacy, superseded by bridges/syntax.zig) -│ └── bridges/ # Zig-Janet bridge modules -│ ├── vaxis.zig # High-level UI bridge -│ ├── fs.zig # File system operations -│ └── syntax.zig # Tree-sitter bindings (TBD) +├── src/ # Rust source code +│ ├── main.rs # Bootstrap: Janet init + event loop +│ ├── app.rs # Application state and main loop +│ ├── event.rs # Event handling system +│ ├── ui.rs # UI rendering +│ └── janet/ # Rust-Janet bridge modules +│ ├── mod.rs # Module definitions +│ ├── keymap.rs # Key handling bridge +│ └── state.rs # State management bridge └── runtime/ # Janet runtime source code - ├── core.janet # Core runtime entrypoint (init file) - ├── modal.janet # Modal system - ├── buffer.janet # Buffer management - ├── keymap.janet # Keybindings - ├── editor.janet # Editor state and management - ├── movement.janet # Movement logic - ├── selection.janet # Selection logic - ├── utils.janet # Utility functions - └── config.janet # Configuration system (TBD) + └── koa/ # Koa Janet modules + ├── koa.janet # Main entrypoint + ├── keymap.janet # Keybindings (minimal) + └── stubs.janet # Placeholder functions ``` ## Roadmap ### Phase 1: Strategic Hybrid Foundation -- [x] **Janet Integration & Bootstrap** - - [x] Integrate jzignet library for Janet embedding - - [x] Set up Janet environment initialization in Zig - - [x] Create minimal Zig bootstrap that hands control to Janet - - [x] Design Janet API for editor state management - -- [x] **High-Level UI Bridge** (Current Priority) - - [x] Create semantic rendering bridge functions - - [x] Maintain existing ui.zig performance and features - - [x] Bridge accepts editor state from Janet, renders in Zig - - [x] Replace primitive vaxis calls with high-level operations - -- [x] **Editor State Migration to Janet** - - [x] Port current editor state management to Janet - - [x] Implement modal system (Normal/Insert/Select/Command) in Janet - - [x] Create Janet text operations (insert, delete, cursor movement) - - [x] Implement Janet-based key binding system +- [ ] **Janet Integration & Bootstrap** + - [x] Integrate janetrs library for Janet embedding + - [x] Set up Janet environment initialization in Rust + - [ ] Create minimal Rust bootstrap that hands control to Janet + - [ ] Design Janet API for editor state management + +- [ ] **High-Level UI Bridge** (Current Priority) + - [ ] Create semantic rendering bridge functions + - [ ] Maintain ratatui performance and features + - [ ] Bridge accepts editor state from Janet, renders in Rust + - [ ] Replace primitive ratatui calls with high-level operations + +- [ ] **Editor State Migration to Janet** + - [ ] Port current editor state management to Janet + - [ ] Implement modal system (Normal/Insert/Select/Command) in Janet + - [ ] Create Janet text operations (insert, delete, cursor movement) + - [ ] Implement Janet-based key binding system ### Phase 2: Advanced Editor Operations (Janet-Driven) - [ ] **Dynamic Configuration System** @@ -124,11 +127,11 @@ A fully extensible and experimental modal code editor for the terminal. The Zig - [ ] Macro recording and playback ### Phase 3: Language Support & Syntax Highlighting -- [ ] **Tree-sitter Integration (via Zig bridge)** +- [ ] **Tree-sitter Integration (via Rust bridge)** - [ ] Integrate tree-sitter library - [ ] Create Janet API for syntax highlighting - [ ] Parse and highlight common languages: - - [ ] Zig, Rust, C/C++ + - [ ] Rust, Zig, C/C++ - [ ] JavaScript/TypeScript - [ ] Python, Go, Java - [ ] Janet, Lua, Lisp dialects @@ -175,11 +178,12 @@ A fully extensible and experimental modal code editor for the terminal. The Zig ## Architecture Philosophy -**Strategic Hybrid Approach**: This architecture balances flexibility with performance: +**Rust-Janet Hybrid Approach**: This architecture balances flexibility with +performance: -**Zig Layer (Performance Core)**: Handles operations where performance matters: -- Complete UI rendering using existing optimized ui.zig -- TUI operations with proper child window management +**Rust Layer (Performance Core)**: Handles operations where performance matters: +- Complete UI rendering using ratatui +- TUI operations with proper terminal management - File I/O and system calls - Tree-sitter integration for syntax highlighting - Memory-intensive operations @@ -193,33 +197,38 @@ A fully extensible and experimental modal code editor for the terminal. The Zig **High-Level Bridge**: Clean interface between layers: - Janet computes editor state and decisions -- Zig renders state efficiently using native vaxis features +- Rust renders state efficiently using native ratatui features - Minimal bridge calls with semantic operations - Clear separation of concerns -This approach maximizes both flexibility and performance, avoiding the overhead of primitive bridge operations while maintaining the extensibility benefits of Janet scripting (or so I hope!). +This approach maximizes both flexibility and performance, avoiding the overhead +of primitive bridge operations while maintaining the extensibility benefits of +Janet scripting. ## Building and Running ```bash -# Build the editor (add -Doptimize=ReleaseFast for production build) -zig build +# Build the editor (add --release for production build) +cargo build # Run with a file -./zig-out/bin/koa demo.zig +cargo run -- demo.rs # Run without arguments for empty buffer -./zig-out/bin/koa +cargo run ``` ## Testing ```bash -zig build test +cargo test ``` ## Key Bindings +**Note**: Most key bindings are not yet implemented. Current functionality is +limited to basic character input. + ### Normal Mode - `hjkl` or arrow keys - Movement (undo current selections) - `^` or `Home` - Beginning of line @@ -229,13 +238,13 @@ zig build test - `:` - Enter command mode - `w` - Move to next word - `b` - Move to previous word -- `PageUp` - Move to top (20 lines jump) -- `PageDown` - Move to bottom (20 lines jump) +- `PageUp` - Move to top +- `PageDown` - Move to bottom - `o` - Create line below and enter insert mode - `O` - Create line above and enter insert mode -- `x` - Select whole line or next line if the current one is already fully selected -- `d` - Delete character under cursor or the current selection -if one exists +- `x` - Select whole line or next line if the current one is already fully + selected +- `d` - Delete character under cursor or the current selection if one exists - `D` - Duplicate selected line - `Delete` - Delete character under cursor - `Backspace` - Delete character before cursor @@ -246,7 +255,7 @@ if one exists - `Backspace` - Delete character before cursor - `Delete` - Delete character under cursor - `Enter` - Insert newline -- `Tab` - Insert 4 spaces (hardcoded for now) +- `Tab` - Insert 4 spaces - `Home` - Beginning of line - `End` - End of line @@ -256,7 +265,8 @@ if one exists - `$` or `End` - End of line - `d` or `Delete` - Delete selection - `i` - Delete selection and enter insert mode -- `x` - Select whole line or next line if the current one is already fully selected +- `x` - Select whole line or next line if the current one is already fully + selected - `w` - Expand selection to next word - `b` - Shorten selection to previous word - `Escape`, `v` - Return to normal mode @@ -264,13 +274,13 @@ if one exists ### Command Mode - `Escape` - Return to normal mode - `w` - Save file -- `W` - Save file and quit (temporary until command mode gets better) - `q` - Quit editor (does not handle unsaved changes confirmation yet!) ## Contributing -This is a learning project exploring modal editor design with Zig. Contributions and suggestions are welcome! +This is a learning project exploring modal editor design with Rust and Janet. +Contributions and suggestions are welcome! ## License -MIT License - Feel free to use this code for learning and experimentation. +GPLv2 License - Feel free to use this code for learning and experimentation.