tmux

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tmux provides a thin wrapper around the shared pty.Manager from github.com/chainreactors/utils/pty. It adds aiscan-specific command routing (Command interface, RunCommand, SetCommands, SetWorkDir) and re-exports all base types as aliases for backward compatibility.

Index

Constants

View Source
const (
	StateRunning   = pty.StateRunning
	StateCompleted = pty.StateCompleted
	StateKilled    = pty.StateKilled
	StateFailed    = pty.StateFailed
)
View Source
const (
	EventSessionCreated = pty.EventSessionCreated
	EventSessionUpdated = pty.EventSessionUpdated
	EventSessionOutput  = pty.EventSessionOutput
	EventSessionClosed  = pty.EventSessionClosed
)
View Source
const (
	DefaultTimeout   = pty.DefaultTimeout
	DefaultBufferCap = pty.DefaultBufferCap
)

Variables

View Source
var (
	NewOutputBuffer         = pty.NewOutputBuffer
	NewOutputBufferWithFile = pty.NewOutputBufferWithFile
)

Re-export buffer constructors.

View Source
var (
	ShellCommand        = pty.ShellCommand
	DefaultShellCommand = pty.DefaultShellCommand
)

Re-export shell helpers.

View Source
var FormatCompletion = pty.FormatCompletion

Re-export formatting.

Functions

func SplitCommandLine

func SplitCommandLine(input string) ([]string, error)

SplitCommandLine splits a command string into tokens, handling quoting and escaping. Comment-only lines (# ...) and blank lines are stripped.

Types

type Command

type Command interface {
	Name() string
	Execute(ctx context.Context, args []string) error
}

Command is the minimal interface for an in-process command that can be executed inside a goroutine-based session. The command package's Command interface (which adds Usage()) satisfies this via Go structural subtyping.

type Event

type Event = pty.Event

type EventAction

type EventAction = pty.EventAction

type Info

type Info = pty.Info

type Manager

type Manager struct {
	*pty.Manager
	// contains filtered or unexported fields
}

Manager wraps pty.Manager and adds aiscan-specific command routing.

func NewManager

func NewManager() *Manager

NewManager creates a Manager backed by a fresh pty.Manager.

func (*Manager) RunCommand

func (m *Manager) RunCommand(cmdLine string, opts RunOpts) (Info, error)

RunCommand creates a session for the given command line. If the first token matches a registered in-process Command, the command runs in a goroutine-based session (CreateFunc). Otherwise it runs as a shell command in a PTY session (Create).

Pipe support: "pseudo-cmd args | shell-pipeline" is supported. The pseudo-command runs in-process with its output captured to a buffer, then the buffer is piped as stdin to the shell pipeline via sh -c.

func (*Manager) SetCommands

func (m *Manager) SetCommands(fn func(name string) (Command, bool))

SetCommands injects the lookup function used by RunCommand to detect in-process commands. The function is typically a closure over a CommandRegistry in the calling package.

func (*Manager) SetExecHooks

func (m *Manager) SetExecHooks(before func(w io.Writer), after func())

SetExecHooks sets callbacks invoked before/after each in-process command execution. beforeExec receives the session's io.Writer so the caller can redirect a global output sink; afterExec resets it.

func (*Manager) SetWorkDir

func (m *Manager) SetWorkDir(dir string)

SetWorkDir sets the default working directory for shell sessions created by RunCommand.

func (*Manager) Subscribe

func (m *Manager) Subscribe(fn func(Event)) func()

Subscribe registers an event listener and returns an unsubscribe function.

type OutputBuffer

type OutputBuffer = pty.OutputBuffer

type RunOpts

type RunOpts struct {
	Name    string
	Timeout time.Duration
	WorkDir string
	Env     []string
	Ctx     context.Context
}

RunOpts controls how RunCommand creates a session.

type State

type State = pty.State

type StdinReceiver added in v0.2.7

type StdinReceiver interface {
	SetStdinFile(path string)
}

StdinReceiver is an optional interface for pseudo-commands that can accept piped input. When a "shell | pseudo" pattern is detected, RunCommand writes the shell output to a temp file and calls SetStdinFile before Execute.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL