Skip to content

[FEATURE] Syntax highlighting for code in diff/content rendering (chroma) #866

Description

@edenreich

Summary

Follow-up to #865 (card-based tool-call formatter overhaul). The card and diff
surfaces now render file content and diffs cleanly, but the content itself is
still emitted as plain, uncolored text — a Write preview, a Read body, and
the added/removed lines of an Edit/MultiEdit diff show no language-aware
syntax highlighting. Reviewing a proposed change in the approval window would be
noticeably easier to scan with proper highlighting (keywords, strings, comments,
types).

Proposal: add syntax highlighting for programming languages to the diff/content
renderer, keyed off the file extension (and language guess for extensionless
files). chroma is a strong candidate:
it lexes ~250 languages, emits ANSI, and — importantly — is already in the
dependency tree
(github.com/alecthomas/chroma/v2 v2.27.0, pulled in
transitively by charm.land/glamour/v2), so this adds no new direct dependency.
It ships a terminal256/terminalTruecolor formatter that maps cleanly onto the
existing per-token styling, and its style registry can be selected from the
active theme.

Scope notes / constraints:

  • TUI-only. Highlighting must be gated on FormatterUI, same as the card
    colors. FormatterLLM / FormatterShort output must stay plain (ANSI-free) —
    the existing tests assert this and headless infer agent output must not gain
    escape codes.
  • Highlight the content of added/context lines inside a diff; the diff's own
    add/remove +/- coloring (from the diff renderer) stays the source of truth
    for line-level status. The two color layers must compose without fighting
    (foreground token color over the diff line background).
  • Language detection from DiffInfo.FilePath / the tool's file_path arg;
    fall back to no highlighting (plain, current behavior) on unknown languages
    rather than guessing wrong.
  • Respect width/wrapping already handled by DiffRenderer — highlighting is a
    per-token color pass, it must not change the line-splitting/truncation logic.
  • Theme integration: pick a chroma style (or map tokens through the theme
    provider) so it honors light/dark and the existing styles.Provider, keeping
    lipgloss confined to the provider per the component rules.

Primary surface: internal/ui/components/diff_renderer.go
(renderContentPreview, the per-line diff rendering, RenderWriteToolArguments).

Acceptance Criteria

  • Write/Read/Edit/MultiEdit content rendered in the TUI shows
    language-aware syntax highlighting driven by file extension, with a plain
    fallback for unknown/unsupported languages.
  • Highlighting is gated on FormatterUI; FormatterLLM and FormatterShort
    output remains ANSI-free (existing plain-output tests still pass).
  • Token highlighting composes with the existing diff add/remove coloring
    without visual conflict, and does not alter line wrapping/truncation.
  • Highlight style honors the active theme (light/dark) via the styles
    provider; no lipgloss/chroma imports leak into components beyond the
    established provider seam.
  • No new direct dependency added (reuse the already-vendored chroma/v2).
  • Unit tests cover: highlighting applied for a known language, plain fallback
    for an unknown extension, and ANSI-free LLM/Short output.

Follow-up from #865 · #865

Activity

  1. added
    enhancement
    on Jul 11, 2026
  2. moved this to Todo in 2026on Jul 11, 2026
  3. added a commit that references this issue on Jul 11, 2026
    3d10d94
  4. moved this from Todo to Done in 2026on Jul 12, 2026
  5. inference-gateway-releaser commented on Jul 12, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.143.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions