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 identifierclasses (
strorlistofstr, optional) – CSS class names for stylingcontent (
str) – Content to display (default: “”)content_type (
strorContentType) – 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)
- Variables:
content (
str) – Content to displaycontent_type (
ContentType) – Content type enumeration valuelanguage (
str) – Programming language for code highlightingtheme (
str) – Syntax highlighting themeshow_line_numbers (
bool) – Whether line numbers are shown (code only)line_number_start (
int) – Starting line number (code only)width (
int) – Display widthheight (
int) – Display heightshow_scrollbar (
bool) – Whether scrollbar is visibleborder_style (
str) – Border stylescroll_manager (
ScrollManager) – Manages scrolling of contentrendered_lines (
listofstr) – Cached rendered content lines (for ANSI-based content types)rendered_cells (
listoflistofCell) – 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 identifierclasses (
strorlistofstrorsetofstr, optional) – CSS class names for stylingtab_index (
int, optional) – Tab order for focus navigationcontent (str)
content_type (str | ContentType)
language (str)
theme (str)
show_line_numbers (bool)
line_number_start (int)
show_scrollbar (bool)
border_style (str)
title (str | None)
- 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.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_tabWhether this element wants the Tab key instead of focus movement.
Get the current content.
Get the current content type.
parent_frameGet the parent Frame if this element is inside a scrollable frame.
Get the current scroll position.
scroll_state_keyGet the state key for vertical scroll position.
scroll_state_key_xGet the state key for horizontal scroll position.
Whether this content view supports dynamic sizing.
- property content_type: ContentType
Get the current content type.
- Returns:
Current content type enumeration value
- Return type:
- property supports_dynamic_sizing: bool
Whether this content view supports dynamic sizing.
- Returns:
True if configured with fill sizing, False otherwise
- Return type:
- 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 contentcontent_type (
strorContentType, 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:
- handle_key(key)[source]
Handle keyboard input for scrolling.
- Parameters:
key (
Key) – Key press to handle- Returns:
True if key was handled
- Return type:
- 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:
- 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