libtmux Reference MCP Search

Rust

Rust

Drive a real tmux from Rust.

libtmux

Install

$ cargo add libtmux

Quickstart

use libtmux::test::TestServer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Runs for real. `TestServer` is an isolated tmux on its own socket under
// `/tmp/libtmux-rs-test/`, torn down at the end. Your own code says
// `let server = libtmux::Server::new()?;` instead; nothing else changes.
let guard = TestServer::new().await?;
let server = guard.server();
let session = server.new_session("work").await?;
let window = session.new_window("editor").await?;
let pane = window.active_pane().await?.expect("a window has a pane");
pane.send_line("echo hello").await?;
for line in pane.capture().await? {
println!("{}", line.to_string_lossy());
}
guard.shutdown().await?;
Ok(())
}

The crate README's own "Drive tmux" section, verbatim — doctested in full via #![doc = include_str!("../README.md")], so `cargo test --doc` compiles and runs this exact block against a throwaway tmux.

API References

Read on

Esc

Type to search.