terminal

package
v0.0.1-alpha.22 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLocalShell     = "/bin/zsh"
	DefaultReadBufferSize = 20480
	InitialRows           = 27
	InitialCols           = 72
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages terminal sessions, allowing creation, attachment, and more.

func NewManager

func NewManager(
	log *zap.SugaredLogger,
) (*Manager, chan sdkexec.StreamInput, chan sdkexec.StreamOutput, chan sdkexec.StreamResize)

NewManager initializes a new Manager instance. Because we want to be a bit more latency sensitive with the local manager, we're going to directly return the channels for in and out that the exec controller will use.

func (*Manager) AttachSession

func (m *Manager) AttachSession(sessionID string) (*sdkexec.Session, []byte, error)

AttachToSession marks a session as attached and returns its current output buffer.

func (*Manager) CloseSession

func (m *Manager) CloseSession(sessionID string) error

CloseSession cancels the session's context, effectively terminating its command, and removes it from the manager.

func (*Manager) DetachSession

func (m *Manager) DetachSession(sessionID string) (*sdkexec.Session, error)

DetachFromSession marks a session as not attached, stopping output broadcast.

func (*Manager) GetSession

func (m *Manager) GetSession(sessionID string) (*sdkexec.Session, error)

GetSession returns a session by its ID.

func (*Manager) ListSessions

func (m *Manager) ListSessions(_ *types.PluginContext) []*sdkexec.Session

ListSessions returns a list of details for all active sessions.

func (*Manager) ResizeSession

func (m *Manager) ResizeSession(sessionID string, rows, cols uint16) error

func (*Manager) StartSession

func (m *Manager) StartSession(
	pCtx *types.PluginContext,
	opts sdkexec.SessionOptions,
) (*sdkexec.Session, error)

StartSession creates a new terminal session with a given command.

func (*Manager) WriteSession

func (m *Manager) WriteSession(sessionID string, input []byte) error

WriteSession writes data to the session's input.

type OutputBuffer

type OutputBuffer struct {
	// contains filtered or unexported fields
}

OutputBuffer stores terminal output lines, providing a fixed-size cyclic buffer.

func NewOutputBuffer

func NewOutputBuffer(capacity int) *OutputBuffer

NewOutputBuffer initializes an OutputBuffer with a specified capacity.

func (*OutputBuffer) Append

func (b *OutputBuffer) Append(data []byte)

Append adds a line to the buffer, managing overflow by removing the oldest line.

func (*OutputBuffer) GetAll

func (b *OutputBuffer) GetAll() []byte

GetAll retrieves a copy of all stored lines in the buffer.

type Session

type Session struct {
	ID string
	// contains filtered or unexported fields
}

Session represents an individual terminal session.

type SessionDetails

type SessionDetails struct {
	// Labels are key-value pairs for the session.
	Labels map[string]string `json:"labels"`
	// ID is the unique identifier for the session.
	ID string `json:"id"`
	// Command is the command being run in the session.
	Command string `json:"command"`
	// Attached indicates if the session is currently broadcasting output.
	Attached bool `json:"attached"`
}

SessionDetails contains details about a terminal session.

type SessionOptions

type SessionOptions struct {
	ID string `json:"id"`
	// Labels are arbitrary key-value pairs for the session that can be used to filter sessions, or
	// to provide additional information about the session.
	Labels map[string]string `json:"labels"`
	// Kubeconfig is the path to the kubeconfig file.
	Kubeconfig string `json:"kubeconfig"`
	// Context is the name of the context to use.
	Context string `json:"context"`
}

SessionOptions contains options for creating a new terminal session.

Jump to

Keyboard shortcuts

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