console

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Mystdin = NewTerminal()

Mystdin default terminal process

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

func GetAccount

func GetAccount(prompt string) string

GetAccount return account string from input

func GetPassPhrase

func GetPassPhrase(prompt string, confirmation bool, i int) string

getPassPhrase retrieves the password associated with an account, either fetched from a list of preloaded passphrases, or requested interactively from the user.

func MyGetPassword

func MyGetPassword(prompt string, confirmation bool) string

Types

type ProcessCmd added in v0.5.0

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

type ProcessFunc

type ProcessFunc func(line string, param []string) bool

ProcessFunc

type Terminal

type Terminal struct {
	*liner.State

	Isrun bool
	// contains filtered or unexported fields
}

func NewTerminal

func NewTerminal() *Terminal

func (*Terminal) PromptPassword

func (p *Terminal) PromptPassword(prompt string) (passwd string, err error)

func (*Terminal) RegisterProcessFunc

func (c *Terminal) RegisterProcessFunc(key string, f ProcessFunc, allowExec bool)

func (*Terminal) Run

func (c *Terminal) Run()

func (*Terminal) RunCmd added in v0.5.0

func (c *Terminal) RunCmd(strkey string, param []string, isExec bool) bool

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 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 WordCompleter)
}

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