termio

package
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: MIT Imports: 19 Imported by: 71

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Stderr is exported for tests.
	Stderr io.Writer = os.Stderr
	// Stdin is exported for tests.
	Stdin io.Reader = os.Stdin
	// ErrAborted is returned if the user aborts an action.
	ErrAborted = fmt.Errorf("user aborted")
	// ErrInvalidInput is returned if the user enters invalid input.
	ErrInvalidInput = fmt.Errorf("no valid user input")
)
View Source
var (
	// NameVars are the env vars checked for a valid name.
	NameVars = []string{
		"GIT_AUTHOR_NAME",
		"DEBFULLNAME",
		"USER",
	}
	// EmailVars are the env vars checked for a valid email.
	EmailVars = []string{
		"GIT_AUTHOR_EMAIL",
		"DEBEMAIL",
		"EMAIL",
	}
)

Functions

func AskForBool

func AskForBool(ctx context.Context, text string, def bool) (bool, error)

AskForBool ask for a bool (yes or no) exactly once. The empty answer uses the specified default, any other answer is an error.

func AskForConfirmation

func AskForConfirmation(ctx context.Context, text string) bool

AskForConfirmation asks a yes/no question until the user replies yes or no.

func AskForInt

func AskForInt(ctx context.Context, text string, def int) (int, error)

AskForInt asks for an valid interger once. If the input can not be converted to an int it returns an error.

func AskForKeyImport

func AskForKeyImport(ctx context.Context, key string, names []string) bool

AskForKeyImport asks for permissions to import the named key.

func AskForPassword

func AskForPassword(ctx context.Context, name string, repeat bool) (string, error)

AskForPassword prompts for a password, optionally prompting twice until both match.

func AskForString

func AskForString(ctx context.Context, text, def string) (string, error)

AskForString asks for a string once, using the default if the answer is empty. Errors are only returned on I/O errors.

func DetectEmail

func DetectEmail(ctx context.Context, c *cli.Context) string

DetectEmail tries to guess the email of the logged in user.

func DetectName

func DetectName(ctx context.Context, c *cli.Context) string

DetectName tries to guess the name of the logged in user.

func HasPassPromptFunc

func HasPassPromptFunc(ctx context.Context) bool

HasPassPromptFunc returns true if a value for the pass prompt func has been set in this context.

func WithPassPromptFunc

func WithPassPromptFunc(ctx context.Context, ppf PassPromptFunc) context.Context

WithPassPromptFunc returns a context with the password prompt function set.

Types

type LineReader

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

LineReader is an unbuffered line reader.

func NewReader

func NewReader(ctx context.Context, r io.Reader) *LineReader

NewReader creates a new line reader.

func (LineReader) Read

func (lr LineReader) Read(p []byte) (int, error)

Read implements io.Reader.

func (LineReader) ReadLine

func (lr LineReader) ReadLine() (string, error)

ReadLine reads one line w/o buffering.

type PassPromptFunc

type PassPromptFunc func(context.Context, string) (string, error)

PassPromptFunc is a password prompt function.

func GetPassPromptFunc

func GetPassPromptFunc(ctx context.Context) PassPromptFunc

GetPassPromptFunc will return the password prompt func or a default one Note: will never return nil.

type ProgressBar

type ProgressBar struct {
	Hidden bool
	Bytes  bool
	// contains filtered or unexported fields
}

ProgressBar is a gopass progress bar.

Example
max := 100
pb := NewProgressBar(int64(max))

for i := 0; i < max+20; i++ {
	pb.Inc()
	pb.Add(23)
	pb.Set(42)
	time.Sleep(150 * time.Millisecond)
}

time.Sleep(5 * time.Second)
pb.Done()
Output:

func NewProgressBar

func NewProgressBar(total int64) *ProgressBar

NewProgressBar creates a new progress bar.

func (*ProgressBar) Add added in v1.12.8

func (p *ProgressBar) Add(v int64)

Add adds the given amount to the progress.

func (*ProgressBar) Clear

func (p *ProgressBar) Clear()

Clear removes the progress bar.

func (*ProgressBar) Done

func (p *ProgressBar) Done()

Done finalizes the progress bar.

func (*ProgressBar) Inc

func (p *ProgressBar) Inc()

Inc adds one to the progress.

func (*ProgressBar) Set

func (p *ProgressBar) Set(v int64)

Set sets an arbitrary progress.

Jump to

Keyboard shortcuts

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