Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-go latest

Server.Windows

Windows materializes one record per winlink. Failures, including ErrNoServer, remain errors rather than empty results.

Source and package
Qualified name
tmux.Server.Windows
Package
tmux
Declared in
Server
Distribution
github.com/libtmux/libtmux-go/tmux
Source
tmux/hierarchy.go
Other languages
Perlmethod Erlangfunction PowerShellcmdlet Juliafunction Elixirfunction Haskell Common Lispfunction PythonRubyLuaTypeScriptRustJavaC#C++SwiftKotlinScalaOCamlfunction F#function Clojurefunction
func (s Server) Windows( ctx context.Context, ) ([]Window, error)

Examples#

List windows across every session on a private server. Each record is a winlink: linking one window into two sessions produces two records. This example gives each session one independently created window. Use Go 1.26 or newer and tmux 3.3a or newer on a Unix system, with tmux and cat on PATH. In a new directory, create a module and add the library from the Go module proxy:

Terminal window
$ go mod init example.com/libtmux-api && \
go get github.com/libtmux/libtmux-go@latest

Save this complete example as example_test.go. It creates a private temporary socket and stops its server before removing the directory. Cleanup failure fails the example and retains the socket directory. View source

package tmux_test
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"slices"
"time"
"github.com/libtmux/libtmux-go/tmux"
)
// List windows across every session on a private server. Each record is a
// winlink: linking one window into two sessions produces two records.
// This example gives each session one independently created window.
func ExampleServer_Windows_complete() {
run := func() (runErr error) {
directory, err := os.MkdirTemp("", "libtmux-go-api-")
if err != nil {
return fmt.Errorf("create socket directory: %w", err)
}
server, err := tmux.NewServer(tmux.ServerOptions{
SocketPath: filepath.Join(directory, "tmux.sock"),
ConfigFile: "/dev/null",
})
if err != nil {
return errors.Join(err, os.RemoveAll(directory))
}
defer func() {
// Cleanup has its own deadline because the operation may have timed out.
cleanup, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Kill(cleanup); err != nil && !errors.Is(err, tmux.ErrNoServer) {
runErr = errors.Join(runErr, fmt.Errorf("stop server at %s: %w", directory, err))
return
}
runErr = errors.Join(runErr, os.RemoveAll(directory))
}()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for _, name := range []string{"work", "docs"} {
if _, err = server.NewSession(ctx, tmux.NewSessionRequest{
Name: name, WindowName: name + "-editor", Command: "cat", Width: 100, Height: 30,
}); err != nil {
return fmt.Errorf("create %s session: %w", name, err)
}
}
windows, err := server.Windows(ctx)
if err != nil {
return fmt.Errorf("list windows: %w", err)
}
names := make([]string, 0, len(windows))
for _, window := range windows {
name, ok := window.Name()
if !ok {
return fmt.Errorf("window %s has no name", window.ID())
}
names = append(names, name)
}
slices.Sort(names)
fmt.Println(names)
return nil
}
if err := run(); err != nil {
panic(err)
}
// Output:
// [docs-editor work-editor]
}

Run the saved file. Go checks the Output comment and fails on different output or an operation or cleanup error:

Terminal window
$ go test -count=1 -v example_test.go
Parameters

Guides#

Pages that discuss Windows.

In other ports#

List the server's windows

Equivalents of List the server's windows in other languages
Language Equivalent
Python libtmux.Server.windows
Ruby LibTmux::Server#list_windows
Lua libtmux.Snapshot.windows
PowerShell LibTmux\Get-TmuxWindow Use the -Server parameter set to acquire window placements across all sessions.
Julia LibTmux.windows windows with a Snapshot reads every captured physical window. Use windowlinks for session placements.
Erlang tmux_snapshot:windows/1 Returns unique captured physical windows. window_links/1 lists session memberships.
Elixir LibTmux.Snapshot.windows/1 Returns a Selection of every captured physical window. window_links/1 lists session placements.
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
Common Lisp libtmux:windows windows on a snapshot returns captured physical windows once each.
TypeScript server.Server.windows
Rust server.Server.windows
Java io.github.libtmux.Server.windows
Clojure libtmux.core/windows! Acquires a new graph and returns its window placements without deduplicating linked windows.
Kotlin io.github.libtmux.kotlin.Server.windows
Scala io.github.libtmux.scaladsl.Server.windows
C# LibTmux.Server.Windows
F# LibTmux.FSharp.Server.windows Builds a deferred query for placements across all sessions. Query.list acquires the results; a linked window appears once for each session placement.
C++ libtmux::Server::windows
Swift Server.windows()
OCaml Libtmux.Snapshot.windows Reads captured global windows; use window_links for indexed session placements.
Perl LibTmux::Snapshot::windows One entry per physical identity. window_links retains all session placements.
Esc

Type to search.

Reference previewOpen reference