# libtmux.neo._best_winlink

- **Module:** libtmux.neo
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/neo.py#L1204
- **Page:** https://libtmux.org/reference/py/libtmux-neo-_best_winlink/

```
libtmux.neo._best_winlink(rows: OutputsRaw) -> OutputRaw
```

Pick the winlink row tmux would select.

A ``list-windows`` listing enumerates :term:`winlinks <winlink>` --
``(session, index, window)`` edges -- not windows. ``link-window`` can attach
one window to a session at several indexes at once, so the same
``window_id`` may appear on several rows, each with a different
``window_index``.

tmux selects the current winlink when it contains the window, otherwise the
first. ``#{window_active}`` identifies the current row, and the lowest
``window_index`` is tmux's first -- chosen explicitly here, so the caller
need not pre-sort the rows.

## Parameters

- `rows` (OutputsRaw) — Non-empty rows for one object id in one session. Order does not
matter: the current winlink wins, otherwise the lowest
``window_index``.

## Returns

OutputRaw
    The row naming the winlink tmux would act on.

## Example

One row is the whole answer:

```python
>>> from libtmux.neo import _best_winlink
>>> _best_winlink([{"window_id": "@0", "window_index": "1"}])["window_index"]
'1'
```

## Example

A window linked into one session twice gives two rows. When the session is sitting on the higher-indexed link, that is the one tmux acts on:

```python
>>> _best_winlink([
...     {"window_id": "@0", "window_index": "1", "window_active": "0"},
...     {"window_id": "@0", "window_index": "5", "window_active": "1"},
... ])["window_index"]
'5'
```

## Example

When the session is sitting on some *other* window, neither link is current, and tmux falls back to the first:

```python
>>> _best_winlink([
...     {"window_id": "@0", "window_index": "1", "window_active": "0"},
...     {"window_id": "@0", "window_index": "5", "window_active": "0"},
... ])["window_index"]
'1'
```

## Example

The fallback reads the lowest index, not the first row, so a listing that happened to arrive high-index-first still answers tmux's first:

```python
>>> _best_winlink([
...     {"window_id": "@0", "window_index": "5", "window_active": "0"},
...     {"window_id": "@0", "window_index": "1", "window_active": "0"},
... ])["window_index"]
'1'
```
