How ninostephen/durdraw works
Project type and purpose
• Durdraw is a terminal-based ASCII/Unicode/ANSI art editor and animation tool written in Python. It provides:
• An interactive TUI editor (uses curses)
• Command-line playback/export tools (durdraw, durfetch, durview)
• A plugin subsystem for frame-based animations and charset conversions
• Configuration via INI files and built-in themes/charsets
File structure
• Top-level executables and scripts:
• durdraw (entry point CLI script)
• durfetch (CLI wrapper for Neofetch integration)
• durview (animation viewing CLI)
• start-durdraw, shebang convenience script
• Core package directory: durdraw/
• Submodules by feature:
– durdraw_ansiparse.py, durdraw_file.py (file I/O and parsing)
– durdraw_appstate.py (application state management)
– durdraw_gui_manager*.py, durdraw_ui_*.py (UI layer)
– durdraw_undo.py (undo/redo subsystem)
– durdraw_plugins/ (animation and charset plugins)
– durdraw_charsets.py, charsets/ (character set definitions)
– durdraw_themes/ (theme definitions)
• Config and metadata:
• durdraw.ini, pyproject.toml, Dockerfile, install scripts
• Tests: test/durdraw/
README for additional insights
• Architecture is not explicitly diagrammed but key components and CLI commands are described
• External dependencies: Python 3, curses, optional ansilove (PNG/GIF export), neofetch (durfetch)
a. Main components:
1. CLI Frontend Layer
• Entry point scripts (durdraw, durfetch, durview)
• Argument parser and command dispatch
2. Core Engine
• Application State Manager (durdraw_appstate.py)
• Options & Config Loader (durdraw_options.py)
• Undo/Redo Manager (durdraw_undo.py)
3. File & Format Layer
• Parser/Serializer (durdraw_ansiparse.py, durfile.py)
• .dur JSON format (see durformat.md)
• ANSI/ASCII import/export
4. UI Layer (Terminal)
• Low-level curses interface (durdraw_color_curses.py)
• GUI Manager (durdraw_gui_manager.py, durdraw_gui_manager_curses.py)
• UI Widgets (durdraw_ui_widgets.py, durdraw_ui_widgets_curses.py)
• Input handling (keyboard, mouse)
5. Domain Services
• Character Sets & Themes (durdraw_charsets.py, charsets/, themes/)
• Animation Plugins (plugins/*.py)
• Durfetch integration (durfetch.py)
6. External Systems
• ncurses library
• ansilove (optional)
• neofetch (optional for durfetch)
• File system (read/write .dur, config, examples)
b. Relationships and interactions:
• CLI Frontend invokes Core Engine with parsed options
• Core Engine loads Config + Themes/Charsets
• Core Engine orchestrates File & Format Layer to load/save art
• Core Engine pushes drawing commands to UI Layer
• UI Layer renders frames and captures user input, then updates App State
• Plugins hook into the Core Engine for animation operations or charset conversion
• Durfetch wraps Core Engine + Plugins + external neofetch
c. Architectural patterns and design principles:
• Modular separation: CLI vs Core vs UI vs File/Format vs Domain Services
• Plugin architecture for extendibility (animation, charset conversion)
• MVC-like pattern:
• Model = AppState + Document (durdraw_appstate.py + file modules)
• View = UI Layer (curses GUI Manager + Widgets)
• Controller = Core Engine + Command dispatch + Input handlers
• Configuration-driven (INI files for themes, charsets, main options)
d. Key technologies & libraries:
• Python 3
• curses (ncurses/pdcurses) for TUI
• ConfigParser for INI files
• JSON for .dur format
• Optional: ansilove, neofetch