Skip to content

Commit

Permalink
feat(save): add panes to archive
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Aug 18, 2022
1 parent cb380a6 commit 70d0e9c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/actions/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ pub async fn save<P: AsRef<Path>>(backup_dirpath: P) -> Result<(PathBuf, Report)
task::spawn(async move {
let sessions = tmux::session::available_sessions().await?;
let windows = tmux::window::available_windows().await?;
let panes = tmux::pane::available_panes().await?;
let num_sessions = sessions.len() as u16;
let num_windows = windows.len() as u16;

let metadata = Metadata { sessions, windows };
let metadata = Metadata {
sessions,
windows,
panes,
};
let yaml = serde_yaml::to_string(&metadata)?;

let temp_metadata_filepath = temp_dirpath.join(METADATA_FILENAME);
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ async fn run(config: Config) {
.await
.expect("Success saving but could not compact");
}
let message = format!("✅ {report}, persisted to `{:?}`", backup_filepath);
let message = format!(
"✅ {report}, persisted to `{}`",
backup_filepath.to_string_lossy()
);
success_message(message, to_tmux);
}
Err(e) => {
Expand Down
5 changes: 4 additions & 1 deletion src/management/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub struct Metadata {

/// Tmux windows metadata.
pub windows: Vec<tmux::window::Window>,

/// Tmux panes metadata.
pub panes: Vec<tmux::pane::Pane>,
}

impl Metadata {
Expand All @@ -66,7 +69,7 @@ impl Metadata {
Report {
num_sessions: self.sessions.len() as u16,
num_windows: self.windows.len() as u16,
num_panes: 0,
num_panes: self.panes.len() as u16,
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/tmux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ pub async fn available_windows() -> Result<Vec<Window>, ParseError> {
let output = Command::new("tmux").args(&args).output().await?;
let buffer = String::from_utf8(output.stdout)?;

// Each call to `Window::parse` returns a `Result<Window, _>`. All results
// are collected into a Result<Vec<Window>, _>, thanks to `collect()`.
// Note: each call to the `Window::from_str` returns a `Result<Window, _>`.
// All results are then collected into a Result<Vec<Window>, _>, via
// `collect()`.
let result: Result<Vec<Window>, ParseError> = buffer
.trim_end() // trim last '\n' as it would create an empty line
.split('\n')
Expand Down

0 comments on commit 70d0e9c

Please sign in to comment.