in src/superconsole.rs [154:191]
fn render_general(
&mut self,
buffer: &mut Vec<u8>,
state: &State,
mode: DrawMode,
size: Dimensions,
) -> anyhow::Result<()> {
/// Heuristic to determine if a buffer is too large to buffer.
/// Can be tuned, but is currently set to 1000000 graphemes.
#[allow(clippy::ptr_arg)]
fn is_big(buf: &Lines) -> bool {
let len: usize = buf.iter().map(Line::len).sum();
len > MAX_GRAPHEME_BUFFER
}
// Go the beginning of the canvas.
self.root.move_up(buffer)?;
// Pre-draw the frame *and then* start rendering emitted messages.
let mut frame = self.root.draw(state, size, mode)?;
// Render at most a single frame if this not the last render.
// Does not buffer if there is a ridiculous amount of data.
let limit = match mode {
DrawMode::Normal if !is_big(&self.to_emit) => {
let limit = (size.y as usize).saturating_sub(frame.len());
// arbitrary value picked so we don't starve `emit` on small terminal sizes.
Some(cmp::max(limit, MINIMUM_EMIT))
}
_ => None,
};
self.to_emit.render(buffer, limit)?;
frame.render(buffer, None)?;
// clear any residue from the previous render.
queue!(buffer, Clear(ClearType::FromCursorDown))?;
Ok(())
}