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
30 changes: 15 additions & 15 deletions site/src/content/docs/ports/cxx/guides/attaching-to-tmux.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ namespace fs = std::filesystem;
void find_work(const std::string& socket) {
auto server = libtmux::Server::at_socket_path(socket);
if (!server) throw std::runtime_error(server.error().diagnostic);
auto sessions = server->sessions();
if (!sessions) throw std::runtime_error(sessions.error().diagnostic);
for (const auto& session : *sessions) {
if (session.name() == "work") {
std::cout << "work\n";
return;
}
}
throw std::runtime_error("The work session does not exist");
const auto session = server->session("=work:");
if (!session) throw std::runtime_error(session.error().diagnostic);
std::cout << session->name() << '\n';
}

// Stops the private server and removes its directory when it leaves scope,
Expand Down Expand Up @@ -135,11 +129,11 @@ target_compile_features(connect PRIVATE cxx_std_23)
target_link_libraries(connect PRIVATE libtmux::libtmux)
```

Fetch the verified library revision, build, and run:
Build and run with the verified v0.1.1 revision:

```console
$ git clone https://github.com/libtmux/libtmux-cxx libtmux-source &&
git -C libtmux-source checkout 393d4b0ad666f18a6581f1eb281741a75a7503f0 &&
git -C libtmux-source checkout e4766b2870c055bd73b2e1cf6b5f21caad59279b &&
cmake -S . -B build -G Ninja \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_FLAGS=-stdlib=libc++ \
Expand All @@ -156,10 +150,16 @@ leaves that server running.

## Find or create a session

The example only looks up a session. If your application creates a session
after an unsuccessful lookup, another client may create the same name between
those operations. Handle the creation error instead of assuming the lookup
reserves the name.
`server->session("=work:")` looks up the literal name `work`. With only
`workshop` running, `server->session("work")` can select it by prefix.
Create `work` only when the lookup reports `FailureKind::missing`. If another
client creates it first and your application can adopt that session, look up
the exact name again. Report other command failures to the caller.

To follow a rename, copy the session ID with
`std::string id{session->id().value()}` and look it up on the same server.
A replacement daemon can reuse that ID. An application resuming saved work
can check its own session-local marker before adopting the session.

For a complete program that starts and owns its server, see
[Capture pane output](/examples/capture-pane-output/). Continue with
Expand Down
14 changes: 14 additions & 0 deletions site/src/data/mentions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,13 @@
"title": "Filtering and queries",
"section": "concepts"
},
{
"port": "cxx",
"symbol": "libtmux::FailureKind::missing",
"page": "/cxx/latest/guides/attaching-to-tmux/",
"title": "Attaching to tmux",
"section": "guides"
},
{
"port": "cxx",
"symbol": "libtmux::FilterExpr",
Expand Down Expand Up @@ -2212,6 +2219,13 @@
"title": "Socket and servers",
"section": "topics"
},
{
"port": "cxx",
"symbol": "libtmux::Server::session",
"page": "/cxx/latest/guides/attaching-to-tmux/",
"title": "Attaching to tmux",
"section": "guides"
},
{
"port": "cxx",
"symbol": "libtmux::Server::sessions",
Expand Down
8 changes: 4 additions & 4 deletions site/test/fixtures/attach-examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
{
"port": "cxx",
"language": "cpp",
"sourceRevision": "393d4b0ad666f18a6581f1eb281741a75a7503f0",
"sourceRevision": "e4766b2870c055bd73b2e1cf6b5f21caad59279b",
"sourceRepository": "libtmux/libtmux-cxx",
"toolchain": [
"Clang 18",
Expand All @@ -188,13 +188,13 @@
],
"page": "ports/cxx/guides/attaching-to-tmux",
"shellRecipe": [
"git clone https://github.com/libtmux/libtmux-cxx libtmux-source &&\n git -C libtmux-source checkout 393d4b0ad666f18a6581f1eb281741a75a7503f0 &&\n cmake -S . -B build -G Ninja \\\n -DCMAKE_CXX_COMPILER=clang++ \\\n -DCMAKE_CXX_FLAGS=-stdlib=libc++ \\\n -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ &&\n cmake --build build --target connect --parallel 2 &&\n ./build/connect"
"git clone https://github.com/libtmux/libtmux-cxx libtmux-source &&\n git -C libtmux-source checkout e4766b2870c055bd73b2e1cf6b5f21caad59279b &&\n cmake -S . -B build -G Ninja \\\n -DCMAKE_CXX_COMPILER=clang++ \\\n -DCMAKE_CXX_FLAGS=-stdlib=libc++ \\\n -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ &&\n cmake --build build --target connect --parallel 2 &&\n ./build/connect"
],
"expectedOutput": "work",
"files": [
{
"name": "connect.cpp",
"sha256": "54360d06c83b14a8db4994f72ec23dadd7458e237a65da3424d54ede79f845b3"
"sha256": "51522e6608c6e304da0f8d4b54dca2c97201958da5f6f7a70363da397a8e573a"
},
{
"name": "CMakeLists.txt",
Expand All @@ -203,7 +203,7 @@
],
"tmux": [
"3.3a",
"3.7c"
"3.8"
]
},
{
Expand Down
Loading