# `LibTmux.Window`
[🔗](https://github.com/libtmux/libtmux-elixir/blob/86ad4ca80f157adb0c11f6bf7c371b04ca5aa688/lib/libtmux/entities.ex#L217)

An immutable physical window with explicit actions, independent of session membership and index.

## What is on here

A Window is a physical window captured in a `LibTmux.Snapshot`. Its session
index and active state belong to a `LibTmux.WindowLink`, so one Window can
belong to several sessions. Start with these groups:

**Finding the window.** Select windows from a captured snapshot, or look one
up by its exact ID. Neither contacts tmux. An ID that was not captured returns
`{:error, error}` with kind `:not_found`. Turn the window into a reference
tied to the server incarnation that supplied it, ready for an action.

- Select: `LibTmux.Snapshot.windows/1`
- By ID: `LibTmux.Snapshot.fetch/3`
- Reference: `LibTmux.Ref.from_observation/1`

**Looking inside a window.** Read its panes from the snapshot, in numeric
pane-ID order and without I/O. An invalid or stale identity, or a relationship
the snapshot did not capture, raises `LibTmux.Error`. To find the sessions
that hold the window, select its links.

- Panes: `panes/2`
- Links: `LibTmux.Snapshot.window_links/1`

**Renaming.** Rename the window across all its memberships through a Server or
a Control connection. A name holds 1..1024 UTF-8 bytes with no control
characters, and tmux still normalizes it. The optional `session:` reference
requires membership in that session; it does not pick a link index.

- Rename: `rename/4`
- Raise on failure: `rename!/4`

**Killing.** Kill the window, with its panes, in every session that links it,
through a Server. A Control connection returns `unsupported_transport`.

- Kill: `kill/3`
- Raise on failure: `kill!/3`

# `t`

```elixir
@type t() :: %LibTmux.Window{
  height: LibTmux.Schema.observed(non_neg_integer()),
  id: String.t(),
  layout: LibTmux.Schema.observed(String.t()),
  name: LibTmux.Schema.observed(String.t()),
  server_instance: String.t(),
  width: LibTmux.Schema.observed(non_neg_integer()),
  zoomed: LibTmux.Schema.observed(boolean())
}
```

A physical window; session index and active-window state belong to a WindowLink.

# `kill`

```elixir
@spec kill(LibTmux.Server.t(), LibTmux.Ref.t(), [LibTmux.Action.option()]) ::
  {:ok, LibTmux.Action.result(:ok)} | {:error, LibTmux.Action.error()}
```

Kills an exact window through one-shot execution.

Returns `{:ok, result}` on command completion. Optional `session: session_ref` requires membership in that exact session and `timeout` defaults to 5000ms. Killing a window removes it from every session that links it. The reference is
checked against the answering server before dispatch, with the usual one-shot
check/use race. A reference to something that is already gone returns
`{:error, %LibTmux.Action.CompletionError{}}` with the original evidence.
Control connections return `unsupported_transport` before any I/O: a
connection cannot kill what it is attached to. Observations you already hold
keep describing the window.

    alias LibTmux.Window

    Window.kill(server, window_ref)

# `kill!`

```elixir
@spec kill!(LibTmux.Server.t(), LibTmux.Ref.t(), [LibTmux.Action.option()]) :: :ok
```

Returns `:ok` when `kill/3` completes; raises API errors or `LibTmux.Action.CompletionError` otherwise.

# `panes`

```elixir
@spec panes(LibTmux.Snapshot.t(), t()) :: LibTmux.Selection.t(LibTmux.Pane.t())
```

Returns a selection of captured physical panes in numeric pane-ID order.

Uses the supplied snapshot and validates the window's ID and incarnation.
Identity, coverage, empty-selection and no-I/O behavior follow
`LibTmux.Session.windows/2`.

## Examples

    iex> alias LibTmux.{Selection, Snapshot, Window}
    iex> rows = %{window: [%{id: "@0"}], pane: [
    ...>   %{id: "%10", window_id: "@0"}, %{id: "%2", window_id: "@0"}]}
    iex> {:ok, snapshot} = Snapshot.new(rows,
    ...>   server_instance: "example", captured_from: 0, captured_until: 0,
    ...>   complete: [:pane], fields: %{pane: [:id, :window_id]})
    iex> {:ok, window} = Snapshot.fetch(snapshot, :window, "@0")
    iex> Window.panes(snapshot, window) |> Enum.map(& &1.id)
    ["%2", "%10"]
    iex> {:ok, pane} = Window.panes(snapshot, window)
    ...> |> Selection.where(id: "%2") |> Selection.one()
    iex> pane.id
    "%2"

# `rename`

```elixir
@spec rename(LibTmux.Action.connection(), LibTmux.Ref.t(), binary(), [
  LibTmux.Action.option()
]) ::
  {:ok, LibTmux.Action.result(:ok)} | {:error, LibTmux.Action.error()}
```

Renames an exact physical window across all its memberships.

Returns `{:ok, result}` on command completion; unsuccessful outcomes return
`{:error, %LibTmux.Action.CompletionError{}}` with their original evidence.

Names contain 1..1024 UTF-8 bytes without Unicode control characters (Cc),
with literal format syntax.
tmux still applies name normalization, including dollar/backslash escaping.
Control characters fail before I/O on both transports. Optional `session: session_ref` requires
membership in that exact session; it does not select a captured link index.
`timeout` defaults to 5000ms. See `LibTmux.Action` for transport and outcomes.

    alias LibTmux.Window

    Window.rename(control, window_ref, "editor")

# `rename!`

```elixir
@spec rename!(LibTmux.Action.connection(), LibTmux.Ref.t(), binary(), [
  LibTmux.Action.option()
]) :: :ok
```

Returns `:ok` when `rename/4` completes; raises API errors or `LibTmux.Action.CompletionError` otherwise.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
