fix(compatibility): do not offset first scroll region line (#82)

This commit is contained in:
Aram Drevekenin 2020-12-04 15:19:00 +01:00 committed by GitHub
parent a56cb3c9ad
commit 1c1558df64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 25 deletions

View File

@ -641,12 +641,9 @@ impl Scroll {
}
pub fn delete_lines_in_scroll_region(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self.scroll_region {
// the scroll region indices start at 1, so we need to adjust them
let scroll_region_top_index = scroll_region_top - 1;
let scroll_region_bottom_index = scroll_region_bottom - 1;
let current_canonical_line_index = self.cursor_position.line_index.0;
if current_canonical_line_index >= scroll_region_top_index
&& current_canonical_line_index <= scroll_region_bottom_index
if current_canonical_line_index >= scroll_region_top
&& current_canonical_line_index <= scroll_region_bottom
{
// when deleting lines inside the scroll region, we must make sure it stays the
// same size (and that other lines below it aren't shifted inside it)
@ -655,26 +652,23 @@ impl Scroll {
for _ in 0..count {
self.canonical_lines.remove(current_canonical_line_index);
self.canonical_lines
.insert(scroll_region_bottom_index + 1, CanonicalLine::new());
.insert(scroll_region_bottom, CanonicalLine::new());
}
}
}
}
pub fn add_empty_lines_in_scroll_region(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self.scroll_region {
// the scroll region indices start at 1, so we need to adjust them
let scroll_region_top_index = scroll_region_top - 1;
let scroll_region_bottom_index = scroll_region_bottom - 1;
let current_canonical_line_index = self.cursor_position.line_index.0;
if current_canonical_line_index >= scroll_region_top_index
&& current_canonical_line_index <= scroll_region_bottom_index
if current_canonical_line_index >= scroll_region_top
&& current_canonical_line_index <= scroll_region_bottom
{
// when adding empty lines inside the scroll region, we must make sure it stays the
// same size and that lines don't "leak" outside of it
// so we add an empty line where the cursor currently is, and delete the last line
// of the scroll region
for _ in 0..count {
self.canonical_lines.remove(scroll_region_bottom_index + 1);
self.canonical_lines.remove(scroll_region_bottom);
self.canonical_lines
.insert(current_canonical_line_index, CanonicalLine::new());
}

View File

@ -9,7 +9,7 @@ use crate::terminal_pane::terminal_character::{
AnsiCode, CharacterStyles, NamedColor, TerminalCharacter,
};
use crate::terminal_pane::Scroll;
use crate::utils::logging::{debug_log_to_file, debug_log_to_file_pid_0};
use crate::utils::logging::{debug_log_to_file, debug_log_to_file_pid_3};
use crate::VteEvent;
#[derive(Clone, Copy, Debug)]
@ -730,8 +730,7 @@ impl vte::Perform for TerminalPane {
.pending_styles
.background(Some(AnsiCode::NamedColor(NamedColor::White)));
} else {
debug_log_to_file_pid_0(format!("unhandled csi m code {:?}", params), self.pid)
.unwrap();
let _ = debug_log_to_file(format!("unhandled csi m code {:?}", params));
}
} else if c == 'C' {
// move cursor forward
@ -761,12 +760,21 @@ impl vte::Perform for TerminalPane {
// TODO: implement 1
} else if c == 'H' {
// goto row/col
// we subtract 1 from the row/column because these are 1 indexed
// (except when they are 0, in which case they should be 1
// don't look at me, I don't make the rules)
let (row, col) = if params.len() == 1 {
(params[0] as usize, params[0] as usize)
if params[0] == 0 {
(0, params[0] as usize)
} else {
(params[0] as usize - 1, params[0] as usize)
}
} else {
// we subtract 1 from the column because after we get a cursor goto, the print
// character should be printed on top of the cursor
(params[0] as usize, params[1] as usize - 1)
if params[0] == 0 {
(0, params[1] as usize - 1)
} else {
(params[0] as usize - 1, params[1] as usize - 1)
}
};
self.scroll.move_cursor_to(row, col);
} else if c == 'A' {
@ -818,8 +826,9 @@ impl vte::Perform for TerminalPane {
}
} else if c == 'r' {
if params.len() > 1 {
let top_line_index = params[0] as usize;
let bottom_line_index = params[1] as usize;
// minus 1 because these are 1 indexed
let top_line_index = params[0] as usize - 1;
let bottom_line_index = params[1] as usize - 1;
self.scroll
.set_scroll_region(top_line_index, bottom_line_index);
self.scroll.show_cursor();
@ -865,7 +874,8 @@ impl vte::Perform for TerminalPane {
let line = if params[0] == 0 {
1
} else {
params[0] as usize
// minus 1 because this is 1 indexed
params[0] as usize - 1
};
self.scroll.move_cursor_to_line(line);
} else if c == 'P' {

View File

@ -2,6 +2,7 @@
source: src/tests/integration/compatibility.rs
expression: snapshot
---
1 [||||||||||||||||||||||||||||||||||||||||||100.0%] Tasks: 79, 382 thr; 1 running
2 [ 0.0%] Load average: 1.40 1.43 1.38
3 [ 0.0%] Uptime: 2 days, 07:33:50
@ -29,4 +30,3 @@ expression: snapshot
444 root 20 0 1635M 83324 44976 S 0.0 0.5 0:33.13 /usr/bin/dockerd -H fd://
449 root 20 0 1635M 83324 44976 S 0.0 0.5 0:41.39 /usr/bin/dockerd -H fd://
F1Help F2Setup F3SearchF4FilterF5Tree F6SortByF7Nice -F8Nice +F9Kill F10Quit

View File

@ -37,8 +37,8 @@ pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> {
file.write_all(message.as_bytes())
}
pub fn debug_log_to_file_pid_0(message: String, pid: RawFd) -> io::Result<()> {
if pid == 0 {
pub fn debug_log_to_file_pid_3(message: String, pid: RawFd) -> io::Result<()> {
if pid == 3 {
debug_log_to_file(message)
} else {
Ok(())