Skip to content

Commit

Permalink
feat(restore): WIP prepare for creating panes
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Aug 18, 2022
1 parent aa9661b commit 117279b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
- restore windows
- restore panes
- add `restore --attach` to automatically attach if running from the terminal
- in `restore()` gather the true metadata for displaying the overview, instead
of the metadata from the archive
12 changes: 8 additions & 4 deletions src/actions/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn restore<P: AsRef<Path>>(backup_filepath: P) -> Result<v1::Overview>
}

let session = session.clone();
let related_windows: Vec<_> = metadata.windows_related_to(&session);
let related_windows = metadata.windows_related_to(&session);

let handle = task::spawn(async move { restore_session(session, related_windows).await });
handles.push(handle);
Expand All @@ -47,11 +47,13 @@ pub async fn restore<P: AsRef<Path>>(backup_filepath: P) -> Result<v1::Overview>
Ok(metadata.overview())
}

/// Create the session and its windows.
/// Create the session along with its windows and panes.
///
/// The name of the session's first window is taken from the first `Window`. The remainder of
/// windows are created in sequence, to preserve the order from the backup.
/// The session is created with the first window in order to give it the right name. The remainder
/// of windows are created in sequence, to preserve the order from the backup.
async fn restore_session(session: Session, windows: Vec<Window>) -> Result<(), ParseError> {
// 1. Create the session and the windows (each has one empty pane).

// A session is guaranteed to have at least one window.
let first_window_name = windows.first().unwrap().name.as_str();
tmux::session::new_session(&session, first_window_name).await?;
Expand All @@ -60,5 +62,7 @@ async fn restore_session(session: Session, windows: Vec<Window>) -> Result<(), P
tmux::window::new_window(window, session.dirpath.as_path(), &session.name).await?;
}

// 2. Create panes in each window.

Ok(())
}

0 comments on commit 117279b

Please sign in to comment.