Session.newWindow
Creates a window in this session and returns that exact window.
Source and package
- Module
- io.github.libtmux.scaladsl.cats
- Declared in
- Session
- Package
- io.github.libtmux:libtmux-scala_3
- Source
- libtmux-scala-cats/build/generated/sources/catalog/scala/operations/GeneratedOperations.scala
- Other languages
- PythonRubyLuaTypeScriptRustGoJavaC#C++SwiftKotlin F#
- Scala extension methods Adds methods callable on the receiver type without changing its definition. Language documentation [F[_]](self: Session[F])(using F: _root_
.cats [F]) Scala method declarations Declares a method, with its name, parameter lists and return type. Language documentation newWindow(name: String): F[Window[F]] Scala extension methods Adds methods callable on the receiver type without changing its definition. Language documentation [F[_]](self: Session[F])(using F: _root_.effect .Async .cats [F]) Scala method declarations Declares a method, with its name, parameter lists and return type. Language documentation newWindow(configure: io.effect .Async .github => Unit): F[Window[F]] Scala extension methods Adds methods callable on the receiver type without changing its definition. Language documentation [F[_]](self: Session[F])(using F: _root_.libtmux .Window Spec .Builder .cats [F]) Scala method declarations Declares a method, with its name, parameter lists and return type. Language documentation newWindow(spec: io.effect .Async .github ): F[Window[F]].libtmux .Window Spec -
Examples#
Create a window and read the updated session. Use JDK 25, Git, and tmux 3.2a through 3.7c on Linux, with /bin/cat and /bin/sh available. In an empty directory, fetch the documented library revision:
Terminal window $ git clone https://github.com/libtmux/libtmux-java.git libtmux-source && \git -C libtmux-source checkout f56392b5d9bc7f1f9c1631842333fb90f3d82d40Save this consumer setup as settings.gradle.kts: View source
rootProject.name = "api-example"includeBuild("libtmux-source") {dependencySubstitution {substitute(module("io.github.libtmux:libtmux-scala-cats_3")).using(project(":libtmux-scala-cats"))}}Save this consumer setup as build.gradle.kts: View source
plugins {scalaapplication}repositories { mavenCentral() }dependencies {implementation("io.github.libtmux:libtmux-scala-cats_3:0.0.1-alpha.17-SNAPSHOT")implementation("org.scala-lang:scala3-library_3:3.9.0")}java { toolchain { languageVersion.set(JavaLanguageVersion.of(25)) } }application { mainClass.set(providers.gradleProperty("exampleMain")) }Save this consumer setup as gradle.properties: View source
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8kotlin.daemon.jvmargs=-Xmx2gorg.gradle.workers.max=2Save this launcher as run.sh. It creates and stops a private tmux server, including after program failure. A shutdown failure retains its socket directory and exits unsuccessfully. View source
#!/bin/shset -euif [ "$#" -eq 0 ]; thenprintf 'Usage: sh run.sh program [arguments...]\n' >&2exit 2fibinary=$(command -v "${TMUX_BIN:-tmux}")mkdir -p /tmp/libtmux-java-devdirectory=$(mktemp -d /tmp/libtmux-java-dev/api.XXXXXX)socket="$directory/tmux.sock"config="$directory/tmux.conf"alive() {"$binary" -S "$socket" display-message -p '#{pid}' >/dev/null 2>&1}cleanup() {status=$?trap - 0 HUP INT TERMif alive; thenif ! "$binary" -S "$socket" kill-server; thenprintf 'Cannot stop tmux; kept %s\n' "$directory" >&2exit 1fiattempts=0while alive && [ "$attempts" -lt 100 ]; dosleep 0.05attempts=$((attempts + 1))doneif alive; thenprintf 'tmux is still responding; kept %s\n' "$directory" >&2exit 1fifirm -rf "$directory" || exit 1exit "$status"}trap cleanup 0trap 'exit 1' HUP INT TERMunset TMUX TMUX_PANEprintf 'set-option -g default-shell /bin/sh\n' > "$config""$binary" -S "$socket" -f "$config" new-session -d -s work-one -n editor /bin/cat"$binary" -S "$socket" split-window -h -t '=work-one:editor' /bin/cat"$binary" -S "$socket" new-window -d -t '=work-one' -n logs /bin/cat"$binary" -S "$socket" new-session -d -s work-two -n editor /bin/cat"$@" "$binary" "$socket" "$config""$binary" -S "$socket" has-session -t '=work-one'"$binary" -S "$socket" has-session -t '=work-two'Save this complete program as src/main/scala/NewWindow.scala. It opens an ordinary client for the launcher's server; closing the client releases its transport. View source
package io.github.libtmux.examples.api.scalacatsimport io.github.libtmux.{ServerConfig, ServerEndpoint, WindowSpec}import java.nio.file.Pathimport io.github.libtmux.scaladsl.cats.*import _root_.cats.effect.{ExitCode, IO, IOApp}import _root_.cats.syntax.all.*/** Create a window and read the updated session. */object NewWindow extends IOApp {def run(args: List[String]): IO[ExitCode] = {val program = IO {require(args.length == 3, "expected: tmux-binary socket-path config-file")ServerConfig.builder().binary(args(0)).endpoint(ServerEndpoint.socketPath(Path.of(args(1)))).configFile(Path.of(args(2))).build()}.flatMap { config =>Server.resource[IO](config).use { server =>for {found <- server.session("work-one")session <- IO.fromOption(found)(new IllegalStateException("missing work-one"))window <- session.newWindow(WindowSpec.builder().named("api-window").running("/bin/cat").build())_ <- IO.println(s"created=${window.name}")updated <- server.session("work-one")refreshed <- IO.fromOption(updated)(new IllegalStateException("missing work-one"))_ <- IO.println("windows=" + refreshed.windows.map(_.name).sorted.mkString(","))} yield ()}}program.as(ExitCode.Success).handleErrorWith { error =>IO(System.err.println("Example failed: " + error.getMessage)).as(ExitCode.Error)}}}Build the minimal consumer and run the saved program with the private fixture. An operation or cleanup error makes the command exit unsuccessfully:
Terminal window $ ./libtmux-source/gradlew --project-dir . --console=plain --quiet \installDist -PexampleMain=io.github.libtmux.examples.api.scalacats.NewWindow && \sh run.sh build/install/api-example/bin/api-exampleExpected output:
created=api-windowwindows=api-window,editor,logs- Parameters
-
-
name ( String ) (for
newWindow(name)) -
configure ( io
.github => Unit ) (for.libtmux .Window Spec .Builder newWindow(configure)) -
spec ( io
.github ) (for.libtmux .Window Spec newWindow(spec))
-
tmux command
new-windowIn other ports Create a window
- Python
libtmux.Session.new_window - Ruby
LibTmux::Session#new_window - Lua
libtmux.Session:new_window - TypeScript
session.Session.newWindow - Rust
session.Session.new_window - Go
tmux.Session.NewWindow - Java
io.github.libtmux.Session.newWindow - C#
LibTmux.Session.CreateWindowAsync - C++
libtmux::Session::new_window - Swift
Server.newWindow(in:named:startDirectory:at:environment:shell:) - Kotlin
io.github.libtmux.kotlin.Session.newWindow - F# No source-verified F# equivalent is recorded for this operation.