console

package
v0.0.0-...-dc08795 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPrompt = "$🐌 "

DefaultPrompt is the default prompt line prefix to use for user input querying.

View Source
const HistoryFile = ".gh_history"

HistoryFile is the file within the data directory to store input scrollback.

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 Console

type Console struct {
	Printer io.Writer // Output writer to serialize any display strings to
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, handler Handler) *Console

func (*Console) ClearHistory

func (c *Console) ClearHistory()

func (*Console) Execute

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

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

func (*Console) Exit

func (c *Console) Exit() error

func (*Console) Interactive

func (c *Console) Interactive()

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

func (*Console) SetWordCompleter

func (c *Console) SetWordCompleter(words []string)

func (*Console) Welcome

func (c *Console) Welcome(message string)

type Handler

type Handler interface {
	ExecCommand(ctx context.Context, cmd string) error
}

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)

	// SetHistory sets the input scrollback history that the prompter will allow
	// the user to scroll back to.
	SetHistory(history []string)

	// 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)

	// ClearHistory clears the entire history
	ClearHistory()

	// SetWordCompleter sets the completion function that the prompter will call to
	// fetch completion candidates when the user presses tab.
	SetWordCompleter(completer liner.WordCompleter)
}

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

Jump to

Keyboard shortcuts

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