Skip to content
Veloce Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Stream logs into a ScrollView

Recipe for offset slicing and scrollbars.

Stream logs into a ScrollView

Problem: show an unbounded line stream in a bounded viewport.

Steps:

  1. Keep logs: Vec<String> and offset: u16 in view state. Render:
ScrollView::new()
    .offset(self.offset)
    .flex_grow(1.0)
    .children(self.logs.iter().map(Text::new))
  1. Append lines from background actions; leave offset alone to pin the top, or clamp it to the bottom to tail the stream.
  2. Drive offset from Up/Down keys with saturating_sub/saturating_add — the position stays stable across frames.
  3. A scrollbar (█/│) appears automatically once content overflows the viewport.

Check: push 2,000 lines and confirm the frame stays interactive; the runnable agent_dashboard example streams mock tool output this way:

cargo run -p veloce-tui --example agent_dashboard

Was this page helpful?