Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Format Ruby with syntax_tree
887fbe07a5f0e6d6ec55291c766457c3cf752b9f
26 changes: 26 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,32 @@ The packaging test expects the program to be refused on a tmux that lacks a
listed capability and to succeed on one that has them all, and the docs export
gives each page the release it needs in `tmux_releases`.

Format Ruby source at 100 columns and examples at 80, then refresh the copied
examples and API source links:

```console
$ mise exec -- bundle exec scripts/format
```

Run the same read-only format check as CI:

```console
$ mise exec -- bundle exec scripts/format --check
```

Standard formats and lints the Ruby files under `scripts/`.

The shared width check reads tracked Markdown and example files. Download the
[pinned checker][example-width-checker] and run it from the checkout with
Python 3.11 or newer:

```console
$ python3 /path/to/check_example_width.py --root .
```

[example-width-checker]: https://raw.githubusercontent.com/libtmux/.github/bd3bae79572512da032287202d74c8da03b5967b/actions/check-example-width/check_example_width.py


Check unstaged changes for whitespace errors:

```console
Expand Down
89 changes: 89 additions & 0 deletions .github/WRITING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ lines. Omit narration of surrounding code, duplicated counts or defaults, and
history recorded by Git. Preserve tool directives and markers such as
`# frozen_string_literal: true` and `# docs:begin` / `# docs:end`.

### Code blocks

Code blocks are paste-and-run units enforced by
`test/unit/readme_blocks_test.rb` and
`test/integration/readme_commands_test.rb`:
Expand All @@ -81,6 +83,93 @@ Code blocks are paste-and-run units enforced by
- Tag source fences with their language and wrap displayed code lines within 80
columns.

## Examples

<!-- shared:examples -->

