Skip to content

textual_enhanced.tools

Provides assorted tools that help with Textual things.

History

History(history=None, max_length=500)

Bases: Generic[HistoryItem]

A class for handling and tracking history.

Parameters:

Name Type Description Default

history

Sequence[HistoryItem] | None

Set to the given history.

None

max_length

int

Optional maximum length for the history.

500

can_go_backward property

can_go_backward

Can history go backward?

can_go_forward property

can_go_forward

Can history go forward?

current_item property

current_item

The current item in the history.

If there is no current item in the history the value is None.

current_location property

current_location

The current integer location in the history.

If there is no valid location the value is None.

__delitem__

__delitem__(index)

Delete an item in history.

__iter__

__iter__()

Support iterating through the history.

__len__

__len__()

The length of the history.

add

add(item)

Add an item to the history.

Parameters:

Name Type Description Default

item

HistoryItem

The item to add.

required

Returns:

Type Description
Self

Self.

backward

backward()

Go backward through the history.

Returns:

Type Description
bool

True if we moved through history, False if not.

forward

forward()

Go forward through the history.

Returns:

Type Description
bool

True if we moved through history, False if not.

goto

goto(location)

Jump to a specific location within history.

goto_end

goto_end()

Go to the end of the history.

add_key

add_key(label, key, context=None)

Add a key name to a label.

Parameters:

Name Type Description Default

label

str

The label to add the key to.

required

key

str

The display name of the key to add.

required

context

App[Any] | Widget | None

The widget, screen or application.

None

Returns:

Type Description
str

The label with a display of the key added.

Notes

By default the key label will use the current theme's accent colour, if that can't be derived from the context them dim will be used.