zellij

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package zellij provides a client for interacting with the zellij terminal multiplexer. It abstracts session, tab, and pane management operations into a type-safe API.

Index

Constants

View Source
const ASCIICtrlC = 3

ASCIICtrlC is the ASCII code for Ctrl+C (interrupt)

Variables

This section is empty.

Functions

func CurrentSessionName

func CurrentSessionName() string

CurrentSessionName returns the name of the zellij session we're currently inside, or empty string if not inside a zellij session.

func IsInsideTargetSession

func IsInsideTargetSession(session string) bool

IsInsideTargetSession returns true if we're inside the specified session.

Types

type Session

type Session interface {
	// Tab management
	CreateTabWithCommand(ctx context.Context, name, cwd, command string, args []string, paneName string) error
	SwitchToTab(ctx context.Context, name string) error
	QueryTabNames(ctx context.Context) ([]string, error)
	TabExists(ctx context.Context, name string) (bool, error)

	// High-level operations
	TerminateAndCloseTab(ctx context.Context, tabName string) error
}

Session defines the interface for operations within a specific zellij session. Each Session instance is bound to a specific session name.

type SessionManager

type SessionManager interface {
	SessionExists(ctx context.Context, name string) (bool, error)
	EnsureSessionWithCommand(ctx context.Context, sessionName, tabName, cwd, command string, args []string) (bool, error)

	// Session returns a Session interface bound to the specified session name.
	Session(name string) Session
}

SessionManager defines the interface for managing zellij sessions. This abstraction enables testing without actual zellij commands.

All session creation should go through EnsureSessionWithCommand to ensure every session starts with an initial tab. Direct session creation methods are intentionally excluded from this interface.

func New

func New() SessionManager

New creates a new zellij client with default configuration.

type SessionManagerMock

type SessionManagerMock struct {
	// EnsureSessionWithCommandFunc mocks the EnsureSessionWithCommand method.
	EnsureSessionWithCommandFunc func(ctx context.Context, sessionName string, tabName string, cwd string, command string, args []string) (bool, error)

	// SessionFunc mocks the Session method.
	SessionFunc func(name string) Session

	// SessionExistsFunc mocks the SessionExists method.
	SessionExistsFunc func(ctx context.Context, name string) (bool, error)
	// contains filtered or unexported fields
}

SessionManagerMock is a mock implementation of SessionManager.

func TestSomethingThatUsesSessionManager(t *testing.T) {

	// make and configure a mocked SessionManager
	mockedSessionManager := &SessionManagerMock{
		EnsureSessionWithCommandFunc: func(ctx context.Context, sessionName string, tabName string, cwd string, command string, args []string) (bool, error) {
			panic("mock out the EnsureSessionWithCommand method")
		},
		SessionFunc: func(name string) Session {
			panic("mock out the Session method")
		},
		SessionExistsFunc: func(ctx context.Context, name string) (bool, error) {
			panic("mock out the SessionExists method")
		},
	}

	// use mockedSessionManager in code that requires SessionManager
	// and then make assertions.

}

func (*SessionManagerMock) EnsureSessionWithCommand

func (mock *SessionManagerMock) EnsureSessionWithCommand(ctx context.Context, sessionName string, tabName string, cwd string, command string, args []string) (bool, error)

EnsureSessionWithCommand calls EnsureSessionWithCommandFunc.

func (*SessionManagerMock) EnsureSessionWithCommandCalls

func (mock *SessionManagerMock) EnsureSessionWithCommandCalls() []struct {
	Ctx         context.Context
	SessionName string
	TabName     string
	Cwd         string
	Command     string
	Args        []string
}

EnsureSessionWithCommandCalls gets all the calls that were made to EnsureSessionWithCommand. Check the length with:

len(mockedSessionManager.EnsureSessionWithCommandCalls())

func (*SessionManagerMock) Session

func (mock *SessionManagerMock) Session(name string) Session

Session calls SessionFunc.

func (*SessionManagerMock) SessionCalls

func (mock *SessionManagerMock) SessionCalls() []struct {
	Name string
}

SessionCalls gets all the calls that were made to Session. Check the length with:

len(mockedSessionManager.SessionCalls())

func (*SessionManagerMock) SessionExists

func (mock *SessionManagerMock) SessionExists(ctx context.Context, name string) (bool, error)

SessionExists calls SessionExistsFunc.

func (*SessionManagerMock) SessionExistsCalls

func (mock *SessionManagerMock) SessionExistsCalls() []struct {
	Ctx  context.Context
	Name string
}

SessionExistsCalls gets all the calls that were made to SessionExists. Check the length with:

len(mockedSessionManager.SessionExistsCalls())

type SessionMock

