Documentation
¶
Overview ¶
Package tmux provides a minimal API to interact with tmux servers.
Index ¶
- func NewServer(opts ...ServerOption) *server
- func SameServer(ctx context.Context, a, b Server) bool
- func SameSession(ctx context.Context, a, b Session) bool
- type Client
- type ClientProperty
- type MenuElement
- type MenuEntry
- type MenuSpacer
- type NewSessionOptions
- type Server
- type ServerOption
- type Session
- type SessionProperty
- type Sessions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
func NewServer(opts ...ServerOption) *server
NewServer creates a new server for the given socket. Note: This doesn't actually create the server yet. You will need to create at least one session for the server to be active.
func SameServer ¶
Equal determines if two servers equivalent, based on PID.
Types ¶
type Client ¶
type Client interface {
// Property retrieves the value of the given property key.
Property(context.Context, ClientProperty) (string, error)
// Properties retrieves the values of all the given property keys.
Properties(context.Context, ...ClientProperty) (map[ClientProperty]string, error)
// DisplayMenu displays a menu in this client.
DisplayMenu(context.Context, []MenuElement) error
}
func CurrentClient ¶
CurrentClient returns a Client if this terminal is currently a tmux client.
func MaybeCurrentClient ¶
func MaybeCurrentClient() Client
MaybeCurrentClient returns a Client if the terminal is currently a tmux client. If it's not currently a tmux client, returns nil.
type ClientProperty ¶
type ClientProperty string
const (
ClientTTY ClientProperty = "#{client_tty}"
)
type MenuElement ¶
type MenuElement interface {
// contains filtered or unexported methods
}
type MenuEntry ¶
type MenuEntry struct {
Name, Key, Command string
}
MenuEntry is an actual entry in the menu that has an executable command.
type MenuSpacer ¶
type MenuSpacer struct{}
MenuSpacer allows you to delineate sections within a menu.
type NewSessionOptions ¶
type NewSessionOptions struct {
// Name is the optional initial name for the session.
Name string
// StartDir is the optional initial working directory for the session.
StartDir string
}
NewSessionOptions affects how NewSession creates sessions.
type Server ¶
type Server interface {
// PID returns the process ID of the server, if it's currently active.
PID(context.Context) (int, error)
// ListSessions lists the sessions that exist in this tmux server.
ListSessions(context.Context) (Sessions, error)
// ListClients lists all clients currently attached to this tmux server.
ListClients(context.Context) ([]Client, error)
// NewSession creates a new session in this tmux server.
NewSession(context.Context, NewSessionOptions) (Session, error)
// AttachOrSwitch either attaches the controlling terminal to the given TargetSession or switches the current tmux client to the TargetSession.
AttachOrSwitch(context.Context, Session) error
// Kill this tmux server.
Kill(context.Context) error
}
func CurrentServer ¶
CurrentServer returns a server if this program is running within a tmux server.
func DefaultServer ¶
func DefaultServer() Server
func MaybeCurrentServer ¶
func MaybeCurrentServer() Server
MaybeCurrentServer returns a server if this program is running within a tmux server. If it's not, it returns nil.
type ServerOption ¶
type ServerOption func(*serverOptions)
func NamedServerSocket ¶
func NamedServerSocket(name string) ServerOption
func ServerConfigFile ¶
func ServerConfigFile(file string) ServerOption
type Session ¶
type Session interface {
// Server returns the tmux server this Session belongs to.
Server() Server
// ID returns the ID of this session within its tmux server.
ID() string
// Property retrieves the value of the given property key.
Property(context.Context, SessionProperty) (string, error)
// Properties retrieves the values of all the given property keys.
Properties(context.Context, ...SessionProperty) (map[SessionProperty]string, error)
// Rename this tmux session to have the given name.
Rename(context.Context, string) error
// Kill this tmux session.
Kill(context.Context) error
}
func CurrentSession ¶
CurrentSession returns a Session if this program is being executed inside tmux.
func MaybeCurrentSession ¶
func MaybeCurrentSession() Session
MaybeCurrentSession returns a Session if this program is being executed inside tmux. If it's not being executed inside tmux, returns nil.
type SessionProperty ¶
type SessionProperty string
const ( SessionID SessionProperty = "#{session_id}" SessionName SessionProperty = "#{session_name}" SessionPath SessionProperty = "#{session_path}" )
type Sessions ¶
type Sessions interface {
// Server returns the tmux server that these Sessions belong to.
Server() Server
// Sessions returns each individual Session.
Sessions() []Session
// Property retrieves the value of the given property key for all of these
// Sessions.
Property(context.Context, SessionProperty) (map[Session]string, error)
// Properties retrieves the values of all the given property keys for all of
// these Sessions.
Properties(context.Context, ...SessionProperty) (map[Session]map[SessionProperty]string, error)
}
Sessions is a list of Sessions, batched together so their operations are more performant.