fix(compatibility): get top not to break everything when exiting (#188)

This commit is contained in:
Aram Drevekenin 2021-02-17 15:55:38 +01:00 committed by GitHub
parent 6e5607ba26
commit 831d26156e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 7 deletions

View file

@ -164,7 +164,7 @@ impl Grid {
pub fn new(rows: usize, columns: usize) -> Self { pub fn new(rows: usize, columns: usize) -> Self {
Grid { Grid {
lines_above: vec![], lines_above: vec![],
viewport: vec![], viewport: vec![Row::new().canonical()],
lines_below: vec![], lines_below: vec![],
cursor: Cursor::new(0, 0), cursor: Cursor::new(0, 0),
scroll_region: None, scroll_region: None,
@ -553,14 +553,14 @@ impl Grid {
} }
} }
fn pad_lines_until(&mut self, position: usize) { 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()); self.viewport.push(Row::new().canonical());
} }
} }
pub fn move_cursor_to(&mut self, x: usize, y: usize) { pub fn move_cursor_to(&mut self, x: usize, y: usize) {
self.cursor.x = x; self.cursor.x = std::cmp::min(self.width - 1, x);
self.cursor.y = y; self.cursor.y = std::cmp::min(self.height - 1, y);
self.pad_lines_until(self.cursor.y + 1); self.pad_lines_until(self.cursor.y);
self.pad_current_line_until(self.cursor.x); self.pad_current_line_until(self.cursor.x);
} }
pub fn move_cursor_up(&mut self, count: usize) { pub fn move_cursor_up(&mut self, count: usize) {
@ -664,8 +664,8 @@ impl Grid {
self.pad_current_line_until(self.cursor.x); self.pad_current_line_until(self.cursor.x);
} }
pub fn move_cursor_to_line(&mut self, line: usize) { pub fn move_cursor_to_line(&mut self, line: usize) {
self.cursor.y = line; self.cursor.y = std::cmp::min(self.height - 1, line);
self.pad_lines_until(self.cursor.y + 1); self.pad_lines_until(self.cursor.y);
self.pad_current_line_until(self.cursor.x); self.pad_current_line_until(self.cursor.x);
} }
pub fn replace_with_empty_chars(&mut self, count: usize, empty_char_style: CharacterStyles) { pub fn replace_with_empty_chars(&mut self, count: usize, empty_char_style: CharacterStyles) {

BIN
src/tests/fixtures/top_and_quit vendored Normal file

Binary file not shown.

View file

@ -8,6 +8,7 @@ use crate::tests::utils::commands::{
SPLIT_RIGHT_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE,
}; };
use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots};
use crate::utils::logging::debug_log_to_file;
use crate::{start, CliArgs}; use crate::{start, CliArgs};
fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput {

View file

@ -484,3 +484,26 @@ pub fn emacs_longbuf() {
get_next_to_last_snapshot(snapshots).expect("could not find snapshot"); get_next_to_last_snapshot(snapshots).expect("could not find snapshot");
assert_snapshot!(snapshot_before_quit); 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);
}

View file

@ -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

View file

@ -1,6 +1,8 @@
use crate::panes::PositionAndSize; use crate::panes::PositionAndSize;
use crate::panes::TerminalPane; use crate::panes::TerminalPane;
use crate::utils::logging::debug_log_to_file;
pub fn get_output_frame_snapshots( pub fn get_output_frame_snapshots(
output_frames: &[Vec<u8>], output_frames: &[Vec<u8>],
win_size: &PositionAndSize, win_size: &PositionAndSize,