Skip to content

textual_enhanced.widgets

New or enhanced widgets.

EnhancedOptionList

Bases: OptionList

The Textual OptionList with more features.

Key changes are:

preserved_highlight property

preserved_highlight

Provides a context that preserves the highlight location.

The rule for how this works is:

  • If the highlighted option has an ID, an attempt will be made to get back to that option;
  • Failing the above an attempt will be made to return to the same location in the list.
  • If neither approach can be taken, and if there OptionList has any content, the first option will be highlighted.

The benefit of this is that the content of an OptionList can be cleared and built up again and, especially if your options have IDs, the user will be no wiser that such drastic measures were taken.

Example
with self.query_one(EnhancedOptionList).preserved_highlight:
    ...do things that modify the `OptionList`

get_content_width

get_content_width(container, viewport)

Workaround for textual#5489.

Note

textual#5489 has been fixed in later versions of Textual, but textual >=2.0 still has some problems so I'm holding off using it for now.

TextViewer

TextViewer(
    text="",
    *,
    name=None,
    id=None,
    classes=None,
    disabled=False,
)

Bases: TextArea

A widget for viewing text.

Parameters:

Name Type Description Default

text

str

The text to view.

''

name

str | None

The name of the TextViewer.

None

id

str | None

The ID of the TextViewer in the DOM.

None

classes

str | None

The CSS classes of the TextViewer.

None

disabled

bool

Whether the TextViewer is disabled or not.

False

action_copy

action_copy()

Action for copying text to the clipboard.

action_cursor_line_end

action_cursor_line_end(select=False)

Add a slightly smarter use of going 'end'.

The rule with this version of going to the end is that if the cursor isn't at the end of the line, then the normal TextArea rules apply, otherwise if the cursor is at the end of the line the cursor will go to the end of the document.

action_cursor_line_start

action_cursor_line_start(select=False)

Add a slightly smarter use of going 'home'.

The rule with this version of going home is that if the cursor isn't at the start of the line, then the normal TextArea rules apply, otherwise if the cursor is at the start of the line the cursor will go to the start of the document.