pub fn read_output_file_tail(
path: &Path,
max_lines: usize,
) -> Option<Vec<String>>Expand description
Read the last max_lines lines of path into a Vec ordered
oldest-first. Returns None on any read error (file missing,
permission denied, a read that failed) so the caller can distinguish
“could not read, keep the tail already held” from “the file is
genuinely empty”. The empty-file case returns Some(vec![]).
The lines come back as the command wrote them, escape sequences and all. What a renderer has to drop to draw them is the renderer’s business: different renderers drop different bytes, so neither rule belongs on a read that only hands the text over.
Only the final TAIL_WINDOW_BYTES are read: for a larger file the
read seeks to len - TAIL_WINDOW_BYTES and drops the first (probably
partial) line after the seek. Files under the window are read whole.
A file the watched command is still writing is read as it stands: an
unterminated final line comes back as Ok and is kept. The one line
that is dropped for good is one that is not valid UTF-8, which is
skipped on every read rather than once.