# server.Server.format

- **Module:** server.Server
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/server.rs#L1189
- **Page:** https://libtmux.org/en/rs/latest/reference/server-server-format/

```
server.Server.format(self, pane: Option<&Pane>, format: &str) -> Result<TmuxText, Error>
```

Expand a tmux format string and return the result.

This is `display-message -p`, whose target is a pane: the format is
evaluated against it, so `#{pane_current_command}` and the session and
window fields around it all resolve from there.

The result is [`TmuxText`] because a format can interpolate names that
are not valid UTF-8.

A literal `#(command)` starts `command` in a shell. Recursive expansion,
such as `#{E:status-left}`, can also expose a command stored in the
expanded value. The job is asynchronous, so this call may return before
it produces output. Escaping the outer template with `##` does not
escape text introduced by a recursive expansion. Use only validated,
simple `#{field}` lookups with untrusted input.

A `%` in the template is a time conversion, not literal text. tmux
expands this command through `strftime` before it expands `#{}` -- it
calls `format_expand_time` here and plain `format_expand` for every
listing -- so `%Y` becomes the year. Write `%%` for a literal `%`.

A `%` followed by something `strftime` does not define is worse than
surprising: it is not portable. glibc keeps both characters, so the
template survives; Apple's libc emits the conversion character alone
and deletes the `%`. So a template separating fields with `%` reads
back correctly on Linux and comes back unframed on macOS. Separate
fields with a byte that is not `%`.

# Errors

Returns [`Error::ServerMismatch`] when the pane belongs to another
server, or an error when tmux rejects the format or the pane is gone.
