Skip to content

Commit 18d9f80

Browse files
committed
options.py(fix[_show_option]): Handle inherited option marker in lookups
why: tmux appends "*" to option names that are inherited from parent scopes (e.g., "visual-activity*" when the value comes from global scope). The lookup code was checking for the exact option name, missing inherited values. what: - Check for both exact key and key with "*" suffix in raw output lookup - Check for inherited marker in exploded output lookup as well - Fix test to properly capture inherited value before set/unset cycle
1 parent 6b81b0c commit 18d9f80

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/libtmux/options.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,19 +1152,32 @@ def _show_option(
11521152
# Parse raw output first (preserves indexed keys like "status-format[0]")
11531153
output_raw = parse_options_to_dict(io.StringIO("\n".join(cmd.stdout)))
11541154

1155+
# Handle tmux's inherited option marker: tmux appends "*" to option names
1156+
# that are inherited from a parent scope (e.g., "visual-activity*" for an
1157+
# option inherited from global scope). We need to check for both the exact
1158+
# option name and the name with "*" suffix.
1159+
option_key = option
1160+
if option not in output_raw and f"{option}*" in output_raw:
1161+
option_key = f"{option}*"
1162+
11551163
# Direct lookup for indexed queries (e.g., "status-format[0]")
11561164
# tmux returns only that index's value, so we handle it before exploding
1157-
if option in output_raw:
1158-
return convert_value(output_raw[option])
1165+
if option_key in output_raw:
1166+
return convert_value(output_raw[option_key])
11591167

11601168
# For base name queries, explode arrays and return structured data
11611169
output_exploded = convert_values(explode_complex(explode_arrays(output_raw)))
11621170

11631171
if not isinstance(output_exploded, (dict, SparseArray)):
11641172
return t.cast("ConvertedValue", output_exploded)
11651173

1166-
if isinstance(output_exploded, dict) and option not in output_exploded:
1167-
return None
1174+
# Check for inherited marker in exploded output as well
1175+
exploded_key = option
1176+
if isinstance(output_exploded, dict):
1177+
if option not in output_exploded and f"{option}*" in output_exploded:
1178+
exploded_key = f"{option}*"
1179+
if exploded_key not in output_exploded:
1180+
return None
11681181

11691182
if isinstance(output_exploded, SparseArray):
11701183
try:
@@ -1173,7 +1186,7 @@ def _show_option(
11731186
except (ValueError, KeyError):
11741187
return None
11751188

1176-
return t.cast("ConvertedValue | None", output_exploded[option])
1189+
return t.cast("ConvertedValue | None", output_exploded[exploded_key])
11771190

11781191
def show_option(
11791192
self,

tests/test_options.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,17 @@ def test_complex_option_values(server: Server) -> None:
618618

619619
# Test option inheritance (only for tmux >= 3.0)
620620
if has_gte_version("3.0"):
621-
parent_val = session.show_option("status-style")
621+
# Capture the inherited value (from global scope). Need include_inherited
622+
# because without an explicit session-level value, show_option returns None
623+
inherited_val = session.show_option("status-style", include_inherited=True)
622624
session.set_option("status-style", "fg=red")
623625
assert session.show_option("status-style") == "fg=red"
624626
assert session.show_option("status-style", include_inherited=True) == "fg=red"
625627
session.unset_option("status-style")
626-
assert session.show_option("status-style", include_inherited=True) == parent_val
628+
# After unsetting, should get inherited value back
629+
assert (
630+
session.show_option("status-style", include_inherited=True) == inherited_val
631+
)
627632

628633

629634
def test_style_option_validation(server: Server) -> None:

0 commit comments

Comments
 (0)