Skip to content

Communicate rendering credit usage in the TUI - #254

Merged
pedjaradenkovic merged 1 commit into
mainfrom
feat/communicate-rendering-credits
Jul 21, 2026
Merged

Communicate rendering credit usage in the TUI#254
pedjaradenkovic merged 1 commit into
mainfrom
feat/communicate-rendering-credits

Conversation

@pedjaradenkovic

@pedjaradenkovic pedjaradenkovic commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Implements Codeplain-ai/next-microsoft#13 — communicate rendering credit usage in the TUI.

Note: the tracking issue lives in next-microsoft, but the TUI code is in this repo.

What it does

Adds a credit-usage line beneath the render status — functionalities N used credits N render time T — matching the Figma design:

  • During render: live line under rendering in progress ...; render time ticks each second, counts update as functionalities complete.
  • On success: frozen totals under ✓ rendering completed! / generated code folder: … (wording synced to the console summary).
  • On failure: usage line placed below the error message.

used credits == functionalities — 1 credit is charged per functional requirement.

Key design points

  • usage_summary.py (new, root): single source of truth for the line's wording/markup, shared by the console summary (cli_output) and the TUI. Kept at root so tui stays independent of cli_output/the renderer.
  • One elapsed-time accessor, RunState.get_live_render_time(): the render time is computed in exactly one place and reused by the log timestamps (previously duplicated in ElapsedTimeFormatter and LoggingHandler), the TUI usage line, and the post-render summary. add_to_render_time resets the segment start after banking so the value isn't re-counted once a render completes.
  • The TUI owns only the refresh cadence: it reads get_live_render_time() and freezes the line while paused so it's never sampled inside the render machine's pause loop. On every terminal path it captures the live value onto run_state, so the TUI line and the console summary always agree.

Bug fixes included

  • format_duration_hms mangled whole-second inputs (10"1s") — this also affected the existing console summary and log timestamps.
  • Render time showed 0 on failure and on cancellation (the render machine doesn't finalize its time when an exception/cancel unwinds out of the render loop) — now the shared live value supplies the real elapsed time.

Tests

New: tests/test_usage_summary.py, tests/test_plain2code_utils.py, tests/test_plain2code_state.py (elapsed-time accounting), and tests/test_tui_usage.py (headless Textual run_test covering the live line, success/failure/cancel states, and pause-freeze).

black / isort / flake8 / mypy all clean. One pre-existing, unrelated failure remains on main (tests/test_plainfileparser.py::test_code_variables).

Open question for review

The generated code folder: path is currently shown absolute (pre-existing behavior, unchanged here); the mockup shows it relative. Left as-is per discussion — to be decided separately.

Add a live credit-usage line (functionalities / used credits / render
time) beneath the render status, shown while rendering and frozen on
success, failure, and cancellation. Wording matches the console
post-render summary.

- New root module usage_summary.py as the single source of truth for the
  usage line, shared by the console summary and the TUI. Kept at root so
  the TUI stays independent of cli_output/the renderer.
- Elapsed render time is read from a single RunState.get_live_render_time()
  accessor, reused by the log timestamps (previously duplicated in
  ElapsedTimeFormatter and LoggingHandler), the TUI usage line, and the
  summary. add_to_render_time resets the segment start after banking so the
  value is not re-counted once a render completes.
- The TUI owns only the refresh cadence: it reads get_live_render_time() and
  freezes the line while paused so it is never sampled inside the pause loop.
  On every terminal path it captures the live value onto run_state so the TUI
  line and console summary agree even when the render machine does not
  finalize its own time (fixes render time reporting 0 on failure and
  cancellation).
- Fix format_duration_hms mangling whole-second inputs (10s rendered as
  "1s"); reuse it for the substate timers.
- Reword the TUI success line to match the design and console
  ("rendering completed!", "generated code folder:").
@pedjaradenkovic
pedjaradenkovic force-pushed the feat/communicate-rendering-credits branch from cdc778d to a493264 Compare July 19, 2026 10:12
@pedjaradenkovic
pedjaradenkovic requested a review from NejcS July 19, 2026 10:12
@pedjaradenkovic pedjaradenkovic self-assigned this Jul 19, 2026
Comment thread tui/plain2code_tui.py
@pedjaradenkovic
pedjaradenkovic merged commit 52b756a into main Jul 21, 2026
10 checks passed
@pedjaradenkovic
pedjaradenkovic deleted the feat/communicate-rendering-credits branch July 21, 2026 12:45
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.

2 participants