prompt

package module
v0.0.0-...-b39bf4a Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2020 License: Apache-2.0 Imports: 6 Imported by: 2

README

Go Prompt Helper Module

GoDoc License Go Report Card Coverage

Go prompt just contains a few utility functions for adding interactive command line prompting. Consider just copying and pasting if needed directly into your own code rather than adding an unnecessary dependency on this package, but importing is also fine.

For a more robust interactive prompt library with full history support consider go-prompt instead.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Plain

func Plain(s string) string

Plain simply prompts the user to enter text interactively.

Example
package main

import (
	"fmt"

	"gitlab.com/rwxrob/prompt"
)

func main() {
	it := prompt.Plain("Enter something: ")
	fmt.Println("Got:", it)
}
Output:

func ScanLine

func ScanLine() string

ScanLine uses the bufio.NewScanner (which defaults to limited line scanning) to safely scan a reasonably long line of standard input. Note that other methods could introduce dangerous input reads that could consume all available memory. Note this does not check for scanner error conditions returning an empty string instead in such cases.

func Secret

func Secret(s string) string

Secret prompts the user to enter text interactively but does not echo what they are typing to the screen. Warning: only works where the syscall.Stdin is supported.

Example
package main

import (
	"fmt"

	"gitlab.com/rwxrob/prompt"
)

func main() {
	it, err := prompt.Secret("Enter secret (you won't see): ")
	fmt.Println("Got:", it)
	fmt.Println("Error:", err)
}
Output:

func Strict

func Strict(s, pattern string) string

Strict prompts the user to enter text interactively that must strictly match the regular expression provided.

Example
package main

import (
	"fmt"

	"gitlab.com/rwxrob/prompt"
)

func main() {
	it, err := prompt.Strict("Enter a number: ", "[0-9]")
	fmt.Println("Got:", it)
	fmt.Println("Error:", err)
}
Output:

func StrictSecret

func StrictSecret(s, pattern string) string

StrictSecret prompts the user to enter text interactively that must strictly match the regular expression provided but without echoing the input to the terminal.

func Until

func Until(s string) string

Until is identical to Plain but loops until at least one non-whitespace character is entered, which is simply a convenient way of writing UntilStrict("some","\\S").

func UntilSecret

func UntilSecret(s string) string

UntilSecret is identical to Secret but loops until at least one non-whitespace character is entered, which is simply a convenient way of writing UntilStrictSecret("some","\\S").

func UntilStrict

func UntilStrict(s, pattern string) string

UntilStrict prompts continuously until the user response matches. Note that if the pattern cannot be matched that this function will never return.

func UntilStrictSecret

func UntilStrictSecret(s, pattern string) string

UntilStrictSecret is identical to StrictSecret but prompts until the input matches the given pattern.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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