mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 05:12:40 +03:00
refactor: hide Screen::lines field
I want to make some changes to the scrollback structure that first require routing some operations through an accessor method, so this commit does that. It should have no functional difference.
This commit is contained in:
parent
35054ed291
commit
2839293674
@ -564,7 +564,7 @@ impl Pane for LocalPane {
|
||||
}
|
||||
}
|
||||
|
||||
for (idx, line) in screen.lines.iter().enumerate() {
|
||||
screen.for_each_phys_line(|idx, line| {
|
||||
let stable_row = screen.phys_to_stable_row_index(idx);
|
||||
|
||||
let mut wrapped = false;
|
||||
@ -607,7 +607,7 @@ impl Pane for LocalPane {
|
||||
coords.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
collect_matches(
|
||||
&mut results,
|
||||
|
@ -55,18 +55,10 @@ pub fn terminal_get_dirty_lines(
|
||||
seqno: SequenceNo,
|
||||
) -> RangeSet<StableRowIndex> {
|
||||
let screen = term.screen();
|
||||
let phys = screen.stable_range(&lines);
|
||||
let lines = screen.get_changed_stable_rows(lines, seqno);
|
||||
let mut set = RangeSet::new();
|
||||
for (idx, line) in screen
|
||||
.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(phys.start)
|
||||
.take(phys.end - phys.start)
|
||||
{
|
||||
if line.changed_since(seqno) {
|
||||
set.add(screen.phys_to_stable_row_index(idx))
|
||||
}
|
||||
for line in lines {
|
||||
set.add(line);
|
||||
}
|
||||
set
|
||||
}
|
||||
@ -79,20 +71,14 @@ pub fn terminal_get_lines(
|
||||
let reverse = term.get_reverse_video();
|
||||
let screen = term.screen_mut();
|
||||
let phys_range = screen.stable_range(&lines);
|
||||
(
|
||||
screen.phys_to_stable_row_index(phys_range.start),
|
||||
screen
|
||||
.lines
|
||||
.iter_mut()
|
||||
.skip(phys_range.start)
|
||||
.take(phys_range.end - phys_range.start)
|
||||
.map(|line| {
|
||||
let mut cloned = line.clone();
|
||||
cloned.set_reverse(reverse, SEQ_ZERO);
|
||||
cloned
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
|
||||
let first = screen.phys_to_stable_row_index(phys_range.start);
|
||||
let mut lines = screen.lines_in_phys_range(phys_range);
|
||||
for line in &mut lines {
|
||||
line.set_reverse(reverse, SEQ_ZERO);
|
||||
}
|
||||
|
||||
(first, lines)
|
||||
}
|
||||
|
||||
/// Implements Pane::get_dimensions for Terminal
|
||||
@ -101,7 +87,7 @@ pub fn terminal_get_dimensions(term: &mut Terminal) -> RenderableDimensions {
|
||||
RenderableDimensions {
|
||||
cols: screen.physical_cols,
|
||||
viewport_rows: screen.physical_rows,
|
||||
scrollback_rows: screen.lines.len(),
|
||||
scrollback_rows: screen.scrollback_rows(),
|
||||
physical_top: screen.visible_row_to_stable_row(0),
|
||||
scrollback_top: screen.phys_to_stable_row_index(0),
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ pub struct Screen {
|
||||
/// on the current window size) and will be the first line to be
|
||||
/// popped off the front of the screen when a new line is added that
|
||||
/// would otherwise have exceeded the line capacity
|
||||
pub lines: VecDeque<Line>,
|
||||
lines: VecDeque<Line>,
|
||||
|
||||
/// Whenever we scroll a line off the top of the scrollback, we
|
||||
/// increment this. We use this offset to translate between
|
||||
@ -296,6 +296,11 @@ impl Screen {
|
||||
&mut self.lines[idx]
|
||||
}
|
||||
|
||||
/// Returns the number of occupied rows of scrollback
|
||||
pub fn scrollback_rows(&self) -> usize {
|
||||
self.lines.len()
|
||||
}
|
||||
|
||||
/// Sets a line dirty. The line is relative to the visible origin.
|
||||
#[inline]
|
||||
pub fn dirty_line(&mut self, idx: VisibleRowIndex, seqno: SequenceNo) {
|
||||
@ -810,4 +815,52 @@ impl Screen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lines_in_phys_range(&self, phys_range: Range<PhysRowIndex>) -> Vec<Line> {
|
||||
self.lines
|
||||
.iter()
|
||||
.skip(phys_range.start)
|
||||
.take(phys_range.end - phys_range.start)
|
||||
.map(|line| line.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_changed_stable_rows(
|
||||
&self,
|
||||
stable_lines: Range<StableRowIndex>,
|
||||
seqno: SequenceNo,
|
||||
) -> Vec<StableRowIndex> {
|
||||
let phys = self.stable_range(&stable_lines);
|
||||
let mut set = vec![];
|
||||
for (idx, line) in self
|
||||
.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(phys.start)
|
||||
.take(phys.end - phys.start)
|
||||
{
|
||||
if line.changed_since(seqno) {
|
||||
set.push(self.phys_to_stable_row_index(idx))
|
||||
}
|
||||
}
|
||||
set
|
||||
}
|
||||
|
||||
pub fn for_each_phys_line<F>(&self, mut f: F)
|
||||
where
|
||||
F: FnMut(usize, &Line),
|
||||
{
|
||||
for (idx, line) in self.lines.iter().enumerate() {
|
||||
f(idx, line);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_each_phys_line_mut<F>(&mut self, mut f: F)
|
||||
where
|
||||
F: FnMut(usize, &mut Line),
|
||||
{
|
||||
for (idx, line) in self.lines.iter_mut().enumerate() {
|
||||
f(idx, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -683,11 +683,13 @@ impl TerminalState {
|
||||
self.erase_in_display(EraseInDisplay::EraseScrollback);
|
||||
|
||||
let row_index = self.screen.phys_row(self.cursor.y);
|
||||
let row = self.screen.lines[row_index].clone();
|
||||
let rows = self.screen.lines_in_phys_range(row_index..row_index + 1);
|
||||
|
||||
self.erase_in_display(EraseInDisplay::EraseDisplay);
|
||||
|
||||
self.screen.lines[0] = row;
|
||||
for (idx, row) in rows.into_iter().enumerate() {
|
||||
*self.screen.line_mut(idx) = row;
|
||||
}
|
||||
|
||||
self.cursor.y = 0;
|
||||
}
|
||||
@ -864,9 +866,9 @@ impl TerminalState {
|
||||
pub fn make_all_lines_dirty(&mut self) {
|
||||
let seqno = self.seqno;
|
||||
let screen = self.screen_mut();
|
||||
for line in &mut screen.lines {
|
||||
screen.for_each_phys_line_mut(|_, line| {
|
||||
line.update_last_change_seqno(seqno);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Returns the 0-based cursor position relative to the top left of
|
||||
@ -2506,7 +2508,7 @@ impl TerminalState {
|
||||
let mut zones = vec![];
|
||||
|
||||
let first_stable_row = screen.phys_to_stable_row_index(0);
|
||||
for (idx, line) in screen.lines.iter_mut().enumerate() {
|
||||
screen.for_each_phys_line_mut(|idx, line| {
|
||||
let stable_row = first_stable_row + idx as StableRowIndex;
|
||||
|
||||
for zone_range in line.semantic_zone_ranges() {
|
||||
@ -2534,7 +2536,7 @@ impl TerminalState {
|
||||
zone.end_y = stable_row;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if let Some(zone) = current_zone.take() {
|
||||
zones.push(zone);
|
||||
}
|
||||
|
@ -167,20 +167,14 @@ impl TestTerm {
|
||||
|
||||
fn assert_dirty_lines(&self, seqno: SequenceNo, expected: &[usize], reason: Option<&str>) {
|
||||
let mut seqs = vec![];
|
||||
let dirty_indices: Vec<usize> = self
|
||||
.screen()
|
||||
.lines
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, line)| {
|
||||
let mut dirty_indices = vec![];
|
||||
|
||||
self.screen().for_each_phys_line(|i, line| {
|
||||
seqs.push(line.current_seqno());
|
||||
if line.changed_since(seqno) {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
dirty_indices.push(i);
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
});
|
||||
assert_eq!(
|
||||
&dirty_indices, &expected,
|
||||
"actual dirty lines (left) didn't match expected dirty \
|
||||
@ -280,9 +274,9 @@ fn print_all_lines(term: &Terminal) {
|
||||
let screen = term.screen();
|
||||
|
||||
println!("whole screen contents are:");
|
||||
for line in screen.lines.iter() {
|
||||
screen.for_each_phys_line(|_, line| {
|
||||
println!("[{}]", line.as_str());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn print_visible_lines(term: &Terminal) {
|
||||
|
Loading…
Reference in New Issue
Block a user