pub struct Log<'a> { /* private fields */ }Expand description
The tail of messages that fits in the area it’s rendered into, oldest
at top, newest at the bottom, each line clipped to area.width() via
PrintLine.
offset (set via Log::offset, default 0) scrolls back through
history: 0 shows the most recent messages, and each increment moves
the window one message further into the past. Like
Table’s state.offset(), this does not clamp offset
– scrolling back past the start of messages shows fewer (or zero)
lines rather than wrapping or panicking, and it’s the caller’s
responsibility to stop incrementing offset past messages.len() if
that’s undesired. This is a different windowing direction than
Table’s (anchored to the most recent entry and counting backward,
rather than anchored to the start and counting forward), so it isn’t
expressed as the same shared helper.
messages is a plain slice the caller owns and appends to (the same
division of labor as ListState for selection):
this widget only reads it. Rows beyond the available messages are left
untouched – compose with fill_rect first
for a solid background if one is wanted.
§Examples
use retroglyph_core::text::Line;
use retroglyph_core::{Headless, Rect, Terminal};
use retroglyph_widgets::{Log, Widget};
let messages = [Line::raw("connected"), Line::raw("joined #general")];
let mut term = Terminal::new(Headless::new(20, 2));
Log::new(&messages).render(Rect::new(0, 0, 20, 2), &mut term);