Documentation ¶
Index ¶
- Variables
- type Interpreter
- func (in *Interpreter) Config()
- func (in *Interpreter) Eval(code string) (v reflect.Value, hasPrint bool, err error)
- func (in *Interpreter) ImportShell()
- func (in *Interpreter) Interactive() error
- func (in *Interpreter) MonitorSignals()
- func (in *Interpreter) OpenHistory(rl *readline.Instance) error
- func (in *Interpreter) Prompt() string
- func (in *Interpreter) RunCode() (reflect.Value, error)
- func (in *Interpreter) RunConfig() error
- func (in *Interpreter) SaveHistory() error
Constants ¶
This section is empty.
Variables ¶
var Symbols = map[string]map[string]reflect.Value{}
Functions ¶
This section is empty.
Types ¶
type Interpreter ¶
type Interpreter struct { // the cosh shell Shell *shell.Shell // HistFile is the name of the history file to open / save. // Defaults to ~/.cosh-history for the default cosh shell. // Update this prior to running Config() to take effect. HistFile string // the yaegi interpreter Interp *interp.Interpreter }
Interpreter represents one running shell context
func NewInterpreter ¶
func NewInterpreter(options interp.Options) *Interpreter
NewInterpreter returns a new Interpreter initialized with the given options. It automatically imports the standard library and configures necessary shell functions. End user app must call [Interp.Config] after importing any additional symbols, prior to running the interpreter.
func (*Interpreter) Config ¶ added in v0.2.0
func (in *Interpreter) Config()
Config performs final configuration after all the imports have been Use'd
func (*Interpreter) Eval ¶
Eval evaluates (interprets) the given code, returning the value returned from the interpreter. HasPrint indicates whether the last line of code has the string print in it, which is for determining whether to print the result in interactive mode. It automatically logs any error in addition to returning it.
func (*Interpreter) ImportShell ¶ added in v0.2.0
func (in *Interpreter) ImportShell()
ImportShell imports special symbols from the shell package.
func (*Interpreter) Interactive ¶ added in v0.2.0
func (in *Interpreter) Interactive() error
Interactive runs an interactive shell that allows the user to input cosh. Must have done in.Config() prior to calling.
func (*Interpreter) MonitorSignals ¶ added in v0.1.4
func (in *Interpreter) MonitorSignals()
MonitorSignals monitors the operating system signals to appropriately stop the interpreter and prevent the shell from closing on Control+C. It is called automatically in another goroutine in NewInterpreter.
func (*Interpreter) OpenHistory ¶ added in v0.2.0
func (in *Interpreter) OpenHistory(rl *readline.Instance) error
OpenHistory opens history from the current HistFile and loads it into the readline history for given rl instance
func (*Interpreter) Prompt ¶
func (in *Interpreter) Prompt() string
Prompt returns the appropriate REPL prompt to show the user.
func (*Interpreter) RunCode ¶
func (in *Interpreter) RunCode() (reflect.Value, error)
RunCode runs the accumulated set of code lines and clears the stack of code lines. It automatically logs any error in addition to returning it.
func (*Interpreter) RunConfig ¶ added in v0.1.4
func (in *Interpreter) RunConfig() error
RunConfig runs the .cosh startup config file in the user's home directory if it exists.
func (*Interpreter) SaveHistory ¶ added in v0.2.0
func (in *Interpreter) SaveHistory() error
SaveHistory saves last 500 (or HISTFILESIZE env value) lines of history, to the current HistFile.