From 831d26156eda9d8de24347d6f0d9751127580533 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 17 Feb 2021 15:55:38 +0100 Subject: [PATCH] fix(compatibility): get top not to break everything when exiting (#188) --- src/client/panes/grid.rs | 14 ++-- src/tests/fixtures/top_and_quit | Bin 0 -> 15909 bytes src/tests/integration/basic.rs | 1 + src/tests/integration/compatibility.rs | 23 +++++++ ...egration__compatibility__top_and_quit.snap | 61 ++++++++++++++++++ src/tests/utils.rs | 2 + 6 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 src/tests/fixtures/top_and_quit create mode 100644 src/tests/integration/snapshots/zellij__tests__integration__compatibility__top_and_quit.snap diff --git a/src/client/panes/grid.rs b/src/client/panes/grid.rs index 062b5c3a..6dfc3140 100644 --- a/src/client/panes/grid.rs +++ b/src/client/panes/grid.rs @@ -164,7 +164,7 @@ impl Grid { pub fn new(rows: usize, columns: usize) -> Self { Grid { lines_above: vec![], - viewport: vec![], + viewport: vec![Row::new().canonical()], lines_below: vec![], cursor: Cursor::new(0, 0), scroll_region: None, @@ -553,14 +553,14 @@ impl Grid { } } fn pad_lines_until(&mut self, position: usize) { - for _ in self.viewport.len()..position { + for _ in self.viewport.len()..=position { self.viewport.push(Row::new().canonical()); } } pub fn move_cursor_to(&mut self, x: usize, y: usize) { - self.cursor.x = x; - self.cursor.y = y; - self.pad_lines_until(self.cursor.y + 1); + self.cursor.x = std::cmp::min(self.width - 1, x); + self.cursor.y = std::cmp::min(self.height - 1, y); + self.pad_lines_until(self.cursor.y); self.pad_current_line_until(self.cursor.x); } pub fn move_cursor_up(&mut self, count: usize) { @@ -664,8 +664,8 @@ impl Grid { self.pad_current_line_until(self.cursor.x); } pub fn move_cursor_to_line(&mut self, line: usize) { - self.cursor.y = line; - self.pad_lines_until(self.cursor.y + 1); + self.cursor.y = std::cmp::min(self.height - 1, line); + self.pad_lines_until(self.cursor.y); self.pad_current_line_until(self.cursor.x); } pub fn replace_with_empty_chars(&mut self, count: usize, empty_char_style: CharacterStyles) { diff --git a/src/tests/fixtures/top_and_quit b/src/tests/fixtures/top_and_quit new file mode 100644 index 0000000000000000000000000000000000000000..4b710cc6ba9b10b0051b11a89acab640d1f8187f GIT binary patch literal 15909 zcmd^`-EP}96o7rVqClR&H@qp(VX-WV`gO1ss~aF$;jT#9^&%JyS*C5xlBG&=()3~v zumRg^>~8PWC)uGSr?jk?wmfVMDj;$s9Z@_V&mV2E{j+*9@zWXV&Z3ZZ-NX&MUNolN zk2DDUU%qNz5&OhAQN#9C*naxFJk*F4e){u|;vD*7wj{$L8(;(zF5QCwd6^w-~T>1F#0demRZ=xT^bPgQ%mU5LSh zHO=a?53AqG+E>_dc9OP1YIoU3We1#a{Sj4@+txq34}5b<8i+AHv16_J+N>cbjJPJ7 zx5$uThatJ^-@TZfJ2jlJ@e>IfQcitFNn^xYqH^teQ@ z8V|TTcZnc(3FyF%G3coMExXfz`>xKwIDaV2l{L^og{FpvmNCLwPsPUwVYEzX0{;Y& zJ4Ws`_~w-M5LSqN%=QM`o49BOI_aF~4)|Khp*(td^!SaN&eLA?0uB*2Y_xtli!wJj zUO&e$L#V_R(PX(;_={ zntok}LDLnj(t~AM`*6Tr5lnAu1y!Z0)55P4v^F2@*XzC6;*DF^BH9$3)jqmLFx^=Y zLf$&z^&>F4f&Uy0Xo%{7gW*}&P^uQS#rP~$#fn~GKS?O9MSwJH5~XT`;7s*sk!k3T z;#686Ehm$%=Xx`-Z82RhZ``8e!6h`BM=Y}HY! zZtq^Zevl7W^`4D!h5XARqQyc2dVT%^y}dlWVE@Are7-to|NV4+@rHd~oL;hz%d-mv z|2*lxehd4->42R?Z_Wp&-=O}FgTeQ&UgT$F-BqFF1Q;3MY1qU@to$rGuc`2Ei`EZ@ds(jh6Eet?A%i3f>uw|R3iiiq@r3RW4jhKu9G9f+z z69_xNsR!}L*3dgTLj4Ge@P)i2wlQD|p(KjR-j}|Buw@WnfG{?gIUw6`3I-KBFce2c z>1~?Pa13JdZUP2c4TD@6X7#Y$eK0#%F~~gvrZI|&(L9?a)E!F=LBN1;3_#&dZVPM5 zvje!o^2H_t6(!zsIE`~5X?Fq!`oF;-b`z;N2pE`$GML{)$($x#wWpqS=A$6;=F<6v zfPsA|gD@P%H1Xo)@aDa&&LCjma12&?Ay?%t7?wvhF%c`8j^=4J$^7K~xLe*KA&Bh^ zFa)(cH?~;UJ1i5fRM`On#K=4-dJ^l;^s3CF%IQK;EW=gI7YJJ!)FcK|fm)g+h8Sjk zVf;{wB&Nh&k+hXTjWew5VD!N4fG-ddHj?}K0!E=fP29|n77~LH1O%=?=otBAh&d2! zyT${59MGY^_=S3zv=jsk_yS?y#E|;}q{Ue*t@g!u3K&>iJUD;>vmkjl0Ryf`I@}jz zB_UwI7fJiaL}G9;QC0$?`T)%T@Z9KiQumkQ(l*1E)tRw^s_#$cl#Gn%{F~~|llo$wKBsEVA@~WS^qreWhBB@DU zP`L?%ydVS&_yXaeyZ|qgKGeK$SbYF_VLqnUSr|`JS&~3aKLmEbe~Hq_4i+?9$gDp@ zvYi3Ecy!>zk^RV$vDZe2`MU@;qwxQq5->QpMw+|Jv7brzWAhq#0Ruia?mu5(@nE)G zOqn4_j6uNQu-pg?q9`1~>p1WW{2F?x4g?JNFAy5V#GAy==*acvQfa;3836;nK4|6( zuyQ7b)iLAMq FakeInputOutput { diff --git a/src/tests/integration/compatibility.rs b/src/tests/integration/compatibility.rs index 37149bc9..213d2bbb 100644 --- a/src/tests/integration/compatibility.rs +++ b/src/tests/integration/compatibility.rs @@ -484,3 +484,26 @@ pub fn emacs_longbuf() { get_next_to_last_snapshot(snapshots).expect("could not find snapshot"); assert_snapshot!(snapshot_before_quit); } + +#[test] +pub fn top_and_quit() { + let fake_win_size = PositionAndSize { + columns: 235, + rows: 56, + x: 0, + y: 0, + }; + let fixture_name = "top_and_quit"; + let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name); + fake_input_output.add_terminal_input(&[&COMMAND_TOGGLE, &QUIT]); + start(Box::new(fake_input_output.clone()), CliArgs::default()); + let output_frames = fake_input_output + .stdout_writer + .output_frames + .lock() + .unwrap(); + let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size); + let snapshot_before_quit = + get_next_to_last_snapshot(snapshots).expect("could not find snapshot"); + assert_snapshot!(snapshot_before_quit); +} diff --git a/src/tests/integration/snapshots/zellij__tests__integration__compatibility__top_and_quit.snap b/src/tests/integration/snapshots/zellij__tests__integration__compatibility__top_and_quit.snap new file mode 100644 index 00000000..1c4e16df --- /dev/null +++ b/src/tests/integration/snapshots/zellij__tests__integration__compatibility__top_and_quit.snap @@ -0,0 +1,61 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot_before_quit + +--- +Tasks: 158 total, 1 running, 157 sleeping, 0 stopped, 0 zombie +%Cpu(s): 24.2 us, 1.6 sy, 0.0 ni, 74.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st +MiB Mem : 15715.1 total, 7001.4 free, 2163.7 used, 6549.9 buff/cache +MiB Swap: 16384.0 total, 16384.0 free, 0.0 used. 12809.8 avail Mem + + PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND + 15838 aram 20 0 7275240 56912 18964 S 73.3 0.4 0:17.79 zellij + 12653 aram 20 0 39032 22164 14372 S 20.0 0.1 0:00.63 urxvt + 1477 aram 20 0 3178660 301992 203236 S 6.7 1.9 3:49.82 Web Content + 1 root 20 0 175360 11532 8596 S 0.0 0.1 0:05.90 systemd + 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd + 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp + 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp + 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kblockd + 8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq + 9 root 20 0 0 0 0 S 0.0 0.0 0:01.24 ksoftirqd/0 + 10 root -2 0 0 0 0 S 0.0 0.0 0:00.00 rcuc/0 + 11 root -2 0 0 0 0 I 0.0 0.0 0:06.12 rcu_preempt + 12 root -2 0 0 0 0 S 0.0 0.0 0:00.00 rcub/0 + 13 root rt 0 0 0 0 S 0.0 0.0 0:00.01 migration/0 + 14 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/0 + 16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 + 17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1 + 18 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/1 + 19 root rt 0 0 0 0 S 0.0 0.0 0:00.35 migration/1 + 20 root -2 0 0 0 0 S 0.0 0.0 0:00.00 rcuc/1 + 21 root 20 0 0 0 0 S 0.0 0.0 0:00.49 ksoftirqd/1 + 23 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/1:0H-kblockd + 24 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/2 + 25 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/2 + 26 root rt 0 0 0 0 S 0.0 0.0 0:00.39 migration/2 + 27 root -2 0 0 0 0 S 0.0 0.0 0:00.00 rcuc/2 + 28 root 20 0 0 0 0 S 0.0 0.0 0:00.99 ksoftirqd/2 + 30 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/2:0H-kblockd + 31 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/3 + 32 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/3 + 33 root rt 0 0 0 0 S 0.0 0.0 0:00.43 migration/3 + 34 root -2 0 0 0 0 S 0.0 0.0 0:00.00 rcuc/3 + 35 root 20 0 0 0 0 S 0.0 0.0 0:00.90 ksoftirqd/3 + 37 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/3:0H-kblockd + 38 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs + 39 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns + 40 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_kthre + 41 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kauditd + 44 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd + 45 root 20 0 0 0 0 S 0.0 0.0 0:00.00 oom_reaper + 46 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 writeback + 47 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kcompactd0 + 48 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd + 49 root 39 19 0 0 0 S 0.0 0.0 0:00.00 khugepaged + 137 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kintegrityd + 138 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kblockd + 139 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 blkcg_punt_bio + 140 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 ata_sff + 141 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 edac-poller +⋊> ~/c/zellij on fix-top ⨯ █ 13:00:53 diff --git a/src/tests/utils.rs b/src/tests/utils.rs index 587d36fd..08c87cbf 100644 --- a/src/tests/utils.rs +++ b/src/tests/utils.rs @@ -1,6 +1,8 @@ use crate::panes::PositionAndSize; use crate::panes::TerminalPane; +use crate::utils::logging::debug_log_to_file; + pub fn get_output_frame_snapshots( output_frames: &[Vec], win_size: &PositionAndSize,