wijjit.terminal.cell.CellPool
- class wijjit.terminal.cell.CellPool[source]
Pool of pre-allocated common Cell objects for performance.
This class provides a cache of commonly-used cells to reduce allocations during rendering. Cells like spaces, border characters, etc. are created once and reused across frames.
Notes
This is a performance optimization that reduces GC pressure and allocation overhead in hot rendering paths. The pool is lazily initialized and uses a dictionary for O(1) lookups.
Examples
Get a space cell:
>>> pool = CellPool() >>> space = pool.get_space() >>> space.char ' '
Get a styled border cell:
>>> border = pool.get_border_char('─', fg_color=(100, 100, 100)) >>> border.char '─'
Methods
__init__()Initialize the cell pool with common cells.
clear()Clear the cache (for testing or memory management).
get_char(char[, fg_color, bg_color, bold, ...])Get a cell with a specific character and optional styling.
get_space([fg_color, bg_color, bold, ...])Get a space cell with optional styling.
- get_space(fg_color=None, bg_color=None, bold=False, italic=False, underline=False, reverse=False, dim=False)[source]
Get a space cell with optional styling.
- Parameters:
fg_color (
tupleof(int,int,int)orNone, optional) – Foreground colorbg_color (
tupleof(int,int,int)orNone, optional) – Background colorbold (
bool, optional) – Bold attributeitalic (
bool, optional) – Italic attributeunderline (
bool, optional) – Underline attributereverse (
bool, optional) – Reverse attributedim (
bool, optional) – Dim attribute
- Returns:
Cached or new space cell
- Return type:
- get_char(char, fg_color=None, bg_color=None, bold=False, italic=False, underline=False, reverse=False, dim=False)[source]
Get a cell with a specific character and optional styling.
This method pools frequently-used characters like border chars.
- Parameters:
char (
str) – Character to displayfg_color (
tupleof(int,int,int)orNone, optional) – Foreground colorbg_color (
tupleof(int,int,int)orNone, optional) – Background colorbold (
bool, optional) – Bold attributeitalic (
bool, optional) – Italic attributeunderline (
bool, optional) – Underline attributereverse (
bool, optional) – Reverse attributedim (
bool, optional) – Dim attribute
- Returns:
Cached or new cell
- Return type:
Notes
This is most effective for border characters and other frequently repeated glyphs. For unique characters, creating cells directly may be more efficient.