diff --git a/site/src/content/docs/ports/cxx/guides/attaching-to-tmux.md b/site/src/content/docs/ports/cxx/guides/attaching-to-tmux.md index f9550dabb..835fdeb0c 100644 --- a/site/src/content/docs/ports/cxx/guides/attaching-to-tmux.md +++ b/site/src/content/docs/ports/cxx/guides/attaching-to-tmux.md @@ -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, @@ -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++ \ @@ -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 diff --git a/site/src/data/mentions.json b/site/src/data/mentions.json index 9f6685775..0bb2886cb 100644 --- a/site/src/data/mentions.json +++ b/site/src/data/mentions.json @@ -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", @@ -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", diff --git a/site/test/fixtures/attach-examples.json b/site/test/fixtures/attach-examples.json index 7cc55341f..d6585e16d 100644 --- a/site/test/fixtures/attach-examples.json +++ b/site/test/fixtures/attach-examples.json @@ -179,7 +179,7 @@ { "port": "cxx", "language": "cpp", - "sourceRevision": "393d4b0ad666f18a6581f1eb281741a75a7503f0", + "sourceRevision": "e4766b2870c055bd73b2e1cf6b5f21caad59279b", "sourceRepository": "libtmux/libtmux-cxx", "toolchain": [ "Clang 18", @@ -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", @@ -203,7 +203,7 @@ ], "tmux": [ "3.3a", - "3.7c" + "3.8" ] }, {