Skip to main content

TextDeltaRenderer

Struct TextDeltaRenderer 

Source
pub struct TextDeltaRenderer;
Expand description

Default implementation of DeltaRenderer for text content.

Supports true append-only streaming pattern that works correctly under line wrapping and in ANSI-stripping environments.

  • First delta: prefix + content (no newline, stays on current line)
  • Subsequent deltas: Parser computes and emits only new suffix
  • Completion: single newline via DeltaRenderer::render_completion
  • Sanitizes newlines to spaces (to prevent artificial line breaks)
  • Applies consistent color formatting

§Output Pattern

§Full Mode (TTY with capable terminal) - Append-Only Pattern

[ccs-glm] Hello                    <- First delta: prefix + content, NO newline
 World                             <- Parser emits suffix: " World" (no prefix, no \r)
\n                                  <- Completion: single newline

Result: Single logical line that may wrap to multiple terminal rows. Terminal handles wrapping naturally. No cursor movement means wrapping is not an issue.

§Full Mode (Legacy Pattern - Deprecated)

Some parsers not yet implementing append-only may still use render_subsequent_delta which rewrites the line with \r. This pattern has known issues with wrapping:

[ccs-glm] Hello                    <- First delta
\r[ccs-glm] Hello World            <- Subsequent: carriage return + full rewrite

Issue: When content wraps, \r only returns to column 0 of current row, not start of logical line. This causes display corruption.

§Basic/None Mode (non-TTY logs)

In non-TTY modes, per-delta output is suppressed to avoid repeated prefixed lines for partial updates. The parser is responsible for flushing the final accumulated content once at a completion boundary (e.g. message_stop).

[ccs-glm] Hello World\n

§CCS Spam Prevention (Bug Fix)

This implementation prevents repeated prefixed lines for CCS agents (ccs/codex, ccs/glm) in non-TTY modes. The spam fix is validated with comprehensive regression tests that simulate real-world streaming scenarios:

  • Ultra-extreme delta counts: Tests verify no spam with 1000+ deltas per content block
  • Multi-turn sessions: Validates 3+ turns with 200+ deltas each (600+ total)
  • All delta types: Covers text deltas, thinking deltas, and tool input deltas
  • Real-world logs: Tests with production logs containing 12,596 total deltas

The multi-line pattern (in-place updates) is the industry standard used by Rich, Ink, Bubble Tea, and other production CLI libraries for clean streaming output.

See regression tests:

  • tests/integration_tests/ccs_delta_spam_systematic_reproduction.rs (systematic reproduction & verification)
  • tests/integration_tests/ccs_all_delta_types_spam_reproduction.rs (1000+ deltas, edge case coverage)
  • tests/integration_tests/ccs_extreme_streaming_regression.rs (500+ deltas per block)
  • tests/integration_tests/ccs_streaming_spam_all_deltas.rs (all delta types)
  • tests/integration_tests/ccs_real_world_log_regression.rs (production log regression)
  • tests/integration_tests/ccs_nuclear_full_log_regression.rs (large captured logs)
  • tests/integration_tests/codex_reasoning_spam_regression.rs (Codex reasoning regression)
  • tests/integration_tests/ccs_wrapping_waterfall_reproduction.rs (wrapping waterfall reproduction)
  • tests/integration_tests/ccs_wrapping_comprehensive.rs (wrapping + append-only behavior)
  • tests/integration_tests/ccs_ansi_stripping_console.rs (ANSI-stripping console behavior)

Trait Implementations§

Source§

impl DeltaRenderer for TextDeltaRenderer

Source§

fn render_first_delta( accumulated: &str, prefix: &str, colors: Colors, terminal_mode: TerminalMode, ) -> String

Render the first delta of a content block. Read more
Source§

fn render_subsequent_delta( _accumulated: &str, _prefix: &str, _colors: Colors, terminal_mode: TerminalMode, ) -> String

Render a subsequent delta (in-place update). Read more
Source§

fn render_completion(terminal_mode: TerminalMode) -> String

Render the completion of streaming. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.