Window.set_hooks
Write a whole hook at once.
Source and package
-
Description#
ReplaceMode::Replaceclears the hook first, so only what is written remains;ReplaceMode::Mergeleaves 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::OptionScopeMismatchwhen tmux keeps the option in another of its tables.Cancel safety
Under
ReplaceMode::Replacethe 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. UnderReplaceMode::Mergethe 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?;- Parameters
-
-
hooks(&IndexedHooks ) #
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
| Language | Equivalent |
|---|---|
| Python | libtmux |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | no equivalent on Window |
| Go | tmux |
| 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#.