oc_chat
Loading...
Searching...
No Matches
oc_ui.terminal.rich_presenter Namespace Reference

Classes

class  _StatusBarLive
class  RichPresenter

Functions

Panel build_answer_panel (RenderableType body, str subtitle="")
Text _check (flag)

Variables

int DEFAULT_TOOL_SPILL_CHARS = 4000
dict _THEME
dict _RULE_TAG_STYLES

Detailed Description

Rich-based presenter for OC Chat (Phase 1.A — skeleton).

Purpose
-------
Implements the :class:`~oc_ui.presenter_base.Presenter` contract
using the `rich <https://rich.readthedocs.io/>`_ library. This first
slice (PR 1.A) ships:

* Styled welcome banner via ``rich.panel.Panel``.
* Pretty tables for ``/models``, ``/session list``, ``/help`` via
  ``rich.table.Table`` — auto column-widths, overflow handling,
  borders.
* Consistent colour theme for info/error/compressed/turn-summary
  lines.
* No streaming overlay yet — :meth:`turn` is a no-op contextmanager
  and :meth:`show_reasoning` / :meth:`show_content` print each chunk
  via ``Console.print(end="")``. Live streaming + Markdown post-commit
  arrive in PR 1.B.

To enable, install the optional dep::

    pip install -e .[rich]

Then run::

    python OC Chat.py --ui rich

If ``rich`` is missing, ``oc_chat.main`` lazy-imports this module and
falls back to :class:`~oc_ui.terminal.presenter.ConsolePresenter`
with a warning.

Responsibilities
----------------
- :class:`RichPresenter` — concrete :class:`Presenter` backed by
  ``rich.console.Console``.
- Themed output via :class:`rich.panel.Panel` and
  :class:`rich.table.Table` for the structured commands.
- Plain ``Console.print`` fallback for streaming chunks pending
  the PR 1.B Live overlay.

Diagnostics
-----------
Domain: OC_UI.TERMINAL
Levels:
    L2 — lifecycle events
    L3 — semantic details
    L4 — deep tracing

Contracts
---------
- Importing this module without ``rich`` installed raises
  :class:`ImportError`; ``main.py`` is responsible for the optional-
  dep gate.
- Theme colours are taken from one ``rich.theme.Theme`` instance so
  callers can override centrally.
- Behavioural parity with :class:`ConsolePresenter` for any non-
  streaming hook — the rich version only adds visual polish.

Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)
- rich.console (terminal rendering — panels, tables, syntax highlighting)
- rich.live (terminal rendering — panels, tables, syntax highlighting)
- rich.markdown (terminal rendering — panels, tables, syntax highlighting)
- rich.padding (terminal rendering — panels, tables, syntax highlighting)
- rich.panel (terminal rendering — panels, tables, syntax highlighting)
- rich.status (terminal rendering — panels, tables, syntax highlighting)
- rich.table (terminal rendering — panels, tables, syntax highlighting)
- rich.text (terminal rendering — panels, tables, syntax highlighting)
- oc_ui.presenter_base (Presenter ABC contract)
- oc_ui.terminal._render (RenderBatcher for batched Live refreshes while streaming)
- oc_ui.terminal.activity (plan_progress_from_result for the plan progress line under planner results)
- oc_ui.terminal.diffview (mutation argument pairing and the diff model for write_file and edit_file results)
- oc_ui.terminal.statusline (StatusBarState and status line rendering for the Live status bar)
- oc_ui.terminal.turn_layout (turn indent, rule composition and answer box titles)
- oc_chat.core.commands (lazy; _fmt_tokens_display for the session list table)
- oc_chat.core.config (lazy; REASONING_EFFORT_LEVELS for the welcome panel)
- oc_chat.core.formatting (lazy; format_duration for the turn summary)
- oc_chat.core.iteration_stat (lazy; iteration_stat_human_line for the answer box bottom border and stats line)
- oc_chat.core.persistence (lazy; save_tool_artifact for spilling long tool results to a file)
- oc_chat.core.session (lazy; ChatSession type hint for bind_session and show_welcome)
- oc_chat.core.tool_activity (lazy; TOOL_ACTIVITY snapshot of the in-flight tool call for the status bar)
- oc_ui.terminal.presenter (lazy; ConsolePresenter._fmt_turn_cost for the shared turn cost segment)
- rich.spinner (animated spinners for the waiting indicator and dispatch chrome)

Function Documentation

◆ _check()

Text oc_ui.terminal.rich_presenter._check ( flag)
protected
Return a styled ✓ / ✗ marker for boolean capability flags.

Definition at line 1219 of file rich_presenter.py.

Here is the caller graph for this function:

◆ build_answer_panel()

Panel oc_ui.terminal.rich_presenter.build_answer_panel ( RenderableType body,
str subtitle = "" )
Build the plan-218 answer box.

P1 element 2/3: ``Assistant Answer:`` is cut into the TOP border
(left-aligned — the session box's own title-in-border mechanic, just
anchored left per the operator's mock) and the per-iteration metadata
line is cut into the BOTTOM border, so the numbers that describe the
answer are attached to the answer instead of floating under it.

Every style token is borrowed from the session box
(:meth:`RichPresenter.show_welcome`) rather than invented: same
``panel_border`` colour, same default box, same ``(1, 2)`` padding.
P3 — no new colours.

*subtitle* is the metadata string; empty renders a plain bottom
border (a turn whose iteration stats are suppressed still closes its
box — it just closes it without numbers).

Definition at line 192 of file rich_presenter.py.

Here is the caller graph for this function:

Variable Documentation

◆ _RULE_TAG_STYLES

dict oc_ui.terminal.rich_presenter._RULE_TAG_STYLES
protected
Initial value:
1= {
2 "fill": "rule",
3 "label": "rule",
4 "stats": "summary",
5 "trailer": "summary",
6}

Definition at line 184 of file rich_presenter.py.

◆ _THEME

dict oc_ui.terminal.rich_presenter._THEME
protected
Initial value:
1= {
2 "rule": "dim cyan",
3 "turn_label": "dim",
4 "waiting": "italic dim cyan",
5 "reasoning": "dim italic cyan",
6 "content": "default",
7 "tool_call": "yellow",
8 "tool_result": "green",
9 "tool_error": "red",
10 "info": "dim",
11 "error": "bold red",
12 "warning": "yellow",
13 "compressed": "dim",
14 "summary": "dim",
15 "panel_border": "cyan",
16 "panel_title": "bold cyan",
17 # Plan 188 T1 — diff view. Rich honours NO_COLOR natively, so these degrade
18 # to plain text without a separate code path.
19 "diff_add": "green",
20 "diff_del": "red",
21 "diff_hunk": "cyan",
22 "diff_header": "dim",
23}

Definition at line 154 of file rich_presenter.py.

◆ DEFAULT_TOOL_SPILL_CHARS

int oc_ui.terminal.rich_presenter.DEFAULT_TOOL_SPILL_CHARS = 4000

Definition at line 148 of file rich_presenter.py.