Skip to content

Commit

Permalink
tmux: capture initial screen contents
Browse files Browse the repository at this point in the history
refs: #1090
  • Loading branch information
wez committed Jan 17, 2022
1 parent 0eb1417 commit 4ebbc66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions mux/src/tmux_commands.rs
Expand Up @@ -172,6 +172,12 @@ impl TmuxDomainState {
mux.add_tab_to_window(&tab, **gui_window_id)?;
gui_window_id.notify();

self.cmd_queue
.lock()
.unwrap()
.push_back(Box::new(CapturePane(pane.pane_id)));
TmuxDomainState::schedule_send_next_command(self.domain_id);

self.add_attached_pane(&pane, &tab.tab_id())?;
log::info!("new pane attached");
}
Expand Down Expand Up @@ -264,7 +270,7 @@ impl TmuxCommand for ListAllPanes {
pub(crate) struct CapturePane(TmuxPaneId);
impl TmuxCommand for CapturePane {
fn get_command(&self) -> String {
format!("capturep -p -t {} -e -C\n", self.0)
format!("capturep -p -t %{} -e -C\n", self.0)
}

fn process_result(&self, domain_id: DomainId, result: &Guarded) -> anyhow::Result<()> {
Expand All @@ -278,11 +284,14 @@ impl TmuxCommand for CapturePane {
None => anyhow::bail!("Tmux domain lost"),
};

let unescaped = termwiz::tmux_cc::unvis(&result.output).context("unescape pane content")?;
let unescaped = unescaped.replace("\n", "\r\n");

let pane_map = tmux_domain.inner.remote_panes.borrow();
if let Some(pane) = pane_map.get(&self.0) {
let mut pane = pane.lock().expect("Grant lock of tmux cmd queue failed");
pane.output_write
.write_all(result.output.as_bytes())
.write_all(unescaped.as_bytes())
.context("writing capture pane result to output")?;
}

Expand Down
2 changes: 1 addition & 1 deletion termwiz/src/tmux_cc/mod.rs
Expand Up @@ -311,7 +311,7 @@ fn parse_line(line: &str) -> anyhow::Result<Event> {

/// Decode OpenBSD `vis` encoded strings
/// See: https://github.com/tmux/tmux/blob/486ce9b09855ae30a2bf5e576cb6f7ad37792699/compat/unvis.c
fn unvis(s: &str) -> anyhow::Result<String> {
pub fn unvis(s: &str) -> anyhow::Result<String> {
enum State {
Ground,
Start,
Expand Down

0 comments on commit 4ebbc66

Please sign in to comment.