An example is code written for a reader: a program under `examples/`, code in
a doc comment or docstring, and every fenced block in a README or docs page.
Shell blocks also follow [Code blocks](#code-blocks).

The text between the shared markers is the same in every libtmux port.
Change it in all of them together.

### Width

- **Examples stay within 80 columns.** They render in fixed-width boxes that
scroll sideways, and 80 columns fits a libtmux.org code block in a
laptop-width window. Comments inside examples wrap at 80 too.
- **The width check enforces it.** It reads the tracked files that
`.github/example-width.toml` names and fails on a wider line. It measures
the whole source line, so code in a doc comment counts its indent and
comment marker. It skips output (a fence tagged `text`, and what a
`console` block prints), hidden setup lines, and a line that is only a URL;
an untagged fence counts as code.
- **A line that must stay wider is listed there with its reason.** An entry
that no longer matches a line fails the check, so no stale entry stays.
- **The formatter's width is the hard limit for all other source.** Example
directories set their formatter to 80 where the formatter takes a width.

### Reaching 80

- **Change the code, not the line breaks.** A formatter rejoins any line that
fits its width. Name a sub-expression, use a short example name, hide setup
the reader does not need, or print less.
- **Break at the outermost level when a break is still needed:** after an
opening parenthesis with one argument per line, one call per line in a
chain, one field per line in a literal.
- **Put a comment on its own line above the code it explains.** Never trail
one after code in an example, unless the repository's example runner reads
it there, as with an assertion marker.
- **Break a long string at a word boundary,** never inside a tmux format
(`#{...}`) or an escape sequence; the joined text stays the same.
- **Continue a long command in a `console` block the way its shell does:**
`\` after a `$ ` prompt, a backtick after `PS> `, one flag per continuation
line.

### What never breaks

- **Output a test compares.** Wrapping it changes what the test expects.
- **A block copied from a source file.** Fix the width in the source and run
the sync command; never edit the copy.
- **Marker lines and URLs,** which tools and readers take whole.

<!-- /shared:examples -->

### In this repository

- **Hard limit:** Syntax Tree formats Ruby examples at 80 columns. Run
`bundle exec scripts/format --check` to check the format. The shared
width action checks the files listed in `.github/example-width.toml`.
- **Not formatted:** Markdown fences, Ruby comments, and YAML example
files still count toward the width limit.
- **Runs, compiles, exempt:** An `<!-- example: ID -->` marker names a
source in `examples/manifest.json`. The excerpt copies the whole source
or a named `# docs:begin NAME` region. Run
`scripts/examples/examples --check` to verify copied excerpts. The
installed-gem tests run the Ruby programs. Console and output fences
use no marker.
- **Compared output and copied blocks:** Keep expected output verbatim.
Edit the source and run `bundle exec scripts/format` to refresh excerpts
and API source links.

Bad, over 80:

```ruby
script =
'printf "%s:%s" "$EXAMPLE_CONTEXT" "$TMUX_PANE"; printf "\\000\\377" >&2; exit 9'
```

Good, each command has its own line:

```ruby
script = [
'printf "%s:%s" "$EXAMPLE_CONTEXT" "$TMUX_PANE"',
'printf "\\000\\377" >&2',
"exit 9"
].join("; ")
```

## Commits, changelogs, and releases

Follow the scoped commit and pull request rules in
Expand Down
22 changes: 22 additions & 0 deletions .github/example-width.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
width = 80
markdown = ["**/*.md"]
sources = ["examples/**/*.rb", "examples/**/*.yaml", "examples/**/*.json"]
allow_ceiling = 1
shared_digest = "872d3f4cb1eb2b5cd9c5b7adc9cd140a153e4bbed3cb5bd0b7400a905e6dae4d"

[[exclude]]
glob = "examples/manifest.json"
reason = "machine-read index whose output strings the example tests compare byte for byte; its line breaks cannot change"

[[exclude]]
glob = "scripts/examples/examples"
reason = "Ruby maintainer command that verifies published examples"

[[exclude]]
glob = "scripts/examples/tests/example_manifest_test.rb"
reason = "unit tests for the manifest checker"

[[allow]]
path = ".github/WRITING.md"
line = " 'printf \"%s:%s\" \"$EXAMPLE_CONTEXT\" \"$TMUX_PANE\"; printf \"\\\\000\\\\377\" >&2; exit 9'"
reason = "the Bad example in the port block; it shows the width problem the Good example fixes"
4 changes: 4 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ jobs:
with:
ruby-version: '4.0.7'
bundler-cache: true
- name: Check Ruby formatting
run: bundle exec scripts/format --check
- name: Check example width
uses: libtmux/.github/actions/check-example-width@bd3bae79572512da032287202d74c8da03b5967b
- name: Install consumer test prerequisites
uses: libtmux/.github/actions/apt-get@30f81842b1e639ea4e25f93f1f2543504178e228
with:
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ requested work.
[.github/CONTRIBUTING.md](.github/CONTRIBUTING.md).
- Documentation, user-facing text, comments, and commit messages:
[.github/WRITING.md](.github/WRITING.md).
- Code examples: [Examples](.github/WRITING.md#examples).
- Support scripts: what may stay, their language, layout and checks:
[.github/SCRIPTS.md](.github/SCRIPTS.md).

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ at one version, so a release has a section in each changelog.

## 0.1.4 (unreleased)

- Format Ruby source and check that published examples fit within
80 columns. (#19)

## 0.1.3 (2026-12-05)

Core and Async can wait for visible pane text with a deadline. On tmux 3.7
Expand Down
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

source "https://rubygems.org"

%w[libtmux libtmux-async libtmux-mcp libtmux-workspace].each do |name|
gemspec path: "gems/#{name}"
end
%w[libtmux libtmux-async libtmux-mcp libtmux-workspace].each { |name| gemspec path: "gems/#{name}" }

group :test do
gem "fcntl", "~> 1.3"
Expand All @@ -18,3 +16,7 @@ end
gem "rake", "~> 13.3"
gem "rbs", "~> 3.10"
gem "yard", "~> 0.9"

group :development do
gem "syntax_tree", "~> 6.3"
end
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ GEM
parser (3.3.13.0)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
prism (1.9.0)
psych (5.5.0)
date
Expand Down Expand Up @@ -125,6 +126,8 @@ GEM
lint_roller (~> 1.1)
rubocop-performance (~> 1.26.0)
stringio (3.2.0)
syntax_tree (6.3.0)
prettier_print (>= 1.2.0)
tmpdir (0.3.1)
fileutils
tsort (0.2.0)
Expand All @@ -150,6 +153,7 @@ DEPENDENCIES
rake (~> 13.3)
rbs (~> 3.10)
standard (~> 1.57)
syntax_tree (~> 6.3)
yard (~> 0.9)

CHECKSUMS
Expand Down Expand Up @@ -184,6 +188,7 @@ CHECKSUMS
optparse (0.8.1) sha256=42bea10d53907ccff4f080a69991441d611fbf8733b60ed1ce9ee365ce03bd1a
parallel (2.3.0) sha256=f75a3e904101ce6a1ccb6b8dc800cbafd42166d83330192438dcf29395167a6f
parser (3.3.13.0) sha256=e02f9b63c2fe05b0c68f692ba4df89b3cb113b663964f75d988fbebfd6c3deca
prettier_print (1.2.1) sha256=a72838b5f23facff21f90a5423cdcdda19e4271092b41f4ea7f50b83929e6ff9
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
psych (5.5.0) sha256=4b245bbbd0f3238df8ccee766ebc1a6b062b10e4ee1d3284eb588739ba156a0a
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
Expand All @@ -201,6 +206,7 @@ CHECKSUMS
standard-custom (1.0.2) sha256=424adc84179a074f1a2a309bb9cf7cd6bfdb2b6541f20c6bf9436c0ba22a652b
standard-performance (1.9.0) sha256=49483d31be448292951d80e5e67cdcb576c2502103c7b40aec6f1b6e9c88e3f2
stringio (3.2.0) sha256=c37cb2e58b4ffbd33fe5cd948c05934af997b36e0b6ca6fdf43afa234cf222e1
syntax_tree (6.3.0) sha256=56e25a9692c798ec94c5442fe94c5e94af76bef91edc8bb02052cbdecf35f13d
tmpdir (0.3.1) sha256=908e9729bb31ce104ba27fc03cfc8293a7f858a8dc9e3a1d7cfd112919a3513d
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
unicode-display_width (3.3.0) sha256=4b7aa66a4b11db50f6f7e98411215cd0dd10eaecb665d36eec5bcacb3fa0b613
Expand Down
Loading