Server.GetWindowsAsync
Reads every window on this server.
Source and package
- Qualified name
-
LibTmux .Server. Get Windows Async - Namespace
- LibTmux
- Declared in
Server- Package
- LibTmux
- Source
- src/LibTmux/Server.Collections.cs
- Task<IRead
Only <Window>> GetWindowsAsync( CancellationList Token cancellationToken = default ) -
- Parameters
-
-
cancellationToken(CancellationToken ) – Cancels the tmux command.Default
default
-
- Returns
-
The windows reported by a successful read.
- Errors
-
-
Lib
Tmux – The listing failed, including an absent daemon.Exception
-
Examples
Read scalar listings from two detached sessions on a private server. Fresh rows do not imply captured child relations. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as
Example.csproj. It references the 0.1.1 release ofLibTmuxon NuGet: View sourceExample.csproj <Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFrameworks>net8.0;net10.0</TargetFrameworks><LangVersion>12.0</LangVersion><Nullable>enable</Nullable><ImplicitUsings>disable</ImplicitUsings><EnableDefaultCompileItems>false</EnableDefaultCompileItems><TreatWarningsAsErrors>true</TreatWarningsAsErrors><AnalysisLevel>10-recommended</AnalysisLevel></PropertyGroup><ItemGroup><Compile Include="Program.cs" /><PackageReference Include="LibTmux" Version="[0.1.1]" /></ItemGroup></Project>Save this complete program as
Program.cs. It creates a private server;await usingdisposes its owned scopes after success, cancellation or failure. The complete file contains explicit imports, a top-level async entry point and a cancellation deadline. View sourceProgram.csComplete program using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading;using LibTmux;if (OperatingSystem.IsWindows()){throw new PlatformNotSupportedException("This example requires tmux on Linux or macOS.");}using CancellationTokenSource deadline = new(TimeSpan.FromSeconds(10));CancellationToken token = deadline.Token;string? testTmux = Environment.GetEnvironmentVariable("LIBTMUX_TEST_TMUX");string? configured = !string.IsNullOrWhiteSpace(testTmux)? testTmux: Environment.GetEnvironmentVariable("LIBTMUX_TMUX");string binary = string.IsNullOrWhiteSpace(configured) ? "tmux" : configured;using TemporaryDirectory socketRoot = new();ServerConnectionOptions options = new(){SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null",TmuxBinaryPath = binary,};await using OwnedServerScope owned = await Server.CreateOwnedAsync(options, token);await using OwnedSessionScope demo = await owned.Value.CreateOwnedSessionAsync(new NewSessionRequest { Name = "demo", Command = "/bin/cat" }, token);await using OwnedSessionScope worker = await owned.Value.CreateOwnedSessionAsync(new NewSessionRequest { Name = "worker", Command = "/bin/cat" }, token);Server server = await Server.ConnectAsync(options, token);IReadOnlyList<Session> sessions = await server.GetSessionsAsync(token);IReadOnlyList<Window> windows = await server.GetWindowsAsync(token);IReadOnlyList<Pane> panes = await server.GetPanesAsync(token);IReadOnlyList<Client> clients = await server.GetClientsAsync(token);if (sessions.Count != 2 || windows.Count != 2 || panes.Count != 2 || clients.Count != 0){throw new InvalidOperationException("Expected two detached sessions, each with one window and pane.");}if (sessions.Any(session => session.Windows.IsCaptured)){throw new InvalidOperationException("Scalar listings must not imply captured child relations.");}foreach (Session session in sessions.OrderBy(session => session.Name, StringComparer.Ordinal)){Console.WriteLine($"Session: {session.Name} ({session.Id})");}Console.WriteLine($"Windows: {windows.Count}; panes: {panes.Count}; clients: {clients.Count}");internal sealed class TemporaryDirectory : IDisposable{private readonly DirectoryInfo _directory = Directory.CreateTempSubdirectory("libtmux-example-");public string FullName => _directory.FullName;public void Dispose() => _directory.Delete(recursive: true);}Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:
Terminal window $ dotnet build Example.csproj --configuration Release && \dotnet bin/Release/net8.0/Example.dll && \dotnet bin/Release/net10.0/Example.dllExpected program output from each framework:
Session: demo ($0)Session: worker ($1)Windows: 2; panes: 2; clients: 0
Recorded calls
source callsThe C# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.Server.GetWindowsAsync.
tmux command
task materialThe tmux commands behind GetWindowsAsync.
list-windows -a server scope, cmd_list_windows_exec tmux C API
task materialThe C declarations in tmux that implement these commands.