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

Classes

class  ConsolePresenter

Functions

bool _color_enabled ()

Variables

bool _COLOR = _color_enabled()
str STYLE_RESET = "\033[0m" if _COLOR else ""
str STYLE_DIM = "\033[2m" if _COLOR else ""
str STYLE_ITALIC = "\033[3m" if _COLOR else ""
str STYLE_BOLD = "\033[1m" if _COLOR else ""
str STYLE_CYAN = "\033[36m" if _COLOR else ""
str STYLE_YELLOW = "\033[33m" if _COLOR else ""
str STYLE_GREEN = "\033[32m" if _COLOR else ""
str STYLE_RED = "\033[31m" if _COLOR else ""
list REASONING_EFFORT_LEVELS = ["low", "medium", "high"]

Detailed Description

Plain-ANSI console presenter for OC Chat.

Purpose
-------
:class:`ConsolePresenter` implements the
:class:`~oc_ui.presenter_base.Presenter` contract using simple
``print`` calls and ANSI escape codes from
:mod:`oc_chat.core.config`. It is the default presenter and the
fallback used by CI, headless runs, and any environment without
optional ``rich`` / ``textual`` dependencies installed.

The Phase 0 quick wins live here:

- Horizontal rule + turn number + timestamp at :meth:`start_turn`.
- :meth:`show_waiting` indicator that is cleared by the first
  reasoning / content chunk.
- Compact :meth:`show_turn_summary` (one dim line) — full
  per-iteration breakdown only when ``verbose`` is set.
- ``NO_COLOR`` / ``FORCE_COLOR`` honoured via the STYLE_* constants
  in :mod:`oc_chat.core.config`.

Responsibilities
----------------
- :class:`ConsolePresenter` — concrete :class:`Presenter`
  implementation backed by ``print``.
- :func:`_color_enabled` — env-var-based ANSI gating.
- All ``show_*`` event hooks for reasoning / content / tool / usage
  / turn-summary / compressed / welcome.
- :meth:`turn` returns a no-op ``contextmanager`` (no live region).

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

Contracts
---------
- Output goes to ``stdout`` exclusively; diagnostics and warnings
  live on ``stderr`` via ``oc_diagnostics``.
- ``NO_COLOR`` set (any value) disables every ANSI sequence.
- ``FORCE_COLOR`` overrides ``NO_COLOR`` and forces ANSI on.
- ``show_*`` hooks are append-only — the presenter never rewinds.
- Safe to use under CI / non-TTY: ``shutil.get_terminal_size`` is
  used with a fallback when the size is undetermined.

Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)
- oc_ui.presenter_base (Presenter ABC contract)
- oc_ui.terminal.activity (plan_progress_from_result for the plan progress line under planner results)
- oc_ui.terminal.diffview (mutation argument pairing and plain unified diff rendering for write_file and edit_file)
- oc_ui.terminal.turn_layout (turn indent, rule labels, answer box markers and line indenters)
- oc_chat.core.commands (lazy; _fmt_tokens_display for the session list table)
- oc_chat.core.formatting (lazy; format_duration for the turn summary)
- oc_chat.core.iteration_stat (lazy; iteration_stat_human_line for the per-iteration stats line)
- oc_chat.core.session (lazy; ChatSession type hint for show_welcome)
- oc_ui.terminal.statusline (lazy; StatusBarState type hint for bind_status)

Function Documentation

◆ _color_enabled()

bool oc_ui.terminal.presenter._color_enabled ( )
protected
Return True iff ANSI styles should be emitted.

Definition at line 106 of file presenter.py.

Variable Documentation

◆ _COLOR

bool oc_ui.terminal.presenter._COLOR = _color_enabled()
protected

Definition at line 115 of file presenter.py.

◆ REASONING_EFFORT_LEVELS

list oc_ui.terminal.presenter.REASONING_EFFORT_LEVELS = ["low", "medium", "high"]

Definition at line 124 of file presenter.py.

◆ STYLE_BOLD

str oc_ui.terminal.presenter.STYLE_BOLD = "\033[1m" if _COLOR else ""

Definition at line 119 of file presenter.py.

◆ STYLE_CYAN

str oc_ui.terminal.presenter.STYLE_CYAN = "\033[36m" if _COLOR else ""

Definition at line 120 of file presenter.py.

◆ STYLE_DIM

str oc_ui.terminal.presenter.STYLE_DIM = "\033[2m" if _COLOR else ""

Definition at line 117 of file presenter.py.

◆ STYLE_GREEN

str oc_ui.terminal.presenter.STYLE_GREEN = "\033[32m" if _COLOR else ""

Definition at line 122 of file presenter.py.

◆ STYLE_ITALIC

str oc_ui.terminal.presenter.STYLE_ITALIC = "\033[3m" if _COLOR else ""

Definition at line 118 of file presenter.py.

◆ STYLE_RED

str oc_ui.terminal.presenter.STYLE_RED = "\033[31m" if _COLOR else ""

Definition at line 123 of file presenter.py.

◆ STYLE_RESET

str oc_ui.terminal.presenter.STYLE_RESET = "\033[0m" if _COLOR else ""

Definition at line 116 of file presenter.py.

◆ STYLE_YELLOW

str oc_ui.terminal.presenter.STYLE_YELLOW = "\033[33m" if _COLOR else ""

Definition at line 121 of file presenter.py.