Core LibrarystableAPI Reference

Choose documentation 3

stable

Current version

stable
English

Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

function libtmux stable

_best_winlink

Pick the winlink row tmux would select.

Source and package
Qualified name
libtmux.neo._best_winlink
Module
libtmux.neo
Package
libtmux
Source
src/libtmux/neo.py

Description#

A list-windows listing enumerates winlinks -- (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.

Examples#

One row is the whole answer:

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

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:

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

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

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

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:

>>> _best_winlink([
... {"window_id": "@0", "window_index": "5", "window_active": "0"},
... {"window_id": "@0", "window_index": "1", "window_active": "0"},
... ])["window_index"]
'1'
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.

Esc

Type to search.

Reference preview Open reference