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-ts latest

Server.windows

Every window on the server, including each placement of a linked window.

Source and package
Qualified name
Server.windows
Module
server
Declared in
Server
Package
libtmux
Source
packages/libtmux/src/server.ts
Other languages
PowerShellcmdlet Juliafunction Elixirfunction PythonRubyLuaRustGoJavaC#C++SwiftKotlinScalaF#function
async windows(): Promise<Selection<Window>>

Description#

Save this complete program as windows.ts. With Bun 1.4.2 or newer, tmux 3.2a or newer, and libtmux installed, run bun run windows.ts. It creates and stops a private tmux server. A failed operation or cleanup exits with an error; a cleanup error names the retained socket directory.

Examples#

import { strict as assert } from "node:assert";
import { mkdtemp, readdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Server, MultipleMatchesError } from "libtmux";
const directory = await mkdtemp(join(tmpdir(), "ltx-example-"));
const server = new Server({
socketPath: join(directory, "tmux.sock"),
configFile: "/dev/null",
timeoutMs: 5_000,
});
const failures: unknown[] = [];
try {
const session = await server.newSession({
name: "home",
windowName: "editor",
shellCommand: "cat",
});
const guest = await server.newSession({
name: "guest",
windowName: "shell",
shellCommand: "cat",
});
const window = await session.newWindow({ name: "logs", shellCommand: "cat" });
await window.link({ session: guest });
const windows = await server.windows();
const logs = windows.where({ name: "logs" });
assert.equal(logs.count(), 2);
console.log("logs placements:", logs.count());
try {
logs.one();
throw new Error("Expected a linked window lookup to be ambiguous");
} catch (error) {
if (!(error instanceof MultipleMatchesError)) throw error;
console.log("ambiguous:", error.code);
}
const placed = logs.one({ session: { is: { name: "home" } } });
assert.equal(placed.id, window.id);
console.log("selected placement:", placed.session?.name);
console.log(
"linked sessions:",
placed.linkedSessions
.map((item) => item.name)
.sort()
.join(", "),
);
} catch (error) {
failures.push(error);
} finally {
try {
if ((await readdir(directory)).includes("tmux.sock")) await server.kill();
await rm(directory, { recursive: true });
} catch (error) {
failures.push(new Error(`Cleanup failed; inspect ${directory}`, { cause: error }));
}
}
if (failures.length > 0) throw new AggregateError(failures, "Example failed");

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.
Elixir LibTmux.Snapshot.windows/1 Returns a Selection of every captured physical window. window_links/1 lists session placements.
Rust server.Server.windows
Go tmux.Server.Windows
Java io.github.libtmux.Server.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()
Esc

Type to search.

Reference previewOpen reference