# Examples

Source: https://libtmux.org/en/tmux/examples/

> Programs for sending input, capturing output, and building workspaces.

Use these programs to send input, capture output, and build a workspace.
Each example page includes its source and test coverage. Check those details
before adapting an excerpt into a standalone program.

<a id="what-verified-means-per-port"></a>

## Source and verification

Port repositories use the following checks for their source examples. This site
reads or copies those examples; a successful site build alone does not execute
them:

### Python
The test configuration includes [`README.md`](<https://github.com/tmux-python/libtmux/blob/9fdd083a8181a827889337b63cd4e6daea661a8c/README.md>) and [`src/libtmux/`](<https://github.com/tmux-python/libtmux/tree/9fdd083a8181a827889337b63cd4e6daea661a8c/src/libtmux>) in its
doctest collection. The `>>>` examples run against isolated tmux sessions.

### TypeScript
[`scripts/check-doc-runnable.ts`](<https://github.com/libtmux/libtmux-ts/blob/46cccfef2a546de55ce8b308249b8c76339089a0/scripts/check-doc-runnable.ts>) checks that a block tagged with its
example source matches that file line for line. The integration suite
executes the source program.

### Go
`go generate ./tmux` refreshes documented regions from matching source
regions under [`examples/`](<https://github.com/libtmux/libtmux-go/tree/6f3df55f8a41999e41225eefb3940545b834e6a2/examples>). CI checks that those generated excerpts are current.

### Rust
The library includes its README as a crate doc comment.
`cargo test --doc` compiles and runs its executable Rust code blocks.

### Java
`./gradlew :docs-tests:test` compiles executable Java blocks in READMEs
and guides against the library artifacts, then runs them against tmux through
`libtmux-junit5`.

### C#
`sync_snippets.py --check` checks excerpts from tested `[Example]`
methods. `ReadmeExampleTests` also compiles and executes blocks marked
`csharp run`.

### C++
[`tools/docs/check_readme.py`](<https://github.com/libtmux/libtmux-cxx/blob/3f93b021cb51e8349bfb9cecc6fd4091f6e79a0f/tools/docs/check_readme.py>) checks that README examples match their
source regions in [`examples/05-readme.cpp`](<https://github.com/libtmux/libtmux-cxx/blob/3f93b021cb51e8349bfb9cecc6fd4091f6e79a0f/examples/05-readme.cpp>). CTest builds and runs that program.

### Swift
[`Scripts/check_examples.py`](<https://github.com/libtmux/libtmux-swift/blob/7993e7044347629b08020e9b02ae8bcffa0e5898/Scripts/check_examples.py>) checks that README examples match sources
under [`Examples/Sources/`](<https://github.com/libtmux/libtmux-swift/tree/7993e7044347629b08020e9b02ae8bcffa0e5898/Examples/Sources>). `swift test --package-path Examples` compiles
those examples through the public products.

See [Testing with libtmux](https://libtmux.org/en/tmux/guides/testing-with-libtmux/) for the fixture
each of those test suites runs against, and each example page for the
exact file a given snippet was quoted from.

- [Attach and send keys](https://libtmux.org/en/tmux/examples/attach-and-send-keys/): Find a session, send a command, and read its output.
- [Capture pane output](https://libtmux.org/en/tmux/examples/capture-pane-output/): Read a pane's screen and wait for output to appear.
- [Build a workspace from a file](https://libtmux.org/en/tmux/examples/workspace-from-file/): Create a session, windows, and panes from configuration.
