Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ availability is separate.
The full support matrix, benchmarks and implementation type coverage remain
separate required gates; one local outer pass does not establish them.

The [option catalog generator](../scripts/option-catalog/README.md) reads a
pinned local tmux source release. Its `--check` compares the shipped option
and hook metadata with that source.

README commands are tested too. The unit suite lints the READMEs in
`test/unit/readme_blocks_test.rb`: one command per console block, `gem install`
names, flags against each executable's `--help`, linked MCP tool names, gem
Expand Down
44 changes: 35 additions & 9 deletions docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,11 @@ type checking. See [signature proof](behavior.md#signature-proof).

| Method | Declared return | Contract |
| --- | --- | --- |
| [#get](../../gems/libtmux/lib/libtmux/options.rb#L192) | `::LibTmux::OptionValue` | [Options and hooks](behavior.md#options-and-hooks) |
| [#list](../../gems/libtmux/lib/libtmux/options.rb#L65) | `::Array[::LibTmux::OptionValue]` | [Options and hooks](behavior.md#options-and-hooks) |
| [#run](../../gems/libtmux/lib/libtmux/options.rb#L202) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#set](../../gems/libtmux/lib/libtmux/options.rb#L196) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#unset](../../gems/libtmux/lib/libtmux/options.rb#L131) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#get](../../gems/libtmux/lib/libtmux/options.rb#L194) | `::LibTmux::OptionValue` | [Options and hooks](behavior.md#options-and-hooks) |
| [#list](../../gems/libtmux/lib/libtmux/options.rb#L66) | `::Array[::LibTmux::OptionValue]` | [Options and hooks](behavior.md#options-and-hooks) |
| [#run](../../gems/libtmux/lib/libtmux/options.rb#L204) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#set](../../gems/libtmux/lib/libtmux/options.rb#L198) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#unset](../../gems/libtmux/lib/libtmux/options.rb#L132) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |

## LibTmux::IncompleteSnapshotError

Expand Down Expand Up @@ -618,6 +618,32 @@ type checking. See [signature proof](behavior.md#signature-proof).
| [#text](../../gems/libtmux/lib/libtmux/errors.rb#L5) | `::String?` | [Errors](behavior.md#errors) |
| [.new](../../gems/libtmux/lib/libtmux/errors.rb#L7) | `::LibTmux::NoMatchError` | [Errors](behavior.md#errors) |

## LibTmux::OptionCatalog

| Method | Declared return | Contract |
| --- | --- | --- |
| [.hooks](../../gems/libtmux/lib/libtmux/option_catalog.rb#L52) | `::Hash[::String, ::LibTmux::OptionCatalog::Hook]` | [Option catalog](behavior.md#option-catalog) |
| [.options](../../gems/libtmux/lib/libtmux/option_catalog.rb#L49) | `::Hash[::String, ::LibTmux::OptionCatalog::Option]` | [Option catalog](behavior.md#option-catalog) |
| [.tmux_version](../../gems/libtmux/lib/libtmux/option_catalog.rb#L46) | `::String` | [Option catalog](behavior.md#option-catalog) |

## LibTmux::OptionCatalog::Hook

| Method | Declared return | Contract |
| --- | --- | --- |
| [#name](../../gems/libtmux/lib/libtmux/option_catalog.rb#L29) | `::String` | [Option catalog](behavior.md#option-catalog) |
| [#scopes](../../gems/libtmux/lib/libtmux/option_catalog.rb#L29) | `::Array[::LibTmux::OptionCatalog::scope]` | [Option catalog](behavior.md#option-catalog) |

## LibTmux::OptionCatalog::Option

| Method | Declared return | Contract |
| --- | --- | --- |
| [#array?](../../gems/libtmux/lib/libtmux/option_catalog.rb#L24) | `bool` | [Option catalog](behavior.md#option-catalog) |
| [#choices](../../gems/libtmux/lib/libtmux/option_catalog.rb#L10) | `::Array[::String]` | [Option catalog](behavior.md#option-catalog) |
| [#name](../../gems/libtmux/lib/libtmux/option_catalog.rb#L10) | `::String` | [Option catalog](behavior.md#option-catalog) |
| [#range](../../gems/libtmux/lib/libtmux/option_catalog.rb#L10) | `::Range[::Integer]?` | [Option catalog](behavior.md#option-catalog) |
| [#scopes](../../gems/libtmux/lib/libtmux/option_catalog.rb#L10) | `::Array[::LibTmux::OptionCatalog::scope]` | [Option catalog](behavior.md#option-catalog) |
| [#type](../../gems/libtmux/lib/libtmux/option_catalog.rb#L10) | `::LibTmux::OptionCatalog::option_type` | [Option catalog](behavior.md#option-catalog) |

## LibTmux::OptionValue

| Method | Declared return | Contract |
Expand All @@ -634,10 +660,10 @@ type checking. See [signature proof](behavior.md#signature-proof).

| Method | Declared return | Contract |
| --- | --- | --- |
| [#get](../../gems/libtmux/lib/libtmux/options.rb#L102) | `::LibTmux::OptionValue` | [Options and hooks](behavior.md#options-and-hooks) |
| [#list](../../gems/libtmux/lib/libtmux/options.rb#L65) | `::Array[::LibTmux::OptionValue]` | [Options and hooks](behavior.md#options-and-hooks) |
| [#set](../../gems/libtmux/lib/libtmux/options.rb#L120) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#unset](../../gems/libtmux/lib/libtmux/options.rb#L131) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#get](../../gems/libtmux/lib/libtmux/options.rb#L103) | `::LibTmux::OptionValue` | [Options and hooks](behavior.md#options-and-hooks) |
| [#list](../../gems/libtmux/lib/libtmux/options.rb#L66) | `::Array[::LibTmux::OptionValue]` | [Options and hooks](behavior.md#options-and-hooks) |
| [#set](../../gems/libtmux/lib/libtmux/options.rb#L121) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |
| [#unset](../../gems/libtmux/lib/libtmux/options.rb#L132) | `::LibTmux::CommandResult` | [Options and hooks](behavior.md#options-and-hooks) |

## LibTmux::OutcomeUnknown

Expand Down
31 changes: 31 additions & 0 deletions docs/reference/behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,37 @@ remains present. Append follows tmux's lowest-free-index rule, and indexed
hooks execute in index order. Empty arrays remain distinct from empty String
values.

## Option catalog

`LibTmux::OptionCatalog.options` and `.hooks` return frozen hashes keyed by
canonical tmux name. Each hash is sorted by name. Look up a name with `[]`
to get its definition or `nil`. The catalog describes built-in definitions
from `OptionCatalog.tmux_version`, currently tmux 3.8, and works without a daemon.
Use `Options` and `Hooks` to read or change values on a connected daemon,
which checks names and values against its own release.

An option's `type` corresponds to its tmux table type. `scopes` lists every
scope declared in the table. `range` gives inclusive numeric limits or `nil`.
`choices` gives the choice values in tmux order and is empty for other types.
`array?` reports the upstream array flag. A hook gives its name and scopes.

<!-- example: api_option_catalog/main -->
```ruby
require "libtmux"

catalog = LibTmux::OptionCatalog
history = catalog.options.fetch("history-limit")
position = catalog.options.fetch("status-position")
created = catalog.hooks.fetch("pane-created")

puts "tmux source: #{catalog.tmux_version}"
puts "history-limit: #{history.type}, #{history.scopes.join(', ')}, " \
"#{history.range}"
puts "status-position: #{position.choices.join(', ')}"
puts "pane-created: #{created.scopes.join(', ')}"
```
<!-- /example -->

## Option values

Option-value accessors are local. `raw` preserves bytes, and `as` explicitly
Expand Down
17 changes: 17 additions & 0 deletions docs/reference/contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,23 @@
"LibTmux::MCP::StdioTransport.new"
]
},
{
"id": "option-catalog",
"title": "Option catalog",
"methods": [
"LibTmux::OptionCatalog.hooks",
"LibTmux::OptionCatalog.options",
"LibTmux::OptionCatalog.tmux_version",
"LibTmux::OptionCatalog::Hook#name",
"LibTmux::OptionCatalog::Hook#scopes",
"LibTmux::OptionCatalog::Option#array?",
"LibTmux::OptionCatalog::Option#choices",
"LibTmux::OptionCatalog::Option#name",
"LibTmux::OptionCatalog::Option#range",
"LibTmux::OptionCatalog::Option#scopes",
"LibTmux::OptionCatalog::Option#type"
]
},
{
"id": "option-values",
"title": "Option values",
Expand Down
16 changes: 16 additions & 0 deletions examples/api/option_catalog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# docs:begin main
require "libtmux"

catalog = LibTmux::OptionCatalog
history = catalog.options.fetch("history-limit")
position = catalog.options.fetch("status-position")
created = catalog.hooks.fetch("pane-created")

puts "tmux source: #{catalog.tmux_version}"
puts "history-limit: #{history.type}, #{history.scopes.join(', ')}, " \
"#{history.range}"
puts "status-position: #{position.choices.join(', ')}"
puts "pane-created: #{created.scopes.join(', ')}"
# docs:end main
20 changes: 20 additions & 0 deletions examples/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@
"output": "Reply from the fixture\n"
}
},
{
"id": "api_option_catalog",
"path": "examples/api/option_catalog.rb",
"gem": "libtmux",
"api": {
"symbols": [
"LibTmux::OptionCatalog.tmux_version",
"LibTmux::OptionCatalog.options",
"LibTmux::OptionCatalog.hooks"
],
"description": "Look up an option's type, scope and allowed values and a hook's scopes using the catalog shipped with the gem.",
"output": "tmux source: 3.8\nhistory-limit: number, session, 0..2147483647\nstatus-position: top, bottom\npane-created: window, pane\n"
}
},
{
"id": "api_cancellation",
"path": "examples/api/cancellation.rb",
Expand Down Expand Up @@ -618,6 +632,12 @@
"region": "main",
"language": "ruby"
},
{
"id": "api_option_catalog/main",
"source": "examples/api/option_catalog.rb",
"region": "main",
"language": "ruby"
},
{
"id": "api_cancellation/main",
"source": "examples/api/cancellation.rb",
Expand Down
2 changes: 2 additions & 0 deletions gems/libtmux/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ in the [main changelog](../../CHANGELOG.md).
(#181)
- Option reads preserve literal asterisks and spaces in user option names
while reporting whether the value is inherited. (#182)
- OptionCatalog exposes the built-in option and hook definitions from tmux
3.8, including option types, ranges, choices and scopes. (#191)
- `Server#write_buffer` raises `UnsupportedFeatureError` for an empty payload
before sending it to tmux. Nonempty writes keep their existing behavior.
(#172)
Expand Down
3 changes: 3 additions & 0 deletions gems/libtmux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ hook: display-message created

The contracts are in [Options and hooks][behavior-options] and
[Option values][behavior-option-values].
Look up built-in types, choices and hook scopes in the
[option catalog][behavior-option-catalog].

## Watch tmux change

Expand Down Expand Up @@ -953,6 +955,7 @@ MIT. See [LICENSE](LICENSE).
[behavior-live-handles]: ../../docs/reference/behavior.md#live-handles
[behavior-option-values]: ../../docs/reference/behavior.md#option-values
[behavior-options]: ../../docs/reference/behavior.md#options-and-hooks
[behavior-option-catalog]: ../../docs/reference/behavior.md#option-catalog
[behavior-records]: ../../docs/reference/behavior.md#captured-records
[behavior-signature]: ../../docs/reference/behavior.md#signature-proof
[behavior-window-links]: ../../docs/reference/behavior.md#window-links
Expand Down
4 changes: 4 additions & 0 deletions gems/libtmux/lib/libtmux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
require "libtmux/terminal"
require "libtmux/text_wait"
require "libtmux/program"

module LibTmux
autoload :OptionCatalog, "libtmux/option_catalog"
end
54 changes: 54 additions & 0 deletions gems/libtmux/lib/libtmux/option_catalog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require "json"

module LibTmux
# Built-in option and hook definitions from the pinned tmux source release.
module OptionCatalog
# Metadata for a built-in tmux option.
class Option
attr_reader :name, :type, :scopes, :range, :choices

def initialize(name, definition)
@name = name
@type = definition.fetch("type").to_sym
@scopes = definition.fetch("scopes").map(&:to_sym).freeze
@range = Range.new(*definition.fetch("range")) if definition.key?("range")
@choices = definition.fetch("choices", [].freeze)
@array = definition.fetch("array", false)
freeze
end
private_class_method :new

# Whether tmux defines the option as an array.
def array? = @array
end

# A built-in hook and the scopes declared by tmux.
class Hook
attr_reader :name, :scopes

def initialize(name, scopes)
@name = name
@scopes = scopes.map(&:to_sym).freeze
freeze
end
private_class_method :new
end

data = JSON.parse(File.binread(File.expand_path("../../schema/option-catalog.json", __dir__)), freeze: true)
TMUX_VERSION = data.fetch("tmux_version")
OPTIONS = data.fetch("options").to_h { |name, definition| [name, Option.__send__(:new, name, definition)] }.freeze
HOOKS = data.fetch("hooks").to_h { |name, scopes| [name, Hook.__send__(:new, name, scopes)] }.freeze
private_constant :TMUX_VERSION, :OPTIONS, :HOOKS

# The source release for both catalogs, independent of any connected daemon.
def self.tmux_version = TMUX_VERSION

# A frozen hash keyed by canonical option name, sorted by name.
def self.options = OPTIONS

# A frozen hash keyed by canonical hook name, sorted by name.
def self.hooks = HOOKS
end
end
6 changes: 4 additions & 2 deletions gems/libtmux/lib/libtmux/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def as(type)
end
end

# Explicit acquisition and mutation at one option scope.
# Explicit acquisition and mutation at one option scope. For built-in
# option types, scopes and allowed values, see {OptionCatalog.options}.
class Options
# tmux prints the user option name as-is and its value as one args_escape token.
USER_OPTION_RECORD = /
Expand Down Expand Up @@ -187,7 +188,8 @@ def decode_escaped(value)
end
end

# Hook values are executable tmux command strings, never literal data.
# Hook values are executable tmux command strings. See {OptionCatalog.hooks}
# for the built-in names and their scopes.
class Hooks < Options
def get(name, index: nil, inherited: false, timeout: 5.0, cancel: nil)
super
Expand Down
3 changes: 3 additions & 0 deletions gems/libtmux/libtmux.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
lib/libtmux/server.rb
lib/libtmux/operations.rb
lib/libtmux/options.rb
lib/libtmux/option_catalog.rb
lib/libtmux/catalog.rb
lib/libtmux/snapshot.rb
lib/libtmux/capture.rb
Expand All @@ -53,6 +54,7 @@ Gem::Specification.new do |spec|
sig/libtmux.rbs
sig/criteria.rbs
sig/operations.rbs
sig/option_catalog.rbs
sig/snapshot.rbs
sig/control.rbs
sig/group.rbs
Expand All @@ -61,6 +63,7 @@ Gem::Specification.new do |spec|
sig/program.rbs
sig/fields.rbs
schema/where-v1.json
schema/option-catalog.json
]
spec.add_dependency "json", ">= 3.0.2", "< 4"
spec.add_dependency "tmpdir", "~> 0.3"
Expand Down
Loading
Loading