-
-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add action to clear all buffers for a specific pane #2239
Changes from 3 commits
ebb9308
06e3cc2
6871ebe
c8c0dd7
1ecaf48
fdb0644
0bef6ef
4cadfe8
41704c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1109,7 +1109,13 @@ impl Grid { | |
Some((self.cursor.x, self.cursor.y)) | ||
} | ||
} | ||
|
||
/// Clears all buffers with text | ||
pub fn clear_screen(&mut self) { | ||
self.lines_above = Default::default(); | ||
self.lines_below = Default::default(); | ||
self.viewport = Default::default(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a conditional here so that we don't do this if |
||
} | ||
/// Dumps all lines above terminal vieport and the viewport itself to a string | ||
pub fn dump_screen(&mut self, full: bool) -> String { | ||
let viewport: String = dump_screen!(self.viewport); | ||
if !full { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,9 @@ pub trait Pane { | |
fn push_right(&mut self, count: usize); | ||
fn pull_left(&mut self, count: usize); | ||
fn pull_up(&mut self, count: usize); | ||
fn clear_screen(&mut self) { | ||
todo!(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not forgo the default implementation here? If you're concerned about plugins (our only other type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, when I was doing this specifically I was trying to understand the whole architecture of zellij, so, I'll gladly just remove it |
||
fn dump_screen(&mut self, _client_id: ClientId, _full: bool) -> String { | ||
"".to_owned() | ||
} | ||
|
@@ -2308,6 +2311,12 @@ impl Tab { | |
} | ||
Ok(()) | ||
} | ||
pub fn clear_active_terminal_screen(&mut self, client_id: ClientId) -> Result<()> { | ||
if let Some(active_pane) = self.get_active_pane_or_floating_pane_mut(client_id) { | ||
active_pane.clear_screen(); | ||
} | ||
Ok(()) | ||
} | ||
pub fn dump_active_terminal_screen( | ||
&mut self, | ||
file: Option<String>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -708,6 +708,35 @@ fn dump_screen() { | |
); | ||
} | ||
|
||
#[test] | ||
fn clear_screen() { | ||
let size = Size { | ||
cols: 121, | ||
rows: 20, | ||
}; | ||
let client_id = 1; | ||
let mut tab = create_new_tab(size, ModeInfo::default()); | ||
let map = Arc::new(Mutex::new(HashMap::new())); | ||
tab.os_api = Box::new(FakeInputOutput { | ||
file_dumps: map.clone(), | ||
..Default::default() | ||
}); | ||
let new_pane_id = PaneId::Terminal(2); | ||
tab.new_pane(new_pane_id, None, None, Some(client_id)) | ||
.unwrap(); | ||
tab.handle_pty_bytes(2, Vec::from("scratch".as_bytes())) | ||
.unwrap(); | ||
let file = "/tmp/log.sh"; | ||
tab.clear_active_terminal_screen(client_id).unwrap(); | ||
tab.dump_active_terminal_screen(Some(file.to_string()), client_id, false) | ||
.unwrap(); | ||
assert_eq!( | ||
map.lock().unwrap().get(file).unwrap(), | ||
"", | ||
"screen was cleared properly" | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
||
#[test] | ||
fn new_floating_pane() { | ||
let size = Size { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3