regions: Vec<ComposeBufferRegion>,
layout: Vec<ComposeLayoutCell>,
cursor_pos: Option<(usize, usize)>,
+ ytop: usize,
scanner: &'static Scan,
conf: InstanceStatusConfig,
last_size: Option<(usize, usize)>,
regions: Vec::new(),
layout: Vec::new(),
cursor_pos: None,
+ ytop: 0,
scanner: Scan::get(),
conf,
last_size: None,
self.layout = self.layout(w);
}
self.cursor_pos = self.determine_cursor_pos();
+
+ if let Some((_cx, cy)) = self.cursor_pos {
+ // Scroll to keep the cursor in view
+ self.ytop = min(self.ytop, cy);
+ self.ytop = max(self.ytop, (cy + 1).saturating_sub(self.page_len));
+ }
}
fn goto_xy(&mut self, x: usize, y: usize) -> bool {
}
lines.extend_from_slice(&self.headersep.render(w));
- let ytop = 0; // FIXME: vary this to keep cursor in view
let ystart = lines.len();
while lines.len() < h {
- let y = ytop + (lines.len() - ystart);
+ let y = self.ytop + (lines.len() - ystart);
match self.get_coloured_line(y) {
Some(line) => lines.push(line),
None => break, // ran out of lines in the buffer
let mut cursor_pos = CursorPosition::None;
if let Some((cx, cy)) = self.cursor_pos {
- if let Some(y) = cy.checked_sub(ytop) {
+ if let Some(y) = cy.checked_sub(self.ytop) {
let cy = y + ystart;
if cy < h {
cursor_pos = CursorPosition::At(cx, cy);