Skip to content

latent.chat.widgets

Custom Textual widgets for the chat REPL.

Classes

RTLInput

RTLInput()

Input widget with full Unicode BiDi support for mixed LTR+RTL text.

When the value contains RTL characters (Hebrew, Arabic, etc.): - render_line displays the text in correct visual order using the Unicode BiDi algorithm via python-bidi. - The cursor is mapped from logical position to visual position using the character reordering table produced by the BiDi algorithm. - Arrow key navigation moves in visual order, not logical order. - Word-jump navigation (Ctrl+←/→) operates on word boundaries in visual order so it stays consistent with visual cursor movement.

Falls back to the default Textual Input rendering when the value contains no RTL characters or when python-bidi is not installed.

Backspace, Delete, Home, and End need no override: - Backspace removes cursor_pos-1 (the last-typed character) — correct. - Delete removes cursor_pos — correct. - Home → logical pos 0. For RTL-dominant text this is the visual right (beginning of reading order); for LTR-dominant it is the visual left. Both are the correct "start" positions. - End → logical pos len(value) — symmetric to Home.

SelectableRichLog

SelectableRichLog(kwargs = {})

RichLog extended with mouse click-drag text selection and clipboard copy.

  • Click and drag to highlight text with reverse-video style.
  • On mouse release, the selected plain text is copied to the clipboard.
  • Appending new content while a drag is in progress clears the selection to avoid stale coordinate references.
  • Ctrl+C is NOT intercepted here — it retains its stream-cancel behaviour.

SessionPicker

SessionPicker(sessions: list[Any], kwargs: Any = {})

Interactive session picker with arrow navigation and Enter to load.

SessionPicker.Selected

Selected(session_id: str, path: str)

Fired when a session is selected.

ToolCallCollapsible

ToolCallCollapsible(tool_name: str, arguments: dict[str, Any], tool_call_id: str)

Collapsible panel for a single tool call + result.

Shows a one-line summary when collapsed (tool name + truncated args), expands to show full JSON arguments and result. Click the title or press Enter to toggle.

Methods

RTLInput.action_cursor_left

action_cursor_left(select: bool = False) -> None

RTLInput.action_cursor_left_word

action_cursor_left_word(select: bool = False) -> None

RTLInput.action_cursor_right

action_cursor_right(select: bool = False) -> None

RTLInput.action_cursor_right_word

action_cursor_right_word(select: bool = False) -> None

RTLInput.render_line

render_line(y: int) -> Strip

SelectableRichLog.on_mouse_down

on_mouse_down(event: MouseDown) -> None

SelectableRichLog.on_mouse_move

on_mouse_move(event: MouseMove) -> None

SelectableRichLog.on_mouse_up

on_mouse_up(event: MouseUp) -> None

SelectableRichLog.render_line

render_line(y: int) -> Strip

SelectableRichLog.write

write(content, kwargs = {})

SessionPicker.on_option_list_option_selected

on_option_list_option_selected(event: OptionList.OptionSelected) -> None

ToolCallCollapsible.set_result

set_result(output: Any, error: str | None) -> None

Append tool result to the collapsible body.