userinput

package
v0.0.0-...-02364a5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UserInput

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

UserInput provides methods for reading user input from the console

func New

func New() *UserInput

New creates a new UserInput instance with a bufio.Reader for reading user input, and pre-defined lists of false and true alternative input values.

func (*UserInput) ReadBool

func (ui *UserInput) ReadBool(prompt string) (bool, error)

ReadBool reads a boolean value from the user input. It accepts a variety of common boolean string representations (e.g. "y", "yes", "t", "true", "1", "n", "no", "f", "false", "0") and returns the corresponding boolean value. If the input is not a valid boolean representation, it returns an error.

func (*UserInput) ReadFloat

func (ui *UserInput) ReadFloat(prompt string) (float64, error)

ReadFloat reads a float64 value from the user, prompting with the given string. It returns the float64 value read, or an error if there was a problem reading the input.

func (*UserInput) ReadInt

func (ui *UserInput) ReadInt(prompt string, args ...int) (int, error)

ReadInt reads an integer value from the user, prompting with the given string. It returns the integer value read, or an error if the input could not be parsed.

func (*UserInput) ReadString

func (ui *UserInput) ReadString(prompt string) (string, error)

ReadString reads a string from the user input, prompting with the given string. It trims any leading or trailing whitespace from the input. If an error occurs while reading the input, it is returned.

Jump to

Keyboard shortcuts

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