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
- func CurrentSessionName() string
- func IsInsideTargetSession(session string) bool
- type Session
- type SessionManager
- type SessionManagerMock
- func (mock *SessionManagerMock) EnsureSessionWithCommand(ctx context.Context, sessionName string, tabName string, cwd string, ...) (bool, error)
- func (mock *SessionManagerMock) EnsureSessionWithCommandCalls() []struct{ ... }
- func (mock *SessionManagerMock) Session(name string) Session
- func (mock *SessionManagerMock) SessionCalls() []struct{ ... }
- func (mock *SessionManagerMock) SessionExists(ctx context.Context, name string) (bool, error)
- func (mock *SessionManagerMock) SessionExistsCalls() []struct{ ... }
- type SessionMock
- func (mock *SessionMock) CreateTabWithCommand(ctx context.Context, name string, cwd string, command string, args []string, ...) error
- func (mock *SessionMock) CreateTabWithCommandCalls() []struct{ ... }
- func (mock *SessionMock) QueryTabNames(ctx context.Context) ([]string, error)
- func (mock *SessionMock) QueryTabNamesCalls() []struct{ ... }
- func (mock *SessionMock) SwitchToTab(ctx context.Context, name string) error
- func (mock *SessionMock) SwitchToTabCalls() []struct{ ... }
- func (mock *SessionMock) TabExists(ctx context.Context, name string) (bool, error)
- func (mock *SessionMock) TabExistsCalls() []struct{ ... }
- func (mock *SessionMock) TerminateAndCloseTab(ctx context.Context, tabName string) error
- func (mock *SessionMock) TerminateAndCloseTabCalls() []struct{ ... }
- type TabLayoutData
Constants ¶
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 ¶
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.
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 ¶
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) 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())