~hime/protochat

559893d95dedad1b45696bafb0af3ca41f475c6d — drbawb 11 months ago 08d3df1
(linetest/ui/buffer) return more generalized iterator

This returns a double ended iterator, which gives callers
downstream a bit more flexibility in how lines are presented
to the client.

This may be useful if we later add buffers that are painted from
top-down, rather than bottom-up.
1 files changed, 5 insertions(+), 4 deletions(-)

M linetest/src/shell/ui/buffer.rs
M linetest/src/shell/ui/buffer.rs => linetest/src/shell/ui/buffer.rs +5 -4
@@ 1,4 1,3 @@

use crossterm::{
    cursor,
    style::{self, Print},


@@ 26,8 25,8 @@ impl Span {
        Self { lines: lines }
    }

    pub fn line_iter(&self) -> impl Iterator<Item = &String> {
        self.lines.iter().rev()
    pub fn line_iter(&self) -> impl DoubleEndedIterator<Item = &String> {
        self.lines.iter()
    }
}
/// The `Buffer` stores a list of lines which need to be displayed 


@@ 103,11 102,13 @@ impl Buffer {
        .map(|line| Span::new(line, self.cols))
        .collect::<Vec<_>>();

        // grab at most a buffer's worth of lines
        let viewport_lines = self.viewport_spans
            .iter()
            .flat_map(|span| span.line_iter())
            .flat_map(|span| span.line_iter().rev())
            .take(self.rows as usize);

        // blit lines to the viewport
        let mut rows_drawn = 0;
        for line in viewport_lines {
            rows_drawn += 1;