Skip to main content
Extensions can create, manage, and interact with terminal sessions. The terminal system runs on Klyx’s internal PRoot-based Linux environment, giving plugins access to a full shell ecosystem.

TerminalManager

The TerminalManager exposes two subsystems plus helpers for opening the terminal:

Running a command

Use runInTerminal to open the terminal and execute a command directly. The command runs in a fresh session — no login shell, prompt, or MOTD, only the command’s stdout/stderr and stdin. The session’s stdin is wired to the terminal, so interactive prompts are answerable by the user:
If the terminal environment isn’t installed yet, the terminal screen opens so the user can complete the setup first.

Opening an interactive shell

Use openTerminal to open the terminal screen. When no session is active, an interactive login shell is created automatically so the user can type commands directly:
For a guaranteed fresh shell even when other sessions exist, pass an interactive command to runInTerminal:

TerminalSessionManager

Manages the lifecycle of terminal sessions. All state is exposed via StateFlow.

Session state

Creating sessions

Getting or creating a session

Switching and terminating

TerminalSessionEntry

TerminalSessionClient

When creating a session, you provide a TerminalSessionClient callback interface. This class is defined in the terminal module (com.klyx.terminal.emulator.TerminalSessionClient), not in the klyx-api module. It receives notifications about text changes, title changes, session completion, bell events, color changes, and more. The TerminalSessionClient interface exposes the following callbacks: Additionally, the terminalCursorStyle property can be set to control the cursor appearance.

TerminalSessionBinder

Manages the binding lifecycle between the app and the background terminal service.

Terminal environment utilities

These functions are available in the com.klyx.api.terminal package:
terminalEnv() sets TERM, TERM_PROGRAM, COLORTERM, HOSTNAME, TMPDIR, LANG, and LC_ALL. processEnv() configures PROOT_LOADER, PROOT_TMP_DIR, HOME, ROOTFS, PATH, and passes through relevant Android system environment variables.

Terminal paths

Terminal-specific paths are available as extensions on Paths:
Native PRoot library paths:

CursorStyle

The terminal cursor style enum (used in settings and client callback):

Example

Create a terminal session with a custom client: