use crate::logical::LogicalLine;
use super::Term;
impl Term {
pub fn viewport_logical_lines(&self) -> Vec<LogicalLine> {
let rows = self.grid.rows();
let total = self.scrollback.len() + rows;
let top = self.scrollback.len() - self.display_offset; let bottom = top + rows;
let floor = self.abs_floor();
let mut start = top;
while start > floor && self.abs_row(start - 1).is_wrapped() {
start -= 1;
}
let mut out = Vec::new();
let mut line = start;
while line < bottom {
let mut text = String::new();
let mut map: Vec<(i32, usize)> = Vec::new();
let mut cur = line;
loop {
let cells = self.abs_line(cur);
for (col, cell) in cells.iter().enumerate() {
if cell.is_spacer() {
continue;
}
let vrow = cur as i32 - top as i32;
text.push(cell.c());
map.push((vrow, col));
if let Some(marks) = self.combining_at(cur, col) {
for &m in marks {
text.push(m);
map.push((vrow, col));
}
}
}
let soft = self.abs_row(cur).is_wrapped();
if soft && cur + 1 < total {
cur += 1;
} else {
break;
}
}
let trimmed = text.trim_end_matches(' ');
map.truncate(trimmed.chars().count());
text.truncate(trimmed.len());
if !text.is_empty() {
out.push(LogicalLine { text, cells: map });
}
line = cur + 1;
}
out
}
}