Go package for ideal tty prompt
Go Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example Enable to mask defualt value Oct 17, 2016
.gitignore
LICENSE LICENSE Dec 24, 2015
Makefile
README.md
ask.go
ask_test.go
input.go Handle space Oct 17, 2016
input_test.go Fix tests Mar 2, 2016
read.go
read_test.go
read_unix.go Fix documentation and comment Jan 14, 2016
read_windows.go
select.go
select_test.go

README.md

go-input

MIT License Go Documentation

go-input is a Go package for reading user input in console.

Here is the some good points compared with other/similar packages. It can handle SIGINT (Ctrl+C) while reading input and returns error. It allows to change IO interface as io.Writer and io.Reader so it's easy to test of your go program with this package (This package is also well-tested!). It also supports raw mode input (reading input without prompting) for multiple platform (Darwin, Linux and Windows). Not only this it allows to prompt complex input via Option struct.

The documentation is on GoDoc.

Install

Use go get to install this package:

$ go get github.com/tcnksm/go-input

Usage

The following is the simple example,

ui := &input.UI{
    Writer: os.Stdout,
    Reader: os.Stdin,
}

query := "What is your name?"
name, err := ui.Ask(query, &input.Options{
    Default: "tcnksm",
    Required: true,
    Loop:     true,
})

You can check other examples in here.

Contribution

  1. Fork (https://github.com/tcnksm/go-input/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

Author

Taichi Nakashima