This repository has been archived on 2025-12-01. You can view files and clone it, but cannot push or open issues or pull requests.
Telefact_archive/src/core/telefact_frame.py

68 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================================
# 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)