repl

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package repl includes the types and functions for a Read Eval Print Loop.

Index

Constants

View Source
const MAX_DIM = 9999

Variables

View Source
var (
	Pkg = slip.Package{
		Name:      "repl",
		Nicknames: []string{},
		Doc:       "A package for REPL related functions.",
		PreSet:    slip.DefaultPreSet,
	}
	// TheHistory is the single global used by readers (editor and
	// termReader).
	TheHistory History
	TheStash   Stash
)
View Source
var (
	// Interactive is set to true when the REPL is interactive.
	Interactive bool

	// Trace reflects the value of tracing as set on startup. It does no
	// reflect the current trace state.
	Trace bool

	// DebugEditor if set before Run() is called will log keystrokes to
	// editor.log when using the editor.
	DebugEditor bool
)

Functions

func FindConfigDir added in v0.9.5

func FindConfigDir() (dir string)

FindConfigDir finds the preferred config directory.

func GetScope

func GetScope() *slip.Scope

GetScope returns the REPL scope.

func Run

func Run()

Run starts the REPL.

func RuneWidth

func RuneWidth(r rune) int

RuneWidth returns the display width of a rune,

func Scope

func Scope() *slip.Scope

Scope returns the REPL scope.

func SetConfigDir

func SetConfigDir(dir string)

SetConfigDir sets the configuration directory for the configuration and history files.

func SetSizer

func SetSizer(hs hasSize)

func Stop added in v0.7.0

func Stop()

Stop and reset the terminal.

func WordMatch added in v0.9.5

func WordMatch(word string) (words []string, lo, hi int)

WordMatch looks for a match of the word provided. The internal slice of sorted words is returned along with the low and high indices into the word slice for matches that begin with the provided word.

func ZeroMods

func ZeroMods()

ZeroMods resets the modified variables list.

Types

type Ansi

type Ansi struct {
	slip.Function
}

Ansi represents the ansi function.

func (*Ansi) Call

func (f *Ansi) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type ClearHistory added in v0.9.0

type ClearHistory struct {
	slip.Function
}

ClearHistory represents the clear-history function.

func (*ClearHistory) Call added in v0.9.0

func (f *ClearHistory) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type ClearStash added in v0.9.0

type ClearStash struct {
	slip.Function
}

ClearStash represents the clear-stash function.

func (*ClearStash) Call added in v0.9.0

func (f *ClearStash) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type Completer

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

Completer provides completion choices given a partial word. Words are stored in a slice in sorted order to optimize not only the search for a match but for returing a slice of matches.

func (*Completer) Init

func (c *Completer) Init()

Init the instance.

type Completions added in v0.9.5

type Completions struct {
	slip.Function
}

Completions represents the completions function.

func (*Completions) Call added in v0.9.5

func (f *Completions) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type EditStash added in v0.9.0

type EditStash struct {
	slip.Function
}

EditStash represents the edit-stash function.

func (*EditStash) Call added in v0.9.0

func (f *EditStash) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type Form

type Form [][]rune

Form is used to represent slip forms as a sequence of lines which are []rune.

func NewForm added in v0.9.0

func NewForm(buf []byte) (f Form)

NewForm creates a new Form from a []byte.

func (Form) Append

func (f Form) Append(b []byte) []byte

Append the form to a byte slice using tabs as separators between lines.

func (Form) Contains

func (f Form) Contains(target string) bool

Contains returns true if the form contains the target string.

func (Form) Dup

func (f Form) Dup() Form

Dup creates a deep duplicate of the form.

func (Form) Empty

func (f Form) Empty() bool

Empty return true if there are not non-space characters in the form.

func (Form) Equal

func (f Form) Equal(f2 Form) bool

Equal returns true if the two forms are equal.

func (Form) String

func (f Form) String() string

String returns a string representation of the form.

func (Form) TabAppend added in v0.9.0

func (f Form) TabAppend(b []byte) []byte

TabAppend the form to a byte slice using tabs as separators between lines.

type Help

type Help struct {
	slip.Function
}

Help represents the help function.

func (*Help) Call

func (f *Help) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type History

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

History keeps a history of forms. Previously added Forms are stored in memory and also to a file.

func (*History) Add

func (h *History) Add(form Form)

Add adds a form to history.

func (*History) Clear added in v0.9.0

func (h *History) Clear(start, end int)

Clear the stash entries in the range specified..

func (*History) Load

func (h *History) Load(filename string)

Load forms from a file and use that file for updates to history.

func (*History) SetLimit

func (h *History) SetLimit(limit int)

SetLimit of the history. The limit is the target maximum number of forms saved.

type LineReader

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

LineReader is an io.Reader that is optimized for reading lines terminated by a newline character.

func NewLineReader

func NewLineReader(r io.Reader, size uint) *LineReader

NewLineReader creates a new LineReader.

func (*LineReader) Read

func (lr *LineReader) Read(p []byte) (n int, err error)

Read into the provided buffer, p.

