terminal

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package terminal provides methods for working with user input

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrKillSignal = linenoise.ErrKillSignal

ErrKillSignal is error type when user cancel input

View Source
var MaskSymbol = "*"

MaskSymbol is symbol used for masking passwords

View Source
var MaskSymbolColorTag = ""

MaskSymbolColorTag is fmtc color tag used for MaskSymbol output

View Source
var Prompt = "> "

Prompt is prompt string

Functions

func AddHistory

func AddHistory(data string)

AddHistory adds line to input history

func PrintActionMessage

func PrintActionMessage(message string)

PrintActionMessage prints message about action currently in progress

Example
statusOk := true

PrintActionMessage("Starting service my-service")

switch statusOk {
case true:
	PrintActionStatus(0) // Print OK
case false:
	PrintActionStatus(1) // Print ERROR
}
Output:

func PrintActionStatus

func PrintActionStatus(status int)

PrintActionStatus prints message with action execution status

Example
statusOk := true

PrintActionMessage("Starting service my-service")

switch statusOk {
case true:
	PrintActionStatus(0) // Print OK
case false:
	PrintActionStatus(1) // Print ERROR
}
Output:

func PrintErrorMessage

func PrintErrorMessage(message string, args ...interface{})

PrintErrorMessage prints error message

Example
// Print red text to stderr
PrintErrorMessage("Error while sending data")
Output:

func PrintWarnMessage

func PrintWarnMessage(message string, args ...interface{})

PrintWarnMessage prints warning message

Example
// Print yellow text to stderr
PrintWarnMessage("Warning file is not found")
Output:

func ReadAnswer

func ReadAnswer(title string, defaultAnswers ...string) (bool, error)

ReadAnswer reads user answer for yes/no question

Example
// If the user doesn't enter any value, we will use the default
// value (Y in this case)
ok, err := ReadAnswer("Remove this file?", "Y")

if !ok || err != nil {
	return
}

if ok {
	fmt.Println("File removed")
}
Output:

func ReadPassword

func ReadPassword(title string, nonEmpty bool) (string, error)

ReadPassword reads password or some private input which will be hidden after pressing Enter

Example
Prompt = "› "
MaskSymbol = "•"
MaskSymbolColorTag = "{s}"

// User must enter password
input, err := ReadUI("Please enter password", true)

if err != nil {
	fmt.Printf("Error: %v", err)
}

fmt.Printf("User password: %s\v", input)
Output:

func ReadUI

func ReadUI(title string, nonEmpty bool) (string, error)

ReadUI reads user input

Example
// User must enter name
input, err := ReadUI("Please enter user name", true)

if err != nil {
	fmt.Printf("Error: %v", err)
}

fmt.Printf("User name: %s\v", input)

// You can read user input without providing any title
fmt.Println("Please enter user name")
input, err = ReadUI("", true)

if err != nil {
	fmt.Printf("Error: %v", err)
}

fmt.Printf("User name: %s\v", input)
Output:

func SetCompletionHandler

func SetCompletionHandler(h func(input string) []string)

SetCompletionHandler adds function for autocompletion

func SetHintHandler

func SetHintHandler(h func(input string) string)

SetHintHandler adds function for input hints

Types

This section is empty.

Directories

Path Synopsis
Package window provides methods for working terminal window
Package window provides methods for working terminal window

Jump to

Keyboard shortcuts

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