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
'─'
__init__()[source]

Initialize the cell pool with common cells.

Return type:

None

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 (tuple of (int, int, int) or None, optional) – Foreground color

  • bg_color (tuple of (int, int, int) or None, optional) – Background color

  • bold (bool, optional) – Bold attribute

  • italic (bool, optional) – Italic attribute

  • underline (bool, optional) – Underline attribute

  • reverse (bool, optional) – Reverse attribute

  • dim (bool, optional) – Dim attribute

Returns:

Cached or new space cell

Return type:

Cell

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 display

  • fg_color (tuple of (int, int, int) or None, optional) – Foreground color

  • bg_color (tuple of (int, int, int) or None, optional) – Background color

  • bold (bool, optional) – Bold attribute

  • italic (bool, optional) – Italic attribute

  • underline (bool, optional) – Underline attribute

  • reverse (bool, optional) – Reverse attribute

  • dim (bool, optional) – Dim attribute

Returns:

Cached or new cell

Return type:

Cell

Notes

This is most effective for border characters and other frequently repeated glyphs. For unique characters, creating cells directly may be more efficient.

clear()[source]

Clear the cache (for testing or memory management).

Notes

Preserves the common space cell. Useful for tests or if the cache grows too large in long-running applications.

Return type:

None