Core Library0.xAPI reference

Choose documentation 1

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.

MoreLess about this notice

method libtmux-kotlin

Server.newSession

Creates a detached session and returns that exact session.

Source and package
Qualified name
io.github.libtmux.kotlin.Server.newSession
Package
io.github.libtmux.kotlin
Declared in
Server
Distribution
io.github.libtmux:libtmux-kotlin
Source
libtmux-kotlin/build/generated/sources/operations/kotlin/io/github/libtmux/kotlin/ServerOperations.kt
public Kotlin suspending functionsAllows a function to call suspending operations and pause without blocking a thread. It does not start a coroutine by itself.Language documentation fun Server.newSession(name: String): Sessionpublic Kotlin suspending functionsAllows a function to call suspending operations and pause without blocking a thread. It does not start a coroutine by itself.Language documentation fun Server.newSession( spec: SessionSpec ): Sessionpublic Kotlin suspending functionsAllows a function to call suspending operations and pause without blocking a thread. It does not start a coroutine by itself.Language documentation fun Server.newSession( configure: SessionBuilder.() -> Unit ): Session
Parameters
Errors
  • IllegalArgumentException – if the session and its first window block both set a directory, or both set a command: tmux has one of each for that window for newSession(configure)

Examples

Create a session running cat. Use JDK 25, Gradle 9 or newer, and tmux 3.3a or newer on Linux, with /bin/cat and /bin/sh available. In an empty directory, save this consumer setup as settings.gradle.kts:

rootProject.name = "api-example"

Save this consumer setup as build.gradle.kts. It depends on the 0.1.2 release from Maven Central:

plugins {
kotlin("jvm") version "2.4.10"
application
}
repositories { mavenCentral() }
dependencies {
implementation("io.github.libtmux:libtmux-kotlin:0.1.2")
}
java { toolchain { languageVersion.set(JavaLanguageVersion.of(25)) } }
kotlin { jvmToolchain(25) }
application { mainClass.set(providers.gradleProperty("exampleMain")) }

Save this consumer setup as gradle.properties: View source

gradle.properties
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8
kotlin.daemon.jvmargs=-Xmx2g
org.gradle.workers.max=2

Save this complete program as src/main/kotlin/NewSession.kt. It starts a private tmux server of its own and stops it when the program closes it. View source

src/main/kotlin/NewSession.ktComplete program
package io.github.libtmux.examples.api.kotlin
import io.github.libtmux.SessionSpec
import io.github.libtmux.kotlin.*
import kotlin.system.exitProcess
import kotlinx.coroutines.runBlocking
/** Create a session running cat. */
fun main() {
try {
runBlocking {
withPrivateServer { server ->
val session = server.newSession(
SessionSpec.builder().named("api-session").running("/bin/cat").build()
)
println("created=${session.name}")
}
}
} catch (error: Exception) {
if (error is InterruptedException) Thread.currentThread().interrupt()
System.err.println("Example failed: ${error.message}")
exitProcess(1)
}
}

Build the minimal consumer with Gradle and run the saved program. An operation or cleanup error makes the command exit unsuccessfully:

Terminal window
$ gradle --console=plain --quiet installDist -PexampleMain=io.github.libtmux.examples.api.kotlin.NewSessionKt && \
build/install/api-example/bin/api-example

Expected output:

created=api-session

Recorded calls

source calls
No call edges in the Kotlin model.

The Kotlin 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 io.github.libtmux.kotlin.Server.newSession.

tmux command

task material

The tmux commands behind newSession.

tmux C API

task material

The C declarations in tmux that implement these commands.

Each path starts at a function a command runs, which is degree 1. The degree counts steps from there along the path, and each step is a call or a reference: degree 2 is reached from that function, degree 3 from the next, and so on.

Create a session and its first pane

  1. 1 cmd_new_session_exec
  2. calls → 2 spawn_window
  3. calls → 3 spawn_pane
  4. calls → 4 window_add_pane
  5. calls → 5 window_pane_create

Guides

task material

Pages that discuss newSession.

In other ports

task equivalence 16 other ports mapped

Source-verified mappings for Create a session. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.

Create a session in each port
PortAPIDiffers from Kotlin
Kotlin io.github.libtmux.kotlin.Server.newSession
Creates a detached session and returns that exact session.
This page
Python libtmux.Server.new_session
Create new session, returns new Session.
None recorded in the model
Ruby LibTmux::Server#new_session
Behavior: Creation.
None recorded in the model
Lua libtmux.Server:new_session None recorded in the model
Erlang tmux_session:create/2
Create a detached session by default and explicitly observe the returned row. Options include name, window_name, dimensions, cwd, env and launch. Performs I/O; an observation failure after successful creation retains mutation = completed and the original command result. Existing names are not adopted.
free function
TypeScript server.Server.newSession
Create a detached session and resolve it as a handle.
None recorded in the model
Rust server.Server.new_session
Create a detached session and return it.
None recorded in the model
Go tmux.Server.NewSession
NewSession creates a detached session, then returns a newly materialized Session. It never changes client focus. KillExisting is not rolled back; transport and context failures may be delivery-ambiguous.
None recorded in the model
Java io.github.libtmux.Server.newSession
Creates a detached session and returns that exact session.
None recorded in the model
Clojure libtmux.core/new-session!
Creates a detached session and returns a fresh captured session map.
free function
Scala io.github.libtmux.scaladsl.Server.newSession
Creates a detached session and returns that exact session.
None recorded in the model
C# LibTmux.Server.CreateSessionAsync
Creates a session.
None recorded in the model
C++ libtmux::Server::new_session
Created detached, and returned, because tmux prints what it made.
readonly
Swift Server.newSession(named:startDirectory:windowName:width:height:environment:shell:)
Creates a detached session.
None recorded in the model
OCaml Libtmux_unix.Client.create_session
Create a detached session on the bound daemon. Name collisions fail.
free function
Perl LibTmux::Server::new_session
new_session(name => string, command => arrayref?, shell_command => string?, width => integer?, height => integer?, cwd => bytes?, environment => hashref?).
Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes.
Raku LibTmux::Server.new-session
Create a detached session and return its value-only, identity-scoped reference.
None recorded in the model
No Haskell equivalent.

No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.

No equivalent is recorded in PowerShell, Julia, Elixir, Common Lisp or F#.

Esc
Search in

Type to search.

Reference previewOpen reference