console

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Stdin = newTerminalPrompter()

Stdin holds the stdin line reader (also using stdout for printing prompts). Only this reader may be used for input because it keeps an internal buffer.

Functions

This section is empty.

Types

type Config

type Config struct {
	DocRoot  string       // Filesystem path from where to load JavaScript files from
	Client   *rpc.Client  // RPC client to execute Lemochain requests through
	Prompter UserPrompter // Input prompter to allow interactive user feedback (defaults to TerminalPrompter)
	Printer  io.Writer    // Output writer to serialize any display strings to (defaults to os.Stdout)
	ChainID  uint16       // Id of LemoChain network
}

Config is the collection of configurations to fine tune the behavior of the JavaScript console.

type Console

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

Console is a JavaScript interpreted runtime environment. It is a fully fleged JavaScript console attached to a running node via an external or in-process RPC client.

func New

func New(config Config) (*Console, error)

func (*Console) Evaluate

func (c *Console) Evaluate(statement string) error

Evaluate executes code and pretty prints the result to the specified output stream.

func (*Console) Execute

func (c *Console) Execute(path string) error

Execute runs the JavaScript file specified as the argument.

func (*Console) Interactive

func (c *Console) Interactive()

Interactive starts an interactive user session, where input is propted from the configured user prompter.

func (*Console) Stop

func (c *Console) Stop(graceful bool) error

Stop cleans up the console and terminates the runtime environment.

func (*Console) Welcome

func (c *Console) Welcome()

Welcome show summary of current Glemo instance and some metadata about the console's available modules.

type UserPrompter

type UserPrompter interface {
	// PromptInput displays the given prompt to the user and requests some textual
	// data to be entered, returning the input of the user.
	PromptInput(prompt string) (string, error)

	// PromptPassword displays the given prompt to the user and requests some textual
	// data to be entered, but one which must not be echoed out into the terminal.
	// The method returns the input provided by the user.
	PromptPassword(prompt string) (string, error)

	// PromptConfirm displays the given prompt to the user and requests a boolean
	// choice to be made, returning that choice.
	PromptConfirm(prompt string) (bool, error)

	// AppendHistory appends an entry to the scrollback history. It should be called
	// if and only if the prompt to append was a valid command.
	AppendHistory(command string)
}

UserPrompter defines the methods needed by the console to promt the user for various types of inputs.

type WordCompleter

type WordCompleter func(line string, pos int) (string, []string, string)

WordCompleter takes the currently edited line with the cursor position and returns the completion candidates for the partial word to be completed. If the line is "Hello, wo!!!" and the cursor is before the first '!', ("Hello, wo!!!", 9) is passed to the completer which may returns ("Hello, ", {"world", "Word"}, "!!!") to have "Hello, world!!!".

Jump to

Keyboard shortcuts

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