How skardyy/ttyimg works
Main Components
• Command Line Interface (CLI) — represented by main.go. This is the entry point where user parameters (image path, resizing options, protocol selection etc.) are processed.
• Image Processing Module — represented by images_manipulation.go and images_query.go. This module handles loading images, scaling, and applying encoding logic.
• OS or Platform Abstraction Layer — represented by platform-specific files (attrs.go, attrs_unix.go, attrs_windows.go). This layer abstracts terminal size querying (cells and pixels) using escape sequences, system calls, or win-specific APIs.
• Logging Module — represented by logger.go, which handles logging events or errors during processing.
Relationships and Interactions
• The CLI (main.go) receives user inputs and invokes the image processing module.
• The image processing module handles both the conversion/resizing of images and the selection of the appropriate protocol (kitty, iterm, or sixel).
• It queries the terminal environment via the OS abstraction module to determine screen dimensions. In this, the platform-specific files (attrs_unix.go/attrs_windows.go) come into play.
• When the input file is a document type (e.g., DOCX, PDF, etc.), the tool will use LibreOffice in a sub-process to convert documents to an image or a supported intermediary format.
• Throughout the process, the logger module records progress, errors, or important events.
• Final output from the processing module is piped back to the CLI to render an image based on the user’s terminal protocol.
Architectural Patterns and Design Principles
• Separation of Concerns: The project divides responsibilities among different modules (CLI, image processing, logging, platform abstraction, external dependency handling).
• Modularity: Each logical component (e.g., image handling vs. OS interactions) is implemented in its own Go file which aids in maintainability.
• Extensibility: The design is open for future enhancements (for example, integrating alternative backends for document conversion or adding more terminal protocols).
Technologies and Frameworks
• Go language (as indicated by go.mod and the .go files).
• External tool: LibreOffice (used when processing certain document image types).
• Terminal protocols: iTerm2, Kitty, and Sixel.