repl

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package repl provides the main interactive shell implementation for gsh. It consolidates functionality from pkg/gline, pkg/shellinput, and other packages into a cohesive REPL that leverages the gsh script interpreter.

Index

Constants

This section is empty.

Variables

View Source
var ErrExit = fmt.Errorf("exit requested")

ErrExit is returned when the user requests to exit the REPL.

Functions

This section is empty.

Types

type Options

type Options struct {
	// ConfigPath is the path to the repl.gsh configuration file.
	// If empty, the default path (~/.gsh/repl.gsh) is used.
	ConfigPath string

	// DefaultConfigContent is the embedded content of defaults/init.gsh.
	// This is loaded before the user's ~/.gsh/repl.gsh file.
	DefaultConfigContent string

	// DefaultConfigFS is the embedded filesystem containing the default config and any
	// modules it imports. If nil, imports from the default config are disabled.
	DefaultConfigFS fs.FS

	// DefaultConfigBasePath is the base path within DefaultConfigFS where the default
	// config resides (e.g., "defaults" if the config is at "defaults/init.gsh").
	DefaultConfigBasePath string

	// HistoryPath is the path to the history database file.
	// If empty, the default path is used.
	HistoryPath string

	// Logger is the logger to use. If nil, a no-op logger is used.
	Logger *zap.Logger

	// ExecMiddleware is optional middleware for command execution.
	ExecMiddleware []executor.ExecMiddleware

	// BuildVersion is the build version string (e.g., "dev" or "1.0.0").
	// Used to show [dev] indicator in prompt for development builds.
	BuildVersion string

	// Runner is the sh runner to use for bash command execution.
	// If nil, a new runner is created with default settings.
	// Passing a runner allows sharing environment variables (like SHELL)
	// that were set up during gsh initialization.
	Runner *shinterp.Runner

	// StartTime is when the application started (for accurate startup time tracking).
	// If zero, startup time tracking is skipped.
	StartTime time.Time

	// StartupTracker is called when the REPL is ready (welcome screen shown).
	// This allows accurate startup time measurement from app start to user-visible ready state.
	StartupTracker StartupTimeTracker
}

type REPL

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

REPL is the main interactive shell interface.

func NewREPL

func NewREPL(opts Options) (*REPL, error)

NewREPL creates a new REPL instance.

func (*REPL) Close

func (r *REPL) Close() error

Close cleans up REPL resources.

func (*REPL) Config

func (r *REPL) Config() *config.Config

Config returns the current configuration.

func (*REPL) Executor

func (r *REPL) Executor() *executor.REPLExecutor

Executor returns the command executor.

func (*REPL) History

func (r *REPL) History() *history.HistoryManager

History returns the history manager.

func (*REPL) Run

func (r *REPL) Run(ctx context.Context) error

Run starts the interactive REPL loop.

type StartupTimeTracker

type StartupTimeTracker interface {
	TrackStartupTime(durationMs int64)
}

Options holds configuration options for creating a new REPL. StartupTimeTracker is an interface for tracking startup time. This allows the REPL to report when the user actually sees the welcome screen.

Directories

Path Synopsis
Package completion provides tab completion functionality for the gsh REPL.
Package completion provides tab completion functionality for the gsh REPL.
completers
Package completers provides specialized completion sources for different types of input.
Package completers provides specialized completion sources for different types of input.
Package config provides configuration management for the gsh REPL.
Package config provides configuration management for the gsh REPL.
Package context provides context aggregation for LLM predictions in the gsh REPL.
Package context provides context aggregation for LLM predictions in the gsh REPL.
Package executor provides command execution abstractions for the gsh REPL.
Package executor provides command execution abstractions for the gsh REPL.
Package input provides input handling for the gsh REPL.
Package input provides input handling for the gsh REPL.
Package render provides agent output rendering functionality for the REPL.
Package render provides agent output rendering functionality for the REPL.

Jump to

Keyboard shortcuts

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