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: 1 addition & 1 deletion scripts/check-example-blocks.negative.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const cases = [
{ name: 'an excerpt whose range ends inside a block', page: attach, find: 'from="found=no" to="done"', replace: 'from="found=no" to="fi"', trips: /opens do it never closes/ },
{ name: 'an excerpt that carries its own text', page: attach, find: 'from="has-session"\n```', replace: 'from="has-session"\ntmux has-session\n```', trips: /carries no text of its own/ },
{ name: 'an excerpt of a block the page does not have', page: attach, find: 'excerpt="send-command.sh" from="has-session"', replace: 'excerpt="other.sh" from="has-session"', trips: /no code block titled "other\.sh"/ },
{ name: 'a Go excerpt of a file missing from the example cache', page: goAttach, find: 'file="examples/pane-io/main.go" from="ctx, cancel', replace: 'file="examples/gone/main.go" from="ctx, cancel', trips: /examples\/gone\/main\.go is not in the go example cache/ },
{ name: 'a Go excerpt of a file missing from the example cache', page: goAttach, find: '```go file="examples/pane-io/main.go" from="', replace: '```go file="examples/gone/main.go" from="', trips: /examples\/gone\/main\.go is not in the go example cache/ },
{ name: 'a port page linking itself as its native version', page: goAttach, find: '](/tmux/examples/attach-and-send-keys/)', replace: '](/examples/attach-and-send-keys/)', trips: /links to the page itself/ },
{ name: 'a Go file inclusion missing from the example cache', page: goAttach, find: '```go file="examples/pane-io/main.go" height="24"\n```', replace: '```go file="examples/gone/main.go" height="24"\n```', trips: /examples\/gone\/main\.go is not in the example cache/ },
]
Expand Down
19 changes: 11 additions & 8 deletions site/src/content/docs/ports/go/examples/attach-and-send-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ the same sequence in shell. [Source](#where-this-comes-from) names the file.
Every call that reaches tmux takes a `context.Context`. The program gives the
whole run 30 seconds, so a wait that never matches ends with
`context.DeadlineExceeded` instead of blocking forever. `tmux.NewServer`
validates a `tmux.ServerOptions` and does not start tmux.
configures a server handle. The first session starts tmux if the selected
server is absent.
`ServerOptions.SocketName` selects a named socket, like `-L`, and
`ServerOptions.ConfigFile` set to `os.DevNull` keeps your tmux configuration
file out, like `-f /dev/null`. Choose a socket name that no other tmux uses,
because [cleanup](#8-clean-up) ends the server on that socket. With an unused
name, the program neither touches nor is changed by the tmux you already use.
`ServerOptions.SocketPath` selects a socket by path, like `-S`.
Use a socket dedicated to the example so [cleanup](#8-clean-up) affects only
its own server. Setting `ServerOptions.ConfigFile` to `os.DevNull` keeps your
tmux configuration out, like `-f /dev/null`.
The native step is
[Choose a private socket](/tmux/examples/attach-and-send-keys/#1-choose-a-private-socket).
The server goes to `run`, so a test can pass in an isolated one.

```go file="examples/pane-io/main.go" from="ctx, cancel := context.WithTimeout" to="return run(ctx, server)"
```go file="examples/pane-io/main.go" from="server, err := tmux.NewServer" to="return run(ctx, server)"
```

<span id="2-find-or-create-the-session" data-inventory-category="heading" data-inventory-display="2. Find or create the session"></span>
Expand Down Expand Up @@ -138,9 +139,11 @@ then the session is killed. The kill uses a context of its own that the run's
cancellation cannot end, with one second to finish, so a deadline that has
passed does not skip the cleanup, and `errors.Join` reports a cleanup failure
beside the original error. With the default `exit-empty` setting, the private
server exits when its last session is gone.
server exits when its last session is gone. When the example owns a socket
directory, it also defers stopping its server. It removes the directory once
the stop succeeds or tmux reports the server is already gone.

```go file="examples/pane-io/main.go" from="=\tdefer func() {" to="=\t}()"
```go file="examples/pane-io/main.go" from="cleanupCtx, cleanupCancel := context.WithTimeout" to="err = errors.Join(err, session.Kill(cleanupCtx))"
```

<span id="setup-and-run" data-inventory-category="heading" data-inventory-display="Setup and run"></span>
Expand Down
14 changes: 7 additions & 7 deletions site/src/data/mentions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6125,13 +6125,6 @@
"title": "Server, session, window, pane",
"section": "concepts"
},
{
"port": "go",
"symbol": "tmux.ServerOptions",
"page": "/go/latest/examples/attach-and-send-keys/",
"title": "Attach and send keys",
"section": "examples"
},
{
"port": "go",
"symbol": "tmux.ServerOptions",
Expand Down Expand Up @@ -6167,6 +6160,13 @@
"title": "Socket and servers",
"section": "topics"
},
{
"port": "go",
"symbol": "tmux.ServerOptions.SocketPath",
"page": "/go/latest/examples/attach-and-send-keys/",
"title": "Attach and send keys",
"section": "examples"
},
{
"port": "go",
"symbol": "tmux.ServerOptions.SocketPath",
Expand Down
Loading