Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved option management, add hook management #516

Open
wants to merge 47 commits into
base: master
Choose a base branch
from

Conversation

tony
Copy link
Member

@tony tony commented Feb 7, 2024

Extracted from #513

Warning

APIs below are subject to change (both params, return types, and structures)

Changes

New internal: OptionsMixin

  • show_options(): High level objects, e.g. preserving sparse-array data such as command-alias[1], command-alias[99], and inside of a dataclass object.

    command_alias: SparseArray({0: {'split-pane': 'split-window'})

  • _show_options(): Map of options split up by key, with raw values.

    command-alias[1] split-pane=split-window

  • _show_options_raw(): Raw stdout from tmux show-options

Individual options:

  • show_option(): High level objects, e.g. preserving sparse-array data such as command-alias[1], command-alias[99]

    Not sure if this will scale, but will try to get this:

    > show_option('command-alias')
    SparseArray({0: 'split-pane': 'split-window'})
    
    > show_option('command-alias')[0]
    'split-pane': 'split-window'
    
    > show_option('command-alias[0]')
    'split-pane': 'split-window'
    
  • _show_option():

  • _show_option_raw(): Raw stdout from tmux show-option [option name]

New internal: HooksMixin

New features

  • Window.set_option()

    Learned params:

    • format -> -F
    • unset -> -u
    • global -> -g
    • unset_panes -> -U: Also unset other panse in windows
    • prevent_overwrite: -o
    • suppress_warnings: -q
    • append: -a
  • Window.show_option()

  • Window.show_options()

Breaking changes

Deprecations

  • Deprecated Window.set_window_option() in favor of Window.set_option()
  • Deprecated Window.show_window_option() in favor of Window.show_option()
  • Deprecated Window.show_window_options() in favor of Window.show_options()

Summary by Sourcery

Refactor option and hook management, deprecating old methods.

New Features:

  • Add OptionsMixin to manage tmux options.
  • Add HooksMixin to manage tmux hooks.
  • Introduce new high-level option management methods: show_option(), show_options(), and set_option().
  • Add new high-level hook management methods: run_hook(), set_hook(), show_hooks(), show_hook(), and unset_hook().
  • Implement SparseArray to handle sparse arrays in options and hooks.

Tests:

  • Added tests for new option and hook management methods.

@tony tony force-pushed the improved-options branch from 6cd43f0 to 3399c7d Compare February 7, 2024 16:28
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

Attention: Patch coverage is 79.91071% with 225 lines in your changes missing coverage. Please review.

Project coverage is 85.16%. Comparing base (29f840f) to head (2af77e5).

Files Patch % Lines
src/libtmux/hooks.py 31.65% 72 Missing and 23 partials ⚠️
src/libtmux/options.py 70.78% 50 Missing and 28 partials ⚠️
tests/test_options.py 89.55% 5 Missing and 16 partials ⚠️
tests/legacy_api/test_window.py 60.86% 4 Missing and 5 partials ⚠️
tests/test_window.py 75.67% 4 Missing and 5 partials ⚠️
src/libtmux/_internal/constants.py 97.63% 4 Missing and 2 partials ⚠️
src/libtmux/_internal/sparse_array.py 81.25% 3 Missing ⚠️
tests/test_hooks.py 96.55% 1 Missing and 2 partials ⚠️
src/libtmux/common.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #516      +/-   ##
==========================================
- Coverage   88.54%   85.16%   -3.38%     
==========================================
  Files          36       42       +6     
  Lines        3927     4893     +966     
  Branches      570      698     +128     
==========================================
+ Hits         3477     4167     +690     
- Misses        308      500     +192     
- Partials      142      226      +84     

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

@tony tony mentioned this pull request Feb 7, 2024
@tony tony force-pushed the improved-options branch 4 times, most recently from e5c6186 to 37898a4 Compare February 8, 2024 12:35
@tony tony mentioned this pull request Feb 8, 2024
@tony tony force-pushed the improved-options branch 22 times, most recently from 97d74c1 to 36c5907 Compare February 8, 2024 18:54
tony added 4 commits February 23, 2025 05:51
- Update SparseArray type parameter to include all value types
- Add proper type checking for both dict and SparseArray cases
- Fix return type casting in _show_option method
- Resolve mypy errors related to string indexing of SparseArray
- Add version-specific assertions for terminal features
- Handle rxvt* features in tmux 3.4+
- Make test more robust by checking individual features
WHAT:
- Add comprehensive test coverage for complex option values and edge cases
- Add tests for terminal features edge cases including empty/malformed features
- Add tests for style validation and error handling
- Fix type safety issues in terminal features tests

WHY:
- Ensure proper handling of tmux's complex option types:
  * Empty feature lists (tmux returns [''] not [])
  * Malformed feature strings with colons
  * Features containing spaces and special chars
- Improve type safety by:
  * Adding proper type assertions for runtime checks
  * Using t.cast() to handle complex union types
  * Fixing string vs int indexing for SparseArray
- Make tests more maintainable by:
  * Breaking complex assertions into steps
  * Using descriptive variable names
  * Adding clear comments about tmux behavior
WHAT:
- Add type assertions for style option values
- Convert style values to strings before comparison
- Fix mypy errors in test_style_option_validation

WHY:
- Ensure type safety when handling style option values
- Prevent potential runtime errors from type mismatches
- Make test assertions more robust and explicit
tony added 2 commits February 23, 2025 06:09
WHAT:
- Add version check for status-format option (added in tmux 2.9)
- Update test assertions to handle version-specific behavior

WHY:
- Ensure tests pass on older tmux versions
- Properly handle version-specific options
- Improve test robustness across tmux versions
WHAT:
- Add version check for update-environment option (added in tmux 3.0)
- Update test assertions to handle version-specific behavior
- Add type checking for update-environment value

WHY:
- Ensure tests pass on older tmux versions
- Properly handle version-specific options
- Improve test robustness across tmux versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant