# ============================================================ # File: /home/stu/Projects/Local REPO/telefact/src/core/telefact_frame.py # Description: # Telefact Frame (model) # Defines a 40×24 grid and logical regions for Teletext layout. # Each cell now supports both foreground and background colours. # This file contains no rendering logic — pure data model. # ============================================================ class TelefactFrame: def __init__(self, cols: int = 40, rows: int = 24): self.cols = cols self.rows = rows # Define Teletext-like regions self.header_rows = 1 self.footer_rows = 1 self.body_rows = self.rows - (self.header_rows + self.footer_rows) # grid[row][col] -> (char, fg_color, bg_color) self.grid = [ [(" ", "white", "black") for _ in range(self.cols)] for _ in range(self.rows) ] # -------------------------------------------------------- # Basic cell operations # -------------------------------------------------------- def set_cell( self, col: int, row: int, char: str, fg_color: str = "white", bg_color: str = "black", ): """Sets a character and both colours in a given grid cell.""" if 0 <= col < self.cols and 0 <= row < self.rows and char: self.grid[row][col] = (char[0], fg_color, bg_color) def get_cell(self, col: int, row: int): """Returns (char, fg, bg) for the given grid position.""" if 0 <= col < self.cols and 0 <= row < self.rows: return self.grid[row][col] return (" ", "white", "black") def clear(self, char: str = " ", fg_color: str = "white", bg_color: str = "black"): """Clears the entire frame to a given colour and character.""" for r in range(self.rows): for c in range(self.cols): self.grid[r][c] = (char, fg_color, bg_color) # -------------------------------------------------------- # Region helpers # -------------------------------------------------------- def header_region(self): """Row indices for header region (top row).""" return range(0, self.header_rows) def body_region(self): """Row indices for main content area.""" return range(self.header_rows, self.header_rows + self.body_rows) def footer_region(self): """Row indices for footer region (bottom row).""" return range(self.rows - self.footer_rows, self.rows)