wijjit.elements.display.contentview.ContentView

class wijjit.elements.display.contentview.ContentView(id=None, classes=None, content='', content_type='plain', language='python', theme='monokai', show_line_numbers=False, line_number_start=1, width=60, height=20, show_scrollbar=True, border_style='single', title=None, tab_index=None, bind=True)[source]

Unified content display element supporting multiple content types.

This element renders content in various formats with support for scrolling, borders, and keyboard/mouse interaction. It provides a single component that can display plain text, ANSI-formatted text, HTML, Markdown, Rich markup, or syntax-highlighted code.

Parameters:
  • id (str, optional) – Element identifier

  • classes (str or list of str, optional) – CSS class names for styling

  • content (str) – Content to display (default: “”)

  • content_type (str or ContentType) – Type of content: “plain”, “text”, “ansi”, “html”, “markdown”, “rich”, or “code” (default: “plain”)

  • language (str) – Programming language for code syntax highlighting (default: “python”)

  • theme (str) – Syntax highlighting theme (default: “monokai”)

  • show_line_numbers (bool) – Show line numbers for code (default: False)

  • line_number_start (int) – Starting line number (default: 1)

  • width (int) – Display width in columns (default: 60)

  • height (int) – Display height in rows (default: 20)

  • show_scrollbar (bool) – Whether to show vertical scrollbar (default: True)

  • border_style (str) – Border style: “single”, “double”, “rounded”, or “none” (default: “single”)

  • title (str, optional) – Title to display in top border (default: None)

  • tab_index (int | None)

  • bind (bool | str)

Variables:
  • content (str) – Content to display

  • content_type (ContentType) – Content type enumeration value

  • language (str) – Programming language for code highlighting

  • theme (str) – Syntax highlighting theme

  • show_line_numbers (bool) – Whether line numbers are shown (code only)

  • line_number_start (int) – Starting line number (code only)

  • width (int) – Display width

  • height (int) – Display height

  • show_scrollbar (bool) – Whether scrollbar is visible

  • border_style (str) – Border style

  • title (str or None) – Border title

  • scroll_manager (ScrollManager) – Manages scrolling of content

  • rendered_lines (list of str) – Cached rendered content lines (for ANSI-based content types)

  • rendered_cells (list of list of Cell) – Cached rendered cells (for cell-based content types like HTML)

__init__(id=None, classes=None, content='', content_type='plain', language='python', theme='monokai', show_line_numbers=False, line_number_start=1, width=60, height=20, show_scrollbar=True, border_style='single', title=None, tab_index=None, bind=True)[source]

Initialize scrollable element.

Parameters:
  • id (str, optional) – Element identifier

  • classes (str or list of str or set of str, optional) – CSS class names for styling

  • tab_index (int, optional) – Tab order for focus navigation

  • content (str)

  • content_type (str | ContentType)

  • language (str)

  • theme (str)

  • show_line_numbers (bool)

  • line_number_start (int)

  • width (int | str)

  • height (int | str)

  • show_scrollbar (bool)

  • border_style (str)

  • title (str | None)

  • bind (bool | str)

Return type:

None

Methods

__init__([id, classes, content, ...])

Initialize scrollable element.

add_class(class_name)

Add a CSS class to this element.

apply_props(props)

Apply props from a VNode, skipping ephemeral props.

can_scroll(direction)

Check if the element can scroll in the given direction.

get_ephemeral_state()

Get ephemeral state that should survive reconciliation.

get_hardware_cursor_position()

Absolute screen cell where the hardware terminal cursor should park.

get_height_for_width(width)

Return the height this element needs when laid out at width.

get_intrinsic_size()

Return preferred size for auto sizing.

handle_key(key)

Handle keyboard input for scrolling.

handle_mouse(event)

Handle mouse input for scrolling.

has_class(class_name)

Check if element has a CSS class.

on_blur()

Called when element loses focus.

on_focus()

Called when element gains focus.

on_hover_enter()

Called when mouse enters element.

on_hover_exit()

Called when mouse exits element.

on_mount()

Called when element is first added to the element tree.

on_unmount()

Called when element is removed from the element tree.

on_update(changed_props)

Called when element props are updated during reconciliation.

remove_class(class_name)

Remove a CSS class from this element.

render_signature()

Hashable/comparable capture of everything render_to() reads.

render_to(ctx)

Render content view using cell-based rendering.

restore_ephemeral_state(state)

Restore ephemeral state after reconciliation.

restore_scroll_position(position)

Restore scroll position from saved state.

set_bounds(bounds)

Set bounds and resize element to fit.

set_content(content[, content_type])

Update content and optionally content type.

toggle_class(class_name)

Toggle a CSS class on this element.

Attributes

captures_tab

Whether this element wants the Tab key instead of focus movement.

content

Get the current content.

content_type

Get the current content type.

parent_frame

Get the parent Frame if this element is inside a scrollable frame.

scroll_position

Get the current scroll position.

scroll_state_key

Get the state key for vertical scroll position.

scroll_state_key_x

Get the state key for horizontal scroll position.

supports_dynamic_sizing

Whether this content view supports dynamic sizing.

property content_type: ContentType

Get the current content type.

Returns:

Current content type enumeration value

Return type:

ContentType

property content: str

Get the current content.

Returns:

Current content string

Return type:

str

property supports_dynamic_sizing: bool

Whether this content view supports dynamic sizing.

Returns:

True if configured with fill sizing, False otherwise

Return type:

bool

set_bounds(bounds)[source]

Set bounds and resize element to fit.

Parameters:

bounds (Bounds) – New bounds for the element

Return type:

None

set_content(content, content_type=None)[source]

Update content and optionally content type.

Parameters:
  • content (str) – New content

  • content_type (str or ContentType, optional) – New content type (if None, keeps current type)

Return type:

None

restore_scroll_position(position)[source]

Restore scroll position from saved state.

Parameters:

position (int) – Scroll position to restore

Return type:

None

property scroll_position: int

Get the current scroll position.

Returns:

Current scroll offset (0-based)

Return type:

int

can_scroll(direction)[source]

Check if the element can scroll in the given direction.

Parameters:

direction (int) – Scroll direction: negative for up, positive for down

Returns:

True if scrolling in the given direction is possible

Return type:

bool

handle_key(key)[source]

Handle keyboard input for scrolling.

Parameters:

key (Key) – Key press to handle

Returns:

True if key was handled

Return type:

bool

async handle_mouse(event)[source]

Handle mouse input for scrolling.

Parameters:

event (MouseEvent) – Mouse event to handle

Returns:

True if event was handled

Return type:

bool

render_to(ctx)[source]

Render content view using cell-based rendering.

Parameters:

ctx (PaintContext) – Paint context with buffer, style resolver, and bounds

Return type:

None

Notes

This method implements cell-based rendering for content views, supporting all content types with their respective formatting.

Theme styles:

This element uses the following theme style classes: - contentview: Base style (for background/fallback) - contentview:focus: When content view has focus - contentview.border: For border characters - contentview.border:focus: For border when focused

get_intrinsic_size()[source]

Return preferred size for auto sizing.

Returns:

Preferred (width, height)

Return type:

tuple of (int, int)