type SessionMock struct {
	// CreateTabWithCommandFunc mocks the CreateTabWithCommand method.
	CreateTabWithCommandFunc func(ctx context.Context, name string, cwd string, command string, args []string, paneName string) error

	// QueryTabNamesFunc mocks the QueryTabNames method.
	QueryTabNamesFunc func(ctx context.Context) ([]string, error)

	// SwitchToTabFunc mocks the SwitchToTab method.
	SwitchToTabFunc func(ctx context.Context, name string) error

	// TabExistsFunc mocks the TabExists method.
	TabExistsFunc func(ctx context.Context, name string) (bool, error)

	// TerminateAndCloseTabFunc mocks the TerminateAndCloseTab method.
	TerminateAndCloseTabFunc func(ctx context.Context, tabName string) error
	// contains filtered or unexported fields
}

SessionMock is a mock implementation of Session.

func TestSomethingThatUsesSession(t *testing.T) {

	// make and configure a mocked Session
	mockedSession := &SessionMock{
		CreateTabWithCommandFunc: func(ctx context.Context, name string, cwd string, command string, args []string, paneName string) error {
			panic("mock out the CreateTabWithCommand method")
		},
		QueryTabNamesFunc: func(ctx context.Context) ([]string, error) {
			panic("mock out the QueryTabNames method")
		},
		SwitchToTabFunc: func(ctx context.Context, name string) error {
			panic("mock out the SwitchToTab method")
		},
		TabExistsFunc: func(ctx context.Context, name string) (bool, error) {
			panic("mock out the TabExists method")
		},
		TerminateAndCloseTabFunc: func(ctx context.Context, tabName string) error {
			panic("mock out the TerminateAndCloseTab method")
		},
	}

	// use mockedSession in code that requires Session
	// and then make assertions.

}

func (*SessionMock) CreateTabWithCommand

func (mock *SessionMock) CreateTabWithCommand(ctx context.Context, name string, cwd string, command string, args []string, paneName string) error

CreateTabWithCommand calls CreateTabWithCommandFunc.

func (*SessionMock) CreateTabWithCommandCalls

func (mock *SessionMock) CreateTabWithCommandCalls() []struct {
	Ctx      context.Context
	Name     string
	Cwd      string
	Command  string
	Args     []string
	PaneName string
}

CreateTabWithCommandCalls gets all the calls that were made to CreateTabWithCommand. Check the length with:

len(mockedSession.CreateTabWithCommandCalls())

func (*SessionMock) QueryTabNames

func (mock *SessionMock) QueryTabNames(ctx context.Context) ([]string, error)

QueryTabNames calls QueryTabNamesFunc.

func (*SessionMock) QueryTabNamesCalls

func (mock *SessionMock) QueryTabNamesCalls() []struct {
	Ctx context.Context
}

QueryTabNamesCalls gets all the calls that were made to QueryTabNames. Check the length with:

len(mockedSession.QueryTabNamesCalls())

func (*SessionMock) SwitchToTab

func (mock *SessionMock) SwitchToTab(ctx context.Context, name string) error

SwitchToTab calls SwitchToTabFunc.

func (*SessionMock) SwitchToTabCalls

func (mock *SessionMock) SwitchToTabCalls() []struct {
	Ctx  context.Context
	Name string
}

SwitchToTabCalls gets all the calls that were made to SwitchToTab. Check the length with:

len(mockedSession.SwitchToTabCalls())

func (*SessionMock) TabExists

func (mock *SessionMock) TabExists(ctx context.Context, name string) (bool, error)

TabExists calls TabExistsFunc.

func (*SessionMock) TabExistsCalls

func (mock *SessionMock) TabExistsCalls() []struct {
	Ctx  context.Context
	Name string
}

TabExistsCalls gets all the calls that were made to TabExists. Check the length with:

len(mockedSession.TabExistsCalls())

func (*SessionMock) TerminateAndCloseTab

func (mock *SessionMock) TerminateAndCloseTab(ctx context.Context, tabName string) error

TerminateAndCloseTab calls TerminateAndCloseTabFunc.

func (*SessionMock) TerminateAndCloseTabCalls

func (mock *SessionMock) TerminateAndCloseTabCalls() []struct {
	Ctx     context.Context
	TabName string
}

TerminateAndCloseTabCalls gets all the calls that were made to TerminateAndCloseTab. Check the length with:

len(mockedSession.TerminateAndCloseTabCalls())

type TabLayoutData

type TabLayoutData struct {
	TabName  string
	PaneName string
	Command  string
	Args     []string
	Cwd      string
}

TabLayoutData contains the data for rendering a tab layout template.

Jump to

Keyboard shortcuts

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