Skip to content

Latest commit

 

History

History
113 lines (75 loc) · 1.93 KB

File metadata and controls

113 lines (75 loc) · 1.93 KB

API Reference

TerminalManager

Singleton that manages all terminal sessions.

spawn(options?)

Create a new terminal session.

const session = TerminalManager.spawn({
  shell: '/bin/zsh',      // Shell to use (default: $SHELL or /bin/bash)
  cwd: '/path/to/dir',    // Working directory
  cols: 120,              // Terminal width (default: 80)
  rows: 40,               // Terminal height (default: 24)
  env: { FOO: 'bar' },    // Additional environment variables
  visible: true,          // Open terminal window (requires tmux)
});

get(sessionId)

Get session by ID. Returns undefined if not found.

getOrThrow(sessionId)

Get session by ID. Throws if not found.

list()

List all sessions. Returns SessionInfo[].

destroy(sessionId)

Destroy a session by ID. Returns boolean.

destroyAll()

Destroy all sessions.


Session Methods

write(data)

Send raw input to terminal.

session.write('ls -la\n');
session.write('\x03');  // Ctrl+C

read(options?)

Read output buffer.

const output = session.read();
const lastLines = session.read({ lines: 10 });
const cleared = session.read({ clear: true });

runCommand(command, options?)

Execute command and wait for completion.

const result = await session.runCommand('npm install', {
  timeout: 60000,
  waitFor: /\$\s*$/,  // Custom prompt pattern
});
// result: { output: string, completed: boolean }

waitFor(pattern, options?)

Wait for pattern in output.

await session.waitFor(/Password:/);
session.write('secret\n');

resize(cols, rows)

Resize terminal.

kill()

Kill the session.

openWindow()

Open terminal window (visible sessions only).


SessionInfo

interface SessionInfo {
  id: string;
  pid: number;
  createdAt: Date;
  cwd: string;
  alive: boolean;
  visible?: boolean;
  tmuxSession?: string;
  attachCommand?: string;
}