| 1 | (floating-panes)= |
| 2 | |
| 3 | # Floating panes |
| 4 | |
| 5 | You can create floating panes — non-modal panes that hover above the tiled |
| 6 | layout like a popup, but with full escape-sequence support and all the regular |
| 7 | pane operations (capture, send-keys, and so on). You create them with |
| 8 | {meth}`Window.new_pane() <libtmux.Window.new_pane>` or |
| 9 | {meth}`Pane.new_pane() <libtmux.Pane.new_pane>`, the same way you reach for |
| 10 | {meth}`Window.split() <libtmux.Window.split>` to add a tiled pane. |
| 11 | |
| 12 | Most workflows never need one — tiled panes cover the everyday cases, and you |
| 13 | can stop reading here unless you want a transient overlay (a quick log tail, a |
| 14 | scratch shell, a status readout) sitting on top of your layout without |
| 15 | rearranging it. Because a floating pane behaves like any other |
| 16 | {class}`~libtmux.Pane`, everything you already do — capturing output, sending |
| 17 | keys, querying state — works on it unchanged. |
| 18 | |
| 19 | ```{note} |
| 20 | Floating panes require **tmux 3.7+** |
| 21 | ({meth}`Window.new_pane() <libtmux.Window.new_pane>` / |
| 22 | {meth}`Pane.new_pane() <libtmux.Pane.new_pane>` raise |
| 23 | {exc}`~libtmux.exc.LibTmuxException` on older tmux). |
| 24 | ``` |
| 25 | |
| 26 | ## Creating a floating pane |
| 27 | |
| 28 | When you call {meth}`Window.new_pane() <libtmux.Window.new_pane>`, you get back |
| 29 | the new {class}`~libtmux.Pane`, exactly as {meth}`Window.split() |
| 30 | <libtmux.Window.split>` hands you a tiled one. You can confirm a pane is |
| 31 | floating by reading its {attr}`pane_floating_flag <libtmux.Pane.pane_floating_flag>`, |
| 32 | which is `"1"` when it floats: |
| 33 | |
| 34 | ```python |
| 35 | >>> from libtmux.common import has_gte_version |
| 36 | |
| 37 | >>> if has_gte_version("3.7"): |
| 38 | ... floating = window.new_pane(width=20, height=5, shell="sleep 30") |
| 39 | ... is_floating = floating.pane_floating_flag |
| 40 | ... else: |
| 41 | ... is_floating = "1" |
| 42 | >>> is_floating |
| 43 | '1' |
| 44 | ``` |
| 45 | |
| 46 | ## Sizing and positioning |
| 47 | |
| 48 | You set the pane's **size** with `width` and `height` (tmux's `-x` / `-y`), and |
| 49 | its **position** with `x` and `y` — cells measured from the top-left of the |
| 50 | window (tmux's `-X` / `-Y`). tmux reports the placement back through the |
| 51 | {attr}`pane_x <libtmux.Pane.pane_x>` / |
| 52 | {attr}`pane_y <libtmux.Pane.pane_y>` fields: |
| 53 | |
| 54 | ```python |
| 55 | >>> from libtmux.common import has_gte_version |
| 56 | |
| 57 | >>> if has_gte_version("3.7"): |
| 58 | ... placed = window.new_pane(width=20, height=5, x=2, y=1, shell="sleep 30") |
| 59 | ... position = (placed.pane_x, placed.pane_y) |
| 60 | ... else: |
| 61 | ... position = ("2", "1") |
| 62 | >>> position |
| 63 | ('2', '1') |
| 64 | ``` |
| 65 | |
| 66 | ## Styling |
| 67 | |
| 68 | For the rarer cases where appearance matters, you can style a floating pane with |
| 69 | the same overlay options tmux's `new-pane` accepts: `style` (the pane body), |
| 70 | `active_border_style`, and `inactive_border_style`. Each takes a tmux style |
| 71 | string, for example `style="bg=black"` or `active_border_style="fg=green"`. The |
| 72 | defaults read fine on most terminals, so reach for these only when you want a |
| 73 | float to stand out. |
| 74 | |
| 75 | ## Keeping a pane open |
| 76 | |
| 77 | By default a floating pane closes the moment its command exits — fine for a |
| 78 | fire-and-forget command, but you lose whatever it printed. When you want the |
| 79 | output to linger, pass `keep=True` to hold the pane open until you press a key |
| 80 | (tmux's `-k`), or `message="..."` to hold it open showing a custom |
| 81 | `remain-on-exit-format` line (tmux's `-m`). The cost is explicit and small: |
| 82 | both flip the pane's `remain-on-exit` option to `key`, which buys you a pane |
| 83 | that stays on screen and waits for you after the command finishes instead of |
| 84 | vanishing: |
| 85 | |
| 86 | ```python |
| 87 | >>> from libtmux.common import has_gte_version |
| 88 | |
| 89 | >>> if has_gte_version("3.7"): |
| 90 | ... held = window.new_pane(width=20, height=5, shell="sleep 30", keep=True) |
| 91 | ... remain = held.cmd("show-options", "-p", "-v", "remain-on-exit").stdout |
| 92 | ... else: |
| 93 | ... remain = ["key"] |
| 94 | >>> remain |
| 95 | ['key'] |
| 96 | ``` |
| 97 | |
| 98 | ## Identifying floating panes |
| 99 | |
| 100 | When you need to tell floating panes from tiled ones in code, reach for the |
| 101 | tmux 3.7 {attr}`pane_floating_flag <libtmux.Pane.pane_floating_flag>` field. |
| 102 | Every {class}`~libtmux.Pane` carries it, so you can branch on it anywhere you |
| 103 | hold a pane — including filtering a window's {attr}`~libtmux.Window.panes` down |
| 104 | to just the floats: |
| 105 | |
| 106 | ```python |
| 107 | >>> from libtmux.common import has_gte_version |
| 108 | |
| 109 | >>> if has_gte_version("3.7"): |
| 110 | ... _ = window.new_pane(width=20, height=5, shell="sleep 30") |
| 111 | ... floating = [p for p in window.panes if p.pane_floating_flag == "1"] |
| 112 | ... found = len(floating) >= 1 |
| 113 | ... else: |
| 114 | ... found = True |
| 115 | >>> found |
| 116 | True |
| 117 | ``` |
| 118 | |
| 119 | See {meth}`Pane.new_pane() <libtmux.Pane.new_pane>` for the full parameter |
| 120 | reference and {ref}`format-tokens` for the floating-pane geometry fields |
| 121 | ({attr}`pane_x <libtmux.Pane.pane_x>`, {attr}`pane_y <libtmux.Pane.pane_y>`, |
| 122 | {attr}`pane_z <libtmux.Pane.pane_z>`, |
| 123 | {attr}`pane_floating_flag <libtmux.Pane.pane_floating_flag>`). |