repl

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinThemes = map[string]Theme{
	"default": {
		Name:   "Default",
		Styles: DefaultStyles(),
	},
	"dark": {
		Name: "Dark",
		Styles: Styles{
			Title: lipgloss.NewStyle().
				Bold(true).
				Foreground(lipgloss.Color("15")).
				Background(lipgloss.Color("236")).
				Padding(0, 1),

			Prompt: lipgloss.NewStyle().
				Foreground(lipgloss.Color("11")).
				Bold(true),

			Result: lipgloss.NewStyle().
				Foreground(lipgloss.Color("14")),

			Error: lipgloss.NewStyle().
				Foreground(lipgloss.Color("9")).
				Bold(true),

			Info: lipgloss.NewStyle().
				Foreground(lipgloss.Color("3")).
				Italic(true),

			HelpText: lipgloss.NewStyle().
				Foreground(lipgloss.Color("243")).
				Italic(true),
		},
	},
	"light": {
		Name: "Light",
		Styles: Styles{
			Title: lipgloss.NewStyle().
				Bold(true).
				Foreground(lipgloss.Color("0")).
				Background(lipgloss.Color("252")).
				Padding(0, 1),

			Prompt: lipgloss.NewStyle().
				Foreground(lipgloss.Color("4")).
				Bold(true),

			Result: lipgloss.NewStyle().
				Foreground(lipgloss.Color("6")),

			Error: lipgloss.NewStyle().
				Foreground(lipgloss.Color("1")).
				Bold(true),

			Info: lipgloss.NewStyle().
				Foreground(lipgloss.Color("130")).
				Italic(true),

			HelpText: lipgloss.NewStyle().
				Foreground(lipgloss.Color("8")).
				Italic(true),
		},
	},
}

BuiltinThemes provides predefined themes

Functions

This section is empty.

Types

type ClearHistoryMsg

type ClearHistoryMsg struct{}

ClearHistoryMsg is sent when history should be cleared

type Config

type Config struct {
	Title                string
	Prompt               string
	Placeholder          string
	Width                int
	StartMultiline       bool
	EnableExternalEditor bool
	EnableHistory        bool
	MaxHistorySize       int
}

Config holds configuration for the REPL

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration

type EvaluationCompleteMsg

type EvaluationCompleteMsg struct {
	Input  string
	Output string
	Error  error
}

EvaluationCompleteMsg is sent when evaluation is complete

type Evaluator

type Evaluator interface {
	// Evaluate executes the given code and returns the result
	Evaluate(ctx context.Context, code string) (string, error)

	// GetPrompt returns the prompt string for this evaluator
	GetPrompt() string

	// GetName returns the name of this evaluator (for display)
	GetName() string

	// SupportsMultiline returns true if this evaluator supports multiline input
	SupportsMultiline() bool

	// GetFileExtension returns the file extension for external editor
	GetFileExtension() string
}

Evaluator represents the interface for pluggable evaluators

type EvaluatorResult

type EvaluatorResult struct {
	Output string
	Error  error
}

EvaluatorResult represents the result of an evaluation

type ExampleEvaluator

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

ExampleEvaluator is a simple evaluator for demonstration

func NewExampleEvaluator

func NewExampleEvaluator() *ExampleEvaluator

NewExampleEvaluator creates a new example evaluator

func (*ExampleEvaluator) Evaluate

func (e *ExampleEvaluator) Evaluate(ctx context.Context, code string) (string, error)

Evaluate implements the Evaluator interface

func (*ExampleEvaluator) GetFileExtension

func (e *ExampleEvaluator) GetFileExtension() string

GetFileExtension returns the file extension for external editor

func (*ExampleEvaluator) GetName

func (e *ExampleEvaluator) GetName() string

GetName returns the evaluator name

func (*ExampleEvaluator) GetPrompt

func (e *ExampleEvaluator) GetPrompt() string