func (*LineReader) ReadLine

func (lr *LineReader) ReadLine() ([]byte, error)

ReadLine reads a line. The returned line is the internal buffer so should be copied if it needs to be preserved past the next call to the reader.

type NthHistory added in v0.9.0

type NthHistory struct {
	slip.Function
}

NthHistory represents the nth-history function.

func (*NthHistory) Call added in v0.9.0

func (f *NthHistory) Call(s *slip.Scope, args slip.List, depth int) (result slip.Object)

Call the the function with the arguments provided.

type NthStash added in v0.9.0

type NthStash struct {
	slip.Function
}

NthStash represents the nth-stash function.

func (*NthStash) Call added in v0.9.0

func (f *NthStash) Call(s *slip.Scope, args slip.List, depth int) (result slip.Object)

Call the the function with the arguments provided.

type Quit

type Quit struct {
	slip.Function
}

Quit represents the quit function.

func (*Quit) Call

func (f *Quit) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type Repl added in v1.3.1

type Repl struct {
	slip.Function
}

Repl represents the repl function.

func (*Repl) Call added in v1.3.1

func (f *Repl) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type ShowHistory added in v0.9.0

type ShowHistory struct {
	slip.Function
}

ShowHistory represents the show-history function.

func (*ShowHistory) Call added in v0.9.0

func (f *ShowHistory) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type ShowStash added in v0.9.0

type ShowStash struct {
	slip.Function
}

ShowStash represents the show-stash function.

func (*ShowStash) Call added in v0.9.0

func (f *ShowStash) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

type Stash added in v0.9.0

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

Stash is used for history and general use stashes which are a collection of LISP expressions.

func (*Stash) Add added in v0.9.0

func (s *Stash) Add(form Form)

Add adds a form to the stash.

func (*Stash) Append added in v0.9.0

func (s *Stash) Append(b []byte, annotate, tight, raw bool, start, end int) []byte

Append the stash forms in order as expanded LISP code.

func (*Stash) Clear added in v0.9.0

func (s *Stash) Clear(start, end int)

Clear the stash entries in the range specified..

func (*Stash) Cursor added in v0.9.0

func (s *Stash) Cursor() int

Cursor returns the current cursor position.

func (*Stash) Get added in v0.9.0

func (s *Stash) Get() (form Form)

Get the form at the cursor in history.

func (*Stash) LoadExpanded added in v0.9.0

func (s *Stash) LoadExpanded(filename string)

LoadExpanded forms from a file and use that file for updates to history.

func (*Stash) Nth added in v0.9.0

func (s *Stash) Nth(n int) (form Form)

Nth form in stash numbered from the most recent added form.

func (*Stash) SearchBack added in v0.9.0

func (s *Stash) SearchBack(target string) Form

SearchBack for a match to the provided target string starting with the cursor position.

func (*Stash) SearchForward added in v0.9.0

func (s *Stash) SearchForward(target string) (form Form)

SearchForward for a match to the provided target string starting with the cursor at the start position.

func (*Stash) SetCursor added in v0.9.0

func (s *Stash) SetCursor(pos int)

SetCursor sets the current cursor position adjusted to from zero to one less than the length of the history.

func (*Stash) Size added in v0.9.0

func (s *Stash) Size() int

Size of the current history.

type Termock

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

Termock is a mock terminal for testing the editor.

func NewTermock

func NewTermock(high, wide int) *Termock

NewTermock creates a new Termock with an initial size described by high and wide.

func (*Termock) Append

func (tm *Termock) Append(b []byte) []byte

Append the object to a byte slice.

func (*Termock) Equal

func (tm *Termock) Equal(other slip.Object) bool

Equal returns true if this Object and the other are equal in value.

func (*Termock) Eval

func (tm *Termock) Eval(s *slip.Scope, depth int) slip.Object

Eval the object.

func (*Termock) Hierarchy

func (tm *Termock) Hierarchy() []slip.Symbol

Hierarchy returns the class hierarchy as symbols for the instance.

func (*Termock) Input

func (tm *Termock) Input(keys ...string)

func (*Termock) Output

func (tm *Termock) Output() string

func (*Termock) Read

func (tm *Termock) Read(p []byte) (n int, err error)

func (*Termock) Simplify

func (tm *Termock) Simplify() any

Simplify the Object into simple go types of nil, bool, int64, float64, string, []any, map[string]any, or time.Time.

func (*Termock) String

func (tm *Termock) String() string

String returns the instance type.

func (*Termock) Write

func (tm *Termock) Write(p []byte) (n int, err error)

Write the bytes.

type UseStash added in v0.9.0

type UseStash struct {
	slip.Function
}

UseStash represents the use-stash function.

func (*UseStash) Call added in v0.9.0

func (f *UseStash) Call(s *slip.Scope, args slip.List, depth int) slip.Object

Call the the function with the arguments provided.

Directories

Path Synopsis
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems.

Jump to

Keyboard shortcuts

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