Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions src/painting/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,13 @@ use {crate::LineBuffer, crossterm::cursor::MoveUp};
// Returns a string that skips N number of lines with the next offset of lines
// An offset of 0 would return only one line after skipping the required lines
fn skip_buffer_lines(string: &str, skip: usize, offset: Option<usize>) -> &str {
let mut matches = string.match_indices('\n');
let index = if skip == 0 {
0
} else {
matches
.clone()
.nth(skip - 1)
.map(|(index, _)| index + 1)
.unwrap_or(string.len())
};

let limit = match offset {
Some(offset) => {
let offset = skip + offset;
matches
.nth(offset)
.map(|(index, _)| index)
.unwrap_or(string.len())
}
None => string.len(),
};
let (index, limit) = skip_buffer_lines_range(string, skip, offset);

string[index..limit].trim_end_matches('\n')
}

// The byte range `skip_buffer_lines` slices, for callers that need to map a
// position back into the unskipped string.
fn skip_buffer_lines_range(string: &str, skip: usize, offset: Option<usize>) -> (usize, usize) {
let mut matches = string.match_indices('\n');
let index = if skip == 0 {
Expand Down
Loading