Skip to content

fix(tui): Preserve Rich Text styling in collapsible content for diff highlighting#661

Open
sjathin wants to merge 2 commits intoOpenHands:mainfrom
sjathin:open-hands-cli-308
Open

fix(tui): Preserve Rich Text styling in collapsible content for diff highlighting#661
sjathin wants to merge 2 commits intoOpenHands:mainfrom
sjathin:open-hands-cli-308

Conversation

@sjathin
Copy link
Copy Markdown
Contributor

@sjathin sjathin commented Apr 13, 2026

  • A human has tested these changes.

Why

The TUI was stripping Rich Text styling from SDK event visualizations by converting Text objects to plain strings via str(). The SDK's FileEditorObservation.visualize already generates colored diff output (red for removals, green for additions) through its visualize_diff() function, but this styling was lost before reaching the user. All collapsible content rendered as unstyled plain text.

Summary

  • Return event.visualize Text object directly from _build_observation_content() instead of str(event.visualize), preserving Rich styling (colors, bold, dim)
  • Pass Text objects through _create_titled_collapsible and _create_event_collapsible instead of escaping and stringifying
  • Widen _update_widget_in_ui signature to accept str | Text
  • Add 4 tests verifying Text objects and style spans are preserved through the rendering pipeline

Issue Number

Closes #308

Video/Screenshots

Before

Screenshot 2026-04-13 at 20 26 13

After

Screenshot 2026-04-13 at 20 29 42 Screenshot 2026-04-13 at 20 30 09 Screenshot 2026-04-13 at 20 30 57 Screenshot 2026-04-13 at 20 32 04

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • This is Phase 1 of [CLI]: Add rich diff viewer inside the TUI #308. The SDK already had full diff visualization support — the TUI was just discarding the styling. No new diff rendering logic was needed.
  • Phase 2 (separate PR): side-by-side diff view with a custom Textual widget
  • The _escape_rich_markup method is still used and correct for title strings (which use Rich markup syntax). It was only incorrectly applied to collapsible content (which uses Static(markup=False) and renders Text objects directly).

@sjathin sjathin marked this pull request as ready for review April 13, 2026 19:11
@sjathin sjathin changed the title fix(tui): preserve Rich Text styling in collapsible content for diff … fix(tui): preserve Rich Text styling in collapsible content for diff highlighting Apr 13, 2026
@sjathin sjathin changed the title fix(tui): preserve Rich Text styling in collapsible content for diff highlighting fix(tui): Preserve Rich Text styling in collapsible content for diff highlighting Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI]: Add rich diff viewer inside the TUI

1 participant