szn

Bug 440 — Global window status options rejected by scope routing and status cache freeze on active window switch

440. Global window status options rejected by scope routing and status cache freeze on active window switch

Severity: HIGH
Status: Fixed

Between v0.8.2 and v0.9.0, multiple interacting regressions broke window-status-format and window-status-current-format configuration, live runtime option updates, and real-time status line redraws.


Root Cause Analysis

1. Scope Flag Routing Rejection on set -g (Commit ba666087f669 / Bug #415)

In options.zig, window-status-format and window-status-current-format are defined in WINDOW_OPTIONS, whereas global_options holds SESSION_OPTIONS. When parsing set -g window-status-format "..." in szn.conf, the directive is parsed with flags.global = true and flags.window = false.

In server.zig:3305-3309:

if (s.flags.window) {
    self.global_window_options.set(s.option, s.value) catch |err| {
        std.log.warn("set window option {s} failed: {any}", .{ s.option, err });
    };
} else if (s.flags.session or s.flags.server or s.flags.global) {
    self.global_options.set(s.option, s.value) catch |err| {
        std.log.warn("set session/global option {s} failed: {any}", .{ s.option, err });
    };
}

Because s.flags.global is matched in the else if branch without checking if the option belongs to global_window_options, self.global_options.set() fails with error.UnknownOption and the setting is dropped.

Similarly, in cmd.zig:927-937 (cmdSetOption):

if (is_global) {
    if (is_window) {
        server.global_window_options.set(option_name, parsed_val) catch return .err;
    } else {
        server.global_options.set(option_name, parsed_val) catch return .err;
    }
}

Passing set -g window-status-format ... without -w fails directly with .err.

2. Status Cache Stale Rendering on Window Switches & Option Changes (Commit 23cbd6eeaca4 / Bug #425)

Commit 23cbd6eeaca4 introduced status_dirty caching in renderToDisplayClient():

const use_cache = !self.status_dirty and dc.status_line_width == dc.sx and dc.status_line != null and dc.status_line_copy_mode == pane_in_copy_mode and dc.status_line_time == current_sec;

3. Inline Comment Stripping in src/cfg.zig

In cfg.zig:156-177, stripInlineComment() only recognized double quotes ("). If a user specified single-quoted format strings (e.g. set -g window-status-format '#I:#W') or unquoted #I:#W, the parser treated # as an inline comment and truncated the string.

4. Active-Window Sampling in buildStatusLine

In server.zig:478-486, buildStatusLine() retrieved win_fmt only from the currently active window and passed it globally to all windows in buildLine(), ignoring per-window formats set on inactive windows.

5. truncateVisible vs visibleLen Wide Character Discrepancy (Commit 65a952c4f3af / Bug #432)

status.zig:114-124 measured character cell width with char_width.charWidth(cp), while status.zig:172 (truncateVisible) incremented single columns (cols += 1). Wide characters or emoji in window formats resulted in mismatched truncation and alignment calculations.


Impacted Commits (v0.8.2..v0.9.0)

Commit Changeset Description
659 ba666087f669 fix(cfg,server): handle combined short options, scope flag routing, set-environment and if-shell (bug #415)
668 23cbd6eeaca4 perf(server): key status cache on timestamp + status_dirty and use O(1) client lookup (bug #425)
683 65a952c4f3af fix(status): measure wide and combining character cell widths in visibleLen (bug #432)

Resolution

  1. Option Scope Fallback & Command Routing:
    • In applyDirectives(), when -g is given without explicit -s or -w, option lookup tries global_options first; if error.UnknownOption is returned, it falls back to global_window_options.
    • In cmdSetOption(), option lookup falls back between session and window options for both global (-g) and active session targets.
    • Added support for setw, set-window-option, and set-option directives in cfg.zig and registered set-window-option / setw command entry in cmd.zig.
  2. Status Cache Invalidation:
    • Set server.status_dirty = true across all window navigation and lifecycle actions (next_window, prev_window, last_window, select_window_*, new_window, kill_window, rename_window, mouse tab click) and whenever setting options starting with status or window-status.
  3. Single-Quote Quoting Support:
    • Updated stripInlineComment() and parseValue() in cfg.zig to support single-quoted format strings '#I:#W', preserving embedded # format characters without stripping them as comments.
  4. Per-Window Format Resolution:
  5. Wide-Character Cell Width Truncation:
    • Updated truncateVisible() in status.zig to decode codepoints and measure cell widths with char_width.charWidth(), matching visibleLen() and preventing mid-cell splits on wide characters / emojis.