Skip to content

options(fix): Preserve user-option strings - #826

Merged
tony merged 5 commits into
masterfrom
fix/759-user-options
Nov 27, 2026
Merged

tony merged 5 commits into
masterfrom
fix/759-user-options

Conversation

@tony

@tony tony commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Breaking change. Read Before / After below before merging.

Summary

  • Preserve @ user-option strings in show_option() and show_options(), including "123", "on", "off", "", and stravis-escaped newlines, tabs, quotes, and backslashes.
  • Keep built-in numeric, boolean, and structured option conversions unchanged.
  • Document user-option string reads, explicit conversion, and tmux's named-only -A inheritance rule in docs/topics/options_and_hooks.md, CHANGES, and MIGRATION.

Fixes #759

Before / After

Before, show_option() and show_options() ran convert_value() on @ user options, turning "123", "on", and "off" into 123, True, and False:

session.set_option("@count", "123")
session.show_option("@count")

After, @ user options return the string tmux stores ("123"), and callers that want an int or bool convert explicitly:

session.set_option("@count", "123")
int(session.show_option("@count"))

Design decisions

  • In tmux (cmd-set-option.c), every @ option is stored via options_set_string across all supported releases (3.3a+); skipping convert_value() on @ keys (including @name* inherited markers) preserves caller-supplied identifiers such as "007" or "on".
  • In cmd-show-options.c and arguments.c, show-options formats string values through #{q/a:option_value} (args_escape / utf8_strvis), which escapes , , control bytes, and backslashes without adding outer quotes when no space or shell delimiter is present. Decoding args_escape on @ option lines before shlex.split keeps multiline and tab-containing user options intact while leaving built-in option parsing unchanged.
  • In cmd-show-options.c, show-options -A <name> walks parent scopes for @ options whereas bulk show-options -A only walks local @ entries; show_options() and docs/topics/options_and_hooks.md note to pass include_inherited=True to show_option("@name", ...) when reading inherited user options.

Test plan

  • test_custom_options verifies show_option(), show_options(), and show_option(..., include_inherited=True) across server, session, window, and pane scopes for numeric, boolean-spelled, empty, whitespace, quote, backslash, and multiline/tab strings (verified failing on "a b" before _unescape_user_option_value)
  • Built-in option conversion tests and doctests on options.py, docs/topics/options_and_hooks.md, and MIGRATION pass
  • ruff check, ruff format --check, mypy, and sphinx-build -W
  • Full tmux version matrix in CI

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.08%. Comparing base (8d9d823) to head (78a4861).

Files with missing lines Patch % Lines
src/libtmux/options.py 93.75% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #826      +/-   ##
==========================================
+ Coverage   57.58%   58.08%   +0.49%     
==========================================
  Files          29       29              
  Lines        4362     4416      +54     
  Branches      882      895      +13     
==========================================
+ Hits         2512     2565      +53     
- Misses       1539     1540       +1     
  Partials      311      311              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
tony force-pushed the fix/759-user-options branch from 0d8c9fe to 55752f4 Compare November 7, 2026 02:00
@tony tony added the behavior-change Fixes a bug by changing observable or documented behaviour; needs a minor release label Nov 21, 2026
@tony
tony force-pushed the fix/759-user-options branch 3 times, most recently from d2349b0 to d59eee9 Compare November 21, 2026 22:10
@tony tony mentioned this pull request Nov 21, 2026
33 of 58 tasks
@tony
tony force-pushed the fix/759-user-options branch 4 times, most recently from 0997e92 to 78d60c4 Compare November 22, 2026 19:27
@tony tony added the area: options-formats Options, formats, names, targets label Nov 24, 2026
@tony tony added this to the 0.69.0 milestone Nov 24, 2026
@tony
tony force-pushed the fix/759-user-options branch from 78d60c4 to 9374436 Compare November 25, 2026 08:13
@tony tony added this to libtmux Nov 25, 2026
@tony tony moved this to In Progress in libtmux Nov 25, 2026
tony added 5 commits November 26, 2026 19:24
why: tmux stores user options as strings, but reading values such as
"123" or "off" changed their types and broke round trips.

what:
- Preserve @ values in single and bulk option reads across scopes
- Cover inherited reads and retain built-in option conversions
- Document string results and explicit conversion for callers
why: show_option returned @ user options as integers or booleans and
now returns the stored string.

what:
- Add a Breaking changes entry for user option values, with the
  migration
Decode tmux args_escape (utf8_strvis) sequences on @ user options before
shlex.split so embedded newlines, tabs, quotes, and backslashes round-trip
intact, and note tmux's named-only -A behavior for inherited user options.
why: parse_options_to_dict stripped trailing newlines after decoding @
user options, and tmux 3.4's server_client_print ran utf8_strvis without
VIS_DQ on show-options stdout, adding a second backslash before
$[A-Za-z_{] ("$HOME" read back as "\$HOME").

what:
- Strip at most one line-ending \n before decoding @ user-option lines
  and restrict val.rstrip("\n") to the shlex ValueError fallback
- Decode backslash-run parity before $[A-Za-z_{] in
  _unescape_user_option_value (2k + 1 from args_escape on 3.3a and 3.5+,
  2k + 2 on tmux 3.4, ASCII C-locale letters only)
- Test round-trips across all scopes for trailing newlines, carriage
  returns, 3-digit octal before digits, $VAR/\$VAR/$é/\$é, unset options
  with and without ignore_errors=True, child include_inherited=True
  reads, and standalone OptionsMixin subclasses
- Link OptionsMixin methods in MIGRATION and wrap options_and_hooks.md
  to 80 columns
@tony
tony force-pushed the fix/759-user-options branch from 544cfd5 to 78a4861 Compare November 27, 2026 01:26
@tony
tony merged commit a4a37a3 into master Nov 27, 2026
15 checks passed
@tony
tony deleted the fix/759-user-options branch November 27, 2026 01:29
@github-project-automation github-project-automation Bot moved this from In Progress to Done in libtmux Nov 27, 2026
@tony tony mentioned this pull request Nov 28, 2026
7 tasks done
tony added a commit to tmux-python/tmuxp that referenced this pull request Nov 28, 2026
why: Pick up libtmux 0.69.0. Server context managers leave a running
tmux server alive on exit unless kill_on_exit=True is set, @ user
options stay strings in show_option() and show_options(), and empty tmux
format fields hydrate as "" instead of None while unset fields stay
None. tmuxp requires no source changes for the upgrade.

what:
- Bump libtmux ~=0.68.0 -> ~=0.69.0 in pyproject.toml
- Update uv.lock to libtmux 0.69.0 from PyPI (only libtmux moves)

libtmux 0.69.0 (2026-11-27):
- Server.__exit__() preserves running servers unless kill_on_exit=True
  is set (tmux-python/libtmux#728)
- @ user options stay strings in show_option() and show_options()
  (tmux-python/libtmux#826)
- Empty tmux format fields hydrate as "" while unset fields stay None
  (tmux-python/libtmux#900)

See also:
- https://github.com/tmux-python/libtmux/releases/tag/v0.69.0
- https://libtmux.git-pull.com/history/#libtmux-0-69-0-2026-11-27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: options-formats Options, formats, names, targets behavior-change Fixes a bug by changing observable or documented behaviour; needs a minor release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

show_option coerces user options, so an @ option set to 123 or on comes back as an int or a bool

1 participant