diff options
author | Cosmin Popescu <cosminadrianpopescu@gmail.com> | 2022-05-20 11:22:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 11:22:40 +0200 |
commit | 76d871294d0b156afaad50360e6ba4176dc918e4 (patch) | |
tree | da996fb11e785bf0a8365b1918c2f67a1e7ef7a2 /zellij-server/src/os_input_output.rs | |
parent | e663ef2db760bdc05694b1053702bdc22c4f9d08 (diff) |
feat(actions): dump the terminal screen into a file (#1375)
* Initial commit for fixing #1353
* adding a new line between the lines_above and the viewport
* changes following code review
* implementing a test case for the dump screen
* implemented test case for dump_screen
* better regexp replace
* fixes following code review
* style(api): remove extraneous method in plugin pane
* style(fmt): rustfmt
* style(tests): fix method name
Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'zellij-server/src/os_input_output.rs')
-rw-r--r-- | zellij-server/src/os_input_output.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 7905a6e3e..1e43e47fa 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -1,6 +1,8 @@ use std::collections::HashMap; +use std::{fs::File, io::Write}; use crate::panes::PaneId; +use zellij_utils::tempfile::tempfile; use std::env; use std::os::unix::io::RawFd; @@ -268,6 +270,8 @@ pub trait ServerOsApi: Send + Sync { fn load_palette(&self) -> Palette; /// Returns the current working directory for a given pid fn get_cwd(&self, pid: Pid) -> Option<PathBuf>; + /// Writes the given buffer to a string + fn write_to_file(&mut self, buf: String, file: Option<String>); } impl ServerOsApi for ServerOsInputOutput { @@ -345,6 +349,16 @@ impl ServerOsApi for ServerOsInputOutput { } None } + fn write_to_file(&mut self, buf: String, name: Option<String>) { + let mut f: File; + match name { + Some(x) => f = File::create(x).unwrap(), + None => f = tempfile().unwrap(), + } + if let Err(e) = write!(f, "{}", buf) { + log::error!("could not write to file: {}", e); + } + } } impl Clone for Box<dyn ServerOsApi> { |