Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-rs latest

Window.set_hooks

Write a whole hook at once.

Source and package
Qualified name
libtmux::window::Window::set_hooks
Module
window
Declared in
Window
Package
libtmux
Source
crates/libtmux/src/window/settings.rs
Other languages
Perl Erlang PowerShell Julia Elixir Haskell Common Lisp Python Ruby Lua TypeScript Go Java C# C++ Swift Kotlin Scala OCaml F# Clojure
pub async fn set_hooks( &self, name: &str, hooks: &IndexedHooks, replace: ReplaceMode, ) -> Result<(), Error>

Description#

ReplaceMode::Replace clears the hook first, so only what is written remains; ReplaceMode::Merge leaves entries at indices the write does not name.

Sent as at most two tmux invocations rather than one per index: the first command alone, then the rest together. That is not atomic: tmux applies a shared invocation in order and stops at the first refusal, so a rejected entry leaves the ones before it written.

Errors

Returns an error when tmux rejects the name or any command.

Returns crate::Error::OptionScopeMismatch when tmux keeps the option in another of its tables.

Cancel safety

Under ReplaceMode::Replace the clear and the entries are one invocation, so a drop leaves the hook as it was or fully written, never cleared and unwritten; tmux reports one status for that group, so a refusal there cannot name which command drew it. Under ReplaceMode::Merge the first entry is sent on its own, so a drop after it leaves that entry written and the rest not.

Examples#

use std::collections::BTreeMap;
use libtmux::{IndexedHooks, ReplaceMode, TmuxText};
let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("hooked").await?;
let window = session.active_window().await?.expect("a window");
let mut entries = BTreeMap::new();
entries.insert(0, TmuxText::from(b"display-message first".to_vec()));
entries.insert(3, TmuxText::from(b"display-message fourth".to_vec()));
window
.set_hooks("pane-died", &IndexedHooks::from(entries), ReplaceMode::Replace)
.await?;
let written = window.hook("pane-died").await?.expect("the hook is set");
assert_eq!(written.len(), 2);
assert!(written.get(1).is_none(), "the gap is kept");
guard.shutdown().await?;

tmux command#

The tmux commands behind set_hooks.

tmux C API#

The C declarations in tmux that implement these commands.

tmux hooks#

Events that run tmux commands, with the scope each hook belongs to and where tmux fires it.

In other ports#

Write a window hook and its indexed commands at once

Equivalents of Write a window hook and its indexed commands at once in other languages
Language Equivalent
Python libtmux.Window.set_hooks
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
TypeScript no equivalent on Window
Go tmux.Window.SetHooks
Java no equivalent on Window
C# no equivalent on Window
C++ no equivalent on Window
Swift no equivalent on Window
OCaml No direct public OCaml equivalent is recorded for this operation.
Perl No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands.

No equivalent is recorded in Ruby, Lua, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Esc

Type to search.

Reference previewOpen reference