1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Rendering module for terminal-based output.
//!
//! This module provides the core rendering components for the `teng` library,
//! enabling you to display graphics and text in a terminal environment.
//!
//! **Sub-modules:**
//!
//! * [`color`]: Defines the [`Color`] enum for specifying colors.
//! * [`display`]: Defines the [`Display`] struct, a 2D pixel buffer.
//! * [`pixel`]: Defines the [`Pixel`] struct, the basic unit of rendering.
//! * [`render`]: Provides the [`Render`] trait for objects that can be rendered.
//! * [`renderer`]: Defines the [`Renderer`] trait and implementations for rendering to the terminal.
//!
//! **Key Concepts:**
//!
//! * **Pixels:** The fundamental unit of rendering, represented by the [`Pixel`] struct. Pixels define a character and its foreground and background colors.
//! * **Display Buffer:** The [`Display`] struct is a 2D grid of pixels that acts as an in-memory representation of the terminal display.
//! * **Renderer:** The [`Renderer`] trait defines the interface for rendering operations. [`DisplayRenderer`] is a concrete implementation that renders to the terminal using `crossterm`.
//! * **Renderable Objects:** Anything that implements the [`Render`] trait can be drawn to the display using a `Renderer`. This includes strings, characters, pixels, and sprites.
//!
//! **Rendering Process (Simplified):**
//!
//! 1. Create a `DisplayRenderer` (which manages the terminal output).
//! 2. Get a mutable reference to the `Renderer` within your `Component::render()` method.
//! 3. Use methods like `Renderer::render_pixel()` and `Render::render()` to draw pixels and renderable objects to the `Renderer`.
//! 4. The `Renderer` updates its internal `Display` buffer.
//! 5. Call `Renderer::flush()` to write the contents of the `Display` buffer to the terminal, efficiently updating only the changed pixels.
//!
//! [`Color`]: crate::rendering::color::Color
//! [`Display`]: crate::rendering::display::Display
//! [`Pixel`]: crate::rendering::pixel::Pixel
//! [`Render`]: crate::rendering::render::Render
//! [`Renderer`]: crate::rendering::renderer::Renderer
//! [`DisplayRenderer`]: crate::rendering::renderer::DisplayRenderer