fix: fallback to default values when terminal rows/cols are 0 (#1552)

* fix: fallback to default values when terminal rows/cols = 0

* increase retry_pause for failing test

* e2e: load fixtures with cat

* use variable for fixture path
This commit is contained in:
Thomas Linford 2022-07-04 18:28:37 +02:00 committed by GitHub
parent c5e82b7247
commit 3aef436a69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 102 deletions

View file

@ -208,7 +208,6 @@ pub fn scrolling_inside_a_pane() {
let last_snapshot = loop {
RemoteRunner::kill_running_sessions(fake_win_size);
let mut runner = RemoteRunner::new(fake_win_size)
.retry_pause_ms(1000) // we need a longer retry period here because it takes some time to fill the pty buffer
.add_step(Step {
name: "Split pane to the right",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
@ -229,32 +228,7 @@ pub fn scrolling_inside_a_pane() {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(63, 2) && remote_terminal.tip_appears() {
// cursor is in the newly opened second pane
let mut content_to_send = String::new();
write!(&mut content_to_send, "{:0<56}", "line1 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line2 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line3 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line4 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line5 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line6 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line7 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line8 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line9 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line10 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line11 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line12 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line13 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line14 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line15 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line16 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line17 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line18 ").unwrap();
write!(&mut content_to_send, "{:0<58}", "line19 ").unwrap();
write!(&mut content_to_send, "{:0<57}", "line20 ").unwrap();
remote_terminal.send_key(&BRACKETED_PASTE_START);
remote_terminal.send_key(content_to_send.as_bytes());
remote_terminal.send_key(&BRACKETED_PASTE_END);
remote_terminal.load_fixture("e2e/scrolling_inside_a_pane");
step_is_complete = true;
}
step_is_complete
@ -264,7 +238,9 @@ pub fn scrolling_inside_a_pane() {
name: "Scroll up inside pane",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(118, 20) {
if remote_terminal.cursor_position_is(63, 20)
&& remote_terminal.snapshot_contains("line21")
{
// all lines have been written to the pane
remote_terminal.send_key(&SCROLL_MODE);
remote_terminal.send_key(&SCROLL_UP_IN_SCROLL_MODE);
@ -278,10 +254,11 @@ pub fn scrolling_inside_a_pane() {
name: "Wait for scroll to finish",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(118, 20)
&& remote_terminal.snapshot_contains("line1 ")
if remote_terminal.cursor_position_is(63, 20)
&& remote_terminal.snapshot_contains("line3 ")
&& remote_terminal.snapshot_contains("SCROLL: 1/4")
{
// scrolled up one line
// keyboard scrolls up 1 line, scrollback is 4 lines: cat command + 2 extra lines from fixture + prompt
step_is_complete = true;
}
step_is_complete
@ -1076,7 +1053,6 @@ pub fn scrolling_inside_a_pane_with_mouse() {
let last_snapshot = loop {
RemoteRunner::kill_running_sessions(fake_win_size);
let mut runner = RemoteRunner::new(fake_win_size)
.retry_pause_ms(1000) // we need a longer retry period here because it takes some time to fill the pty buffer
.add_step(Step {
name: "Split pane to the right",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
@ -1096,27 +1072,7 @@ pub fn scrolling_inside_a_pane_with_mouse() {
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(63, 2) && remote_terminal.tip_appears() {
// cursor is in the newly opened second pane
remote_terminal.send_key(format!("{:0<56}", "line1 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line2 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line3 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line4 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line5 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line6 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line7 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line8 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line9 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line10 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line11 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line12 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line13 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line14 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line15 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line16 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line17 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line18 ").as_bytes());
remote_terminal.send_key(format!("{:0<58}", "line19 ").as_bytes());
remote_terminal.send_key(format!("{:0<57}", "line20 ").as_bytes());
remote_terminal.load_fixture("e2e/scrolling_inside_a_pane");
step_is_complete = true;
}
step_is_complete
@ -1126,7 +1082,9 @@ pub fn scrolling_inside_a_pane_with_mouse() {
name: "Scroll up inside pane",
instruction: |mut remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(118, 20) {
if remote_terminal.cursor_position_is(63, 20)
&& remote_terminal.snapshot_contains("line21")
{
// all lines have been written to the pane
remote_terminal.send_key(&sgr_mouse_report(Position::new(2, 64), 64));
step_is_complete = true;
@ -1139,10 +1097,11 @@ pub fn scrolling_inside_a_pane_with_mouse() {
name: "Wait for scroll to finish",
instruction: |remote_terminal: RemoteTerminal| -> bool {
let mut step_is_complete = false;
if remote_terminal.cursor_position_is(118, 20)
if remote_terminal.cursor_position_is(63, 20)
&& remote_terminal.snapshot_contains("line1 ")
&& remote_terminal.snapshot_contains("SCROLL: 3/4")
{
// scrolled up one line
// mouse wheel scrolls up 3 lines, scrollback is 4 lines: cat command + 2 extra lines from fixture + prompt
step_is_complete = true;
}
step_is_complete

View file

@ -20,6 +20,7 @@ const ZELLIJ_EXECUTABLE_LOCATION: &str = "/usr/src/zellij/x86_64-unknown-linux-m
const SET_ENV_VARIABLES: &str = "EDITOR=/usr/bin/vi";
const ZELLIJ_LAYOUT_PATH: &str = "/usr/src/zellij/fixtures/layouts";
const ZELLIJ_DATA_DIR: &str = "/usr/src/zellij/e2e-data";
const ZELLIJ_FIXTURE_PATH: &str = "/usr/src/zellij/fixtures";
const CONNECTION_STRING: &str = "127.0.0.1:2222";
const CONNECTION_USERNAME: &str = "test";
const CONNECTION_PASSWORD: &str = "test";
@ -323,6 +324,13 @@ impl RemoteTerminal {
.unwrap();
channel.flush().unwrap();
}
pub fn load_fixture(&mut self, name: &str) {
let mut channel = self.channel.lock().unwrap();
channel
.write_all(format!("cat {ZELLIJ_FIXTURE_PATH}/{name}\n").as_bytes())
.unwrap();
channel.flush().unwrap();
}
}
#[derive(Clone)]
@ -568,6 +576,7 @@ impl RemoteRunner {
self.panic_on_no_retries_left = false;
self
}
#[allow(unused)]
pub fn retry_pause_ms(mut self, retry_pause_ms: usize) -> Self {
self.retry_pause_ms = retry_pause_ms;
self

View file

@ -1,29 +1,29 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 295
assertion_line: 276
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1 
┌ Pane #1 ─────────────────────────────────────────────────┐┌ Pane #2 ─────────────────────────────────── SCROLL: 1/1
│$ ││$ line1 00000000000000000000000000000000000000000000000000
│ ││line2 0000000000000000000000000000000000000000000000000000
│ ││line3 0000000000000000000000000000000000000000000000000000
│ ││line4 0000000000000000000000000000000000000000000000000000
│ ││line5 0000000000000000000000000000000000000000000000000000
│ ││line6 0000000000000000000000000000000000000000000000000000
│ ││line7 0000000000000000000000000000000000000000000000000000
│ ││line8 0000000000000000000000000000000000000000000000000000
│ ││line9 0000000000000000000000000000000000000000000000000000
│ ││line10 000000000000000000000000000000000000000000000000000
│ ││line11 000000000000000000000000000000000000000000000000000
│ ││line12 000000000000000000000000000000000000000000000000000
│ ││line13 000000000000000000000000000000000000000000000000000
│ ││line14 000000000000000000000000000000000000000000000000000
│ ││line15 000000000000000000000000000000000000000000000000000
│ ││line16 000000000000000000000000000000000000000000000000000
│ ││line17 000000000000000000000000000000000000000000000000000
│ ││line18 000000000000000000000000000000000000000000000000000
│ ││line19 00000000000000000000000000000000000000000000000000█
┌ Pane #1 ─────────────────────────────────────────────────┐┌ Pane #2 ─────────────────────────────────── SCROLL: 1/4
│$ ││line3
│ ││line4
│ ││line5
│ ││line6
│ ││line7
│ ││line8
│ ││line9
│ ││line10
│ ││line11
│ ││line12
│ ││line13
│ ││line14
│ ││line15
│ ││line16
│ ││line17
│ ││line18
│ ││line19
│ ││line20
│ ││li█e21
└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SCROLL  <o> SESSION  <q> QUIT 
<↓↑> Scroll / <PgDn/PgUp> Scroll / <d/u> Scroll / <e> Edit / <ENTER> Select pane

View file

@ -1,29 +1,29 @@
---
source: src/tests/e2e/cases.rs
assertion_line: 1154
assertion_line: 1141
expression: last_snapshot
---
Zellij (e2e-test)  Tab #1 
┌ Pane #1 ─────────────────────────────────────────────────┐┌ Pane #2 ─────────────────────────────────── SCROLL: 1/1
│$ ││$ line1 00000000000000000000000000000000000000000000000000
│ ││line2 0000000000000000000000000000000000000000000000000000
│ ││line3 0000000000000000000000000000000000000000000000000000
│ ││line4 0000000000000000000000000000000000000000000000000000
│ ││line5 0000000000000000000000000000000000000000000000000000
│ ││line6 0000000000000000000000000000000000000000000000000000
│ ││line7 0000000000000000000000000000000000000000000000000000
│ ││line8 0000000000000000000000000000000000000000000000000000
│ ││line9 0000000000000000000000000000000000000000000000000000
│ ││line10 000000000000000000000000000000000000000000000000000
│ ││line11 000000000000000000000000000000000000000000000000000
│ ││line12 000000000000000000000000000000000000000000000000000
│ ││line13 000000000000000000000000000000000000000000000000000
│ ││line14 000000000000000000000000000000000000000000000000000
│ ││line15 000000000000000000000000000000000000000000000000000
│ ││line16 000000000000000000000000000000000000000000000000000
│ ││line17 000000000000000000000000000000000000000000000000000
│ ││line18 000000000000000000000000000000000000000000000000000
│ ││line19 00000000000000000000000000000000000000000000000000█
┌ Pane #1 ─────────────────────────────────────────────────┐┌ Pane #2 ─────────────────────────────────── SCROLL: 3/4
│$ ││line1
│ ││line2
│ ││line3
│ ││line4
│ ││line5
│ ││line6
│ ││line7
│ ││line8
│ ││line9
│ ││line10
│ ││line11
│ ││line12
│ ││line13
│ ││line14
│ ││line15
│ ││line16
│ ││line17
│ ││line18
│ ││li█e19
└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SCROLL  <o> SESSION  <q> QUIT 
Tip: Alt + <n> => new pane. Alt + <←↓↑→ or hjkl> => navigate. Alt + <+-> => resize pane.

View file

@ -0,0 +1,21 @@
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
line11
line12
line13
line14
line15
line16
line17
line18
line19
line20
line21

View file

@ -55,10 +55,21 @@ pub(crate) fn get_terminal_size_using_fd(fd: RawFd) -> Size {
unsafe {
ioctl(fd, TIOCGWINSZ.into(), &mut winsize)
};
Size {
rows: winsize.ws_row as usize,
cols: winsize.ws_col as usize,
}
// fallback to default values when rows/cols == 0: https://github.com/zellij-org/zellij/issues/1551
let rows = if winsize.ws_row != 0 {
winsize.ws_row as usize
} else {
24
};
let cols = if winsize.ws_col != 0 {
winsize.ws_col as usize
} else {
80
};
Size { rows, cols }
}
#[derive(Clone)]