repl

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: CC0-1.0, CC0-1.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrompt         = "> "
	DefaultBufferedPrompt = ">> "
)

The default prompts

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

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

Cmd defines a command.

func (*Cmd) Description

func (c *Cmd) Description() string

Description returns a description of the command.

func (*Cmd) Run

func (c *Cmd) Run(l string) (err error)

Run runs the command.

func (*Cmd) String

func (c *Cmd) String() string

String returns the command name (excluding the leading '.').

type CmdFunc

type CmdFunc func(string) error

CmdFunc is a function for a command. The function will be passed any text entered by the user following the command name.

type Printer

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

Printer provides a way to print REPL values to a io.Writer.

func NewPrinter

func NewPrinter(vm *rt.Runtime) *Printer

NewPrinter returns a new printer for the given vm.

func (*Printer) Bold

func (p *Printer) Bold(s string) string

Bold converts the given string to bold text, if colours are enabled. Otherwise the original string is returned.

func (*Printer) FprintError

func (p *Printer) FprintError(w io.Writer, err error) (int, error)

FprintError prints the error err to w. It returns the number of bytes written and any write error encountered.

func (*Printer) FprintHelp

func (p *Printer) FprintHelp(w io.Writer, title string, text string) (n int, err error)

FprintHelp prints the help message to w. It returns the number of bytes written and any write error encountered.

func (*Printer) FprintValue

func (p *Printer) FprintValue(w io.Writer, vs ...rt.Value) (int, error)

FprintValue prints the values to w. It returns the number of bytes written and any write error encountered.

func (*Printer) FprintValueInline

func (p *Printer) FprintValueInline(w io.Writer, vs ...rt.Value) (int, error)

FprintValueInline prints the values to w. It returns the number of bytes written and any write error encountered. The values will be printed inline.

func (*Printer) SetColor

func (p *Printer) SetColor(enable bool)

SetColor enables (true) or disables (false) colourised output.

func (*Printer) SetScreenWidth

func (p *Printer) SetScreenWidth(w int)

SetScreenWidth sets the target display width (in characters). This will be used for line-wrapping. A width <= 0 indicates an "infinitely" wide target display.

func (*Printer) Underline

func (p *Printer) Underline(s string) string

Underline underlines the given string, if colours are enabled. Otherwise the original string is returned.

func (*Printer) WrapString

func (p *Printer) WrapString(s string) string

WrapString wraps the given string to the current screen width.

type Registry

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

Registry is a register of available commands.

func (*Registry) Get

func (reg *Registry) Get(name string) (c *Cmd, ok bool)

Get returns the command corresponding to the given name (excluding the leading '.').

func (*Registry) Names

func (reg *Registry) Names() []string

Names returns a slice of registered command names (excluding the leading '.'), sorted in lex order.

func (*Registry) Register

func (reg *Registry) Register(name string, desc string, run CmdFunc) *Cmd

Register registers the a new command with given name (excluding the leading '.'), description, and function. If a command with this name was already registered it will be replaced with the new command. Returns the new command.

func (*Registry) Run

func (reg *Registry) Run(l string) (bool, error)

Run inspects the given line l of user input and sees whether it corresponds to a registered command. If so, the command will be run. Returns true if this line was handled by a command, along with any error returned by the command. Returns false if this line did not match a registered command.

type Repl

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

Repl is a REPL Lua interpreter.

func NewREPL

func NewREPL(vm *rt.Runtime, w io.Writer) (*Repl, error)

NewREPL returns a new Lua REPL wrapping vm and writing to the given io.Writer.

func (*Repl) ClearBuffer

func (r *Repl) ClearBuffer()

ClearBuffer clears any buffered lines of user input and updates the prompt.

func (*Repl) Close

func (r *Repl) Close() error

Close closes the REPL, preventing further user interaction.

func (*Repl) History

func (r *Repl) History() []string

History returns the history for this session.

func (*Repl) IsTerminal

func (r *Repl) IsTerminal() bool

IsTerminal returns true iff standard output is a terminal.

func (*Repl) Next

func (r *Repl) Next(ctx context.Context) error

Next handles the next line for the REPL.

func (*Repl) Printer

func (r *Repl) Printer() *Printer

Printer returns the printer for this REPL.

func (*Repl) PrintlnError

func (r *Repl) PrintlnError(err error) (int, error)

PrintlnError prints an error to standard output. A newline is appended to the output. It returns the number of bytes written and any write error encountered.

func (*Repl) Readline

func (r *Repl) Readline() (string, error)

Readline reads the next line of user input. An io.EOF will be returned if the REPL should exit.

func (*Repl) Registry

func (r *Repl) Registry() *Registry

Registry returns the dot-command registry for this REPL.

func (*Repl) Runtime

func (r *Repl) Runtime() time.Duration

Runtime returns the total runtime for this REPL.

func (*Repl) SetColor

func (r *Repl) SetColor(enable bool)

SetColor enables (true) or disables (false) colourised output.

func (*Repl) Stdout

func (r *Repl) Stdout() io.Writer

Stdout returns the stdout.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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