A powerful, keyboard-driven TUI application for creating and editing TOML configuration files with template support and real-time validation.
# Install dependencies (Ubuntu/Debian)
sudo apt-get install build-essential libncurses5-dev
# Build
make
# Run
./bin/toml-editorNew to the editor? Start with QUICKSTART.md for a 5-minute tutorial.
- β¨ Full-featured TUI - Built with ncurses for a responsive terminal interface
- π Create & Edit - Create new TOML files or edit existing ones
- π¨ Syntax Highlighting - Color-coded display for sections, keys, values, and comments
- π Template Support - Load pre-defined templates from the
templates/directory - β Real-time Validation - Uses toml-c library to validate TOML syntax before saving
- π Preview Changes - Review modifications before committing to disk
- πΎ Safe Saving - Warns before overwriting existing files with save-as option
- β¨οΈ Keyboard Navigation - Fully navigable with arrow keys and shortcuts
- π Line Management - Insert, edit, and delete lines with ease
- π¬ Comment Preservation - Maintains all comments when editing files
- GCC compiler (C11 or later)
- ncurses library
- make
Ubuntu/Debian:
sudo apt-get install build-essential libncurses5-dev libncursesw5-devFedora/RHEL:
sudo dnf install gcc make ncurses-develArch Linux:
sudo pacman -S base-devel ncursesmacOS:
brew install ncurses- Clone or download this repository
- Navigate to the project directory
- Build the project:
makeThe executable will be created at bin/toml-editor.
make all- Build the project (default)make clean- Remove build artifactsmake debug- Build with debug symbolsmake run- Build and run the programmake install- Install to /usr/local/bin (requires sudo)make uninstall- Remove from /usr/local/bin (requires sudo)
./bin/toml-editorOr if installed:
toml-editor- Create new TOML file from template - Select from available templates in
templates/ - Create new TOML file (blank) - Start with an empty file
- Open existing TOML file - Load and edit an existing TOML file
- ESC - Exit the application
| Key | Action |
|---|---|
β / β |
Navigate up/down through lines |
E |
Edit the current line |
I |
Insert a new line after the current line |
D |
Delete the current line |
P |
Preview changes before saving |
S |
Save the file |
ESC |
Return to main menu (warns if unsaved changes) |
- Type the file path/name
- Press
ENTERto confirm - Press
ESCto cancel
When saving a file that already exists:
S- Overwrite the existing fileN- Save as a new filenameESC- Cancel and return to editing
Templates are TOML files stored in the templates/ directory. The editor will automatically detect and list all .toml files in this directory.
- Create a
.tomlfile in thetemplates/directory - Add your template content with placeholders or default values
- The template will appear in the template selection menu
- basic.toml - Simple configuration with owner and database sections
- config.toml - Application configuration with server, logging, and plugins
The editor uses the toml-c library for parsing and validation. Before saving, the editor validates that:
- All TOML syntax is correct
- Sections are properly formatted
- Key-value pairs are valid
- Arrays and tables are correctly structured
If validation fails, the editor will display an error message and prevent saving until the issues are resolved.
The editor recognizes and color-codes different line types:
- Comments - Lines starting with
#(Magenta) - Sections - Lines like
[section](Cyan, Bold) - Array Tables - Lines like
[[array]](Cyan, Bold) - Key-Value Pairs - Lines with
key = value(Green) - Empty Lines - Blank lines (No color)
- Invalid Lines - Syntax errors (Red)
mag-cfg-c/
βββ assets/ # Documentation and specifications
βββ bin/ # Compiled executable
βββ build/ # Object files
βββ include/ # Header files (toml.h, toml.c)
βββ src/ # Source code
β βββ main.c # Main entry point
β βββ init.c # Initialization and utilities
β βββ file_ops.c # File operations and TOML validation
β βββ ui_render.c # UI rendering functions
β βββ input_handler.c # Input handling
β βββ toml_editor.h # Header with data structures
βββ templates/ # TOML templates
βββ Makefile # Build configuration
βββ README.md # This file
- EditorState - Main state container for the entire application
- EditorLine - Represents a single line with content, type, and modification status
- Template - Template metadata (name and path)
MODE_MENU- Main menuMODE_TEMPLATE_SELECT- Template selectionMODE_FILE_INPUT- File path inputMODE_EDIT- Main editing modeMODE_PREVIEW- Preview changesMODE_SAVE_CONFIRM- Save confirmation dialogMODE_SAVE_AS- Save as new filename
The editor uses toml-c in "header-only mode" by including both toml.h and toml.c. The library is used for:
- Parsing existing files - Load and validate TOML structure
- Validation before save - Ensure syntax correctness
- Error reporting - Provide detailed error messages
- Maximum 1000 lines per file
- Maximum 1024 characters per line
- Maximum 50 templates
- Lines longer than screen width are truncated in display (but preserved in file)
Error: ncurses.h not found
- Install ncurses development libraries (see Requirements section)
Error: toml.h not found
- Ensure
include/toml.handinclude/toml.cexist - Re-run the download commands from the build instructions
Terminal display issues
- Ensure your terminal supports colors
- Try resizing the terminal window
- Check that TERM environment variable is set correctly
File permission errors
- Ensure you have read/write permissions for the target directory
- Check that the
templates/directory exists and is readable
Contributions are welcome! Please ensure:
- Code follows the existing style
- All features are tested
- Documentation is updated
- Commit messages are clear
This project is provided as-is for educational and practical use.
- toml-c library by CK Tan - https://github.com/cktan/tomlc99
- ncurses library for terminal UI
Potential features for future versions:
- Search and replace functionality
- Undo/redo support
- Multi-line value editing
- Inline help for TOML syntax
- Configuration file for editor settings
- Export to JSON/YAML
- Syntax error highlighting with line numbers
- Mouse support
- Copy/paste between lines
- Bookmarks for quick navigation
For issues, questions, or suggestions, please refer to the project repository or documentation.