GetPrompt returns the prompt string

func (*ExampleEvaluator) SupportsMultiline

func (e *ExampleEvaluator) SupportsMultiline() bool

SupportsMultiline returns true if multiline is supported

type ExternalEditorCompleteMsg

type ExternalEditorCompleteMsg struct {
	Content string
	Error   error
}

ExternalEditorCompleteMsg is sent when external editor is complete

type ExternalEditorMsg

type ExternalEditorMsg struct {
	Content string
}

ExternalEditorMsg is sent when external editor should be opened

type History

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

History manages command history for the REPL

func NewHistory

func NewHistory(maxSize int) *History

NewHistory creates a new history manager

func (*History) Add

func (h *History) Add(input, output string, isErr bool)

Add adds a new entry to the history

func (*History) Clear

func (h *History) Clear()

Clear clears all history

func (*History) GetAll

func (h *History) GetAll() []string

GetAll returns all input history entries for counting

func (*History) GetEntries

func (h *History) GetEntries() []HistoryEntry

GetEntries returns all history entries

func (*History) IsNavigating

func (h *History) IsNavigating() bool

IsNavigating returns true if currently navigating history

func (*History) NavigateDown

func (h *History) NavigateDown() string

NavigateDown moves down in history (to newer entries)

func (*History) NavigateUp

func (h *History) NavigateUp() string

NavigateUp moves up in history (to older entries)

func (*History) ResetNavigation

func (h *History) ResetNavigation()

ResetNavigation resets the navigation state

type HistoryEntry

type HistoryEntry struct {
	Input  string
	Output string
	IsErr  bool
}

HistoryEntry represents a single entry in the REPL history

type HistoryNavigationMsg

type HistoryNavigationMsg struct {
	Direction string // "up" or "down"
	Entry     string
}

HistoryNavigationMsg is sent when history navigation occurs

type Model

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

Model represents the UI state for the REPL

func NewModel

func NewModel(evaluator Evaluator, config Config) Model

NewModel creates a new REPL model

func (*Model) AddCustomCommand

func (m *Model) AddCustomCommand(name string, handler func([]string) tea.Cmd)

AddCustomCommand adds a custom slash command

func (*Model) AddCustomCommandRaw added in v0.0.27

func (m *Model) AddCustomCommandRaw(name string, handler func(string, []string) tea.Cmd)

AddCustomCommandRaw registers a command and provides the raw argument string alongside tokenized args.

func (*Model) GetHistory

func (m *Model) GetHistory() *History

GetHistory returns the history object

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the REPL model

func (*Model) SetStyles

func (m *Model) SetStyles(styles Styles)

SetStyles updates the styles for the REPL

func (*Model) SetTheme

func (m *Model) SetTheme(theme Theme)

SetTheme updates the theme for the REPL

func (*Model) SetWidth

func (m *Model) SetWidth(width int)

SetWidth sets the width of the REPL model

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles UI events and updates the model

func (Model) View

func (m Model) View() string

View renders the UI

type MultilineModeToggleMsg

type MultilineModeToggleMsg struct {
	Enabled bool
}

MultilineModeToggleMsg is sent when multiline mode is toggled

type QuitMsg

type QuitMsg struct{}

QuitMsg is sent when the REPL should quit

type SlashCommandMsg

type SlashCommandMsg struct {
	Command string
	Args    []string
}

SlashCommandMsg is sent when a slash command is executed

type Styles

type Styles struct {
	Title    lipgloss.Style
	Prompt   lipgloss.Style
	Result   lipgloss.Style
	Error    lipgloss.Style
	Info     lipgloss.Style
	HelpText lipgloss.Style
}

Styles defines the visual styling for the REPL

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns the default styling configuration

type Theme

type Theme struct {
	Name   string
	Styles Styles
}

Theme represents a color theme for the REPL

Directories

Path Synopsis
evaluators

Jump to

Keyboard shortcuts

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