# Architecture

Source: https://libtmux.org/en/cxx/latest/topics/architecture/

> Locate operations, distinguish snapshots from live commands, and find their implementation.

A server handle selects a tmux server. Object IDs select sessions, windows, and
panes within it. For the object hierarchy and stable IDs, start with [Server,
session, window, pane](https://libtmux.org/en/cxx/latest/concepts/server-session-window-pane/).

<a id="where-behavior-lives-on-the-object-or-through-the-server"></a>

## Calling operations

Session, window, and pane handles carry their ID and server context. Call an
operation on the object you want to change. The examples below send input and
kill that pane.

```cpp
pane->send_text("echo hi");
pane->kill();
```

<a id="a-generated-data-table-under-a-hand-written-surface"></a>

## Reading tmux fields

Object IDs become tmux targets (`-t`). Format variables (`#{...}`) provide
the state returned by tmux.

Handles capture a fixed set of non-optional fields. Use
[`pane->expand("#{...}")`](<https://libtmux.org/en/cxx/latest/reference/libtmux-pane-expand/>) for tokens outside those fields.
[Format-token fields](https://libtmux.org/en/cxx/latest/topics/format-tokens/) covers their interpretation.

<a id="module-layout-by-port"></a>

## Source layout

[`include/libtmux/entities.hpp`](<https://github.com/libtmux/libtmux-cxx/blob/9645e54239e040aa6f2bd6bf42c2fbe1aaf38250/include/libtmux/entities.hpp>) declares [`Session`](<https://libtmux.org/en/cxx/latest/reference/libtmux-session/>), [`Window`](<https://libtmux.org/en/cxx/latest/reference/libtmux-window/>), and [`Pane`](<https://libtmux.org/en/cxx/latest/reference/libtmux-pane/>).
Their method bodies live in [`src/`](<https://github.com/libtmux/libtmux-cxx/tree/9645e54239e040aa6f2bd6bf42c2fbe1aaf38250/src>). [`include/libtmux/server.hpp`](<https://github.com/libtmux/libtmux-cxx/blob/9645e54239e040aa6f2bd6bf42c2fbe1aaf38250/include/libtmux/server.hpp>),
[`include/libtmux/options.hpp`](<https://github.com/libtmux/libtmux-cxx/blob/9645e54239e040aa6f2bd6bf42c2fbe1aaf38250/include/libtmux/options.hpp>), and [`include/libtmux/capabilities.hpp`](<https://github.com/libtmux/libtmux-cxx/blob/9645e54239e040aa6f2bd6bf42c2fbe1aaf38250/include/libtmux/capabilities.hpp>)
define server operations, options, and capability checks.

The [`include/libtmux/testing/`](<https://github.com/libtmux/libtmux-cxx/tree/9645e54239e040aa6f2bd6bf42c2fbe1aaf38250/include/libtmux/testing>) component is separate from the library;
[Context managers](https://libtmux.org/en/cxx/latest/topics/context-managers/) explains its test-server ownership.
