class

Scroll::Tail

Inherits Reference < Object

Maintains the last N complete lines of a byte stream, fed in arbitrary chunks, guaranteeing the displayed window is always N (or fewer) genuinely contiguous complete lines — never a partial line and never a splice across a gap.

Each chunk is tagged with the byte offset at which it begins. If a chunk's start offset does not equal the end offset of the previous chunk, the pump dropped one or more chunks (STDERR could not keep up). Two things then follow:

  • The bytes immediately after a gap are the tail of a line whose head was dropped. They are skipped up to and including the next newline, so that truncated line is never shown.
  • The visible window is frozen on its last good contents while a fresh segment is rebuilt from the post-gap lines. Only once the new segment holds a full window does it replace the visible one. This keeps the display on a valid contiguous window at all times (jumping forward when it can) instead of blanking out and refilling on every drop.

Constants

NEWLINE = '\n'.ord.to_u8

Constructors

new(capacity : Int32)
Source

Instance methods

capacity
Source
feed(bytes : Bytes, start : Int64) : Nil

Feed a chunk of raw bytes that begins at byte start in the stream.

Source
finalize(include_trailing : Bool = false) : Nil

Finish the stream at EOF. Always reveals any partially-rebuilt segment so the display ends on the freshest lines rather than a frozen stale window. When include_trailing is true (the --final option), a trailing line with no newline is also promoted to a complete line first.

Source
size
Source
snapshot

The current retained lines, oldest first. Always a contiguous suffix of some complete-line run in the stream.

Source