Back to Projects
TUIX v0.1Alpha

Last Updated: 2026-05-20

RenderEngine

The RenderEngine class handles all terminal output. Accessible via engine.render, it draws components using Unicode box-drawing characters and ANSI color codes.

draw()

The main entry point for rendering. Clears the terminal, computes all layouts via LayoutEngine._compute_all(), then renders each component. Currently supports exactly one component — raises ValueError for zero components and NotImplementedError for multiple components.

engine.render.draw()
Single Component LimitMulti-modal layout system is still in development. Only one component can be rendered at a time. Only the 'choice' type is fully implemented for rendering.

Box Drawing

Components are drawn inside Unicode box-drawing borders. The characters used are: ┏ (top-left), ┓ (top-right), ┗ (bottom-left), ┛ (bottom-right), ━ (horizontal), ┃ (vertical). The box width is layout.x characters and margins are applied using spaces.

_wrap_and_center(text, max_width)

Internal method that wraps long text to fit within max_width and centers the text block horizontally. Handles explicit newlines in the input. Returns a list of padded strings, each exactly max_width characters wide.

_draw_buttons(*, obj, choices, max_width, max_height)

Renders the interactive button area of a choice component. Buttons are centered horizontally within the box. Multiple buttons in the same row are separated by 4 spaces. The currently selected button (tracked by selected_row and selected_index) is highlighted using selected_background and selected_text colors from the active style.

Long button names are automatically split when they exceed max_width - 4 characters, using visual_width() for accurate measurement of Unicode text.

_draw_choice(obj, text)

Renders a complete choice component: label text area at the top, button area in the middle, and bottom border. The available height for buttons is calculated as layout.y - (label lines) - 5 to account for padding and borders. After rendering, it calls engine.input.listen() to start the input loop.

_refresh(*, selected_row, selected_index)

Triggers a full redraw with updated selection state. Clears the screen and calls draw() again. Called by both RenderEngine._handle_selection_change() and InputHandler when navigation keys are pressed.

Selection Highlighting

The selected button is rendered with background_color() and text_color() ANSI escape codes. Colors are resolved from custom_styles first, falling back to the active preset. The escape code \x1b[0m resets formatting after the highlighted segment.

Current Limitations

  • Only single choice component rendering is fully implemented
  • progress_bar and text_input types have no render methods yet
  • Multi-modal layout system raises NotImplementedError
  • Full screen redraw on every interaction (no differential updates)
FuturePlanned: full multi-component rendering for all types, partial screen updates, and collision-aware layout.