Giter Site home page Giter Site logo

go-input's Introduction

go-input Go Documentation Travis MIT License

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

go-input's People

Contributors

dpastoor avatar pjvds avatar syohex avatar tcnksm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-input's Issues

LineSep trim is not working for windows

resultStr = strings.TrimSuffix(line, LineSep)

When entering an input on Windows, my inputs are always returned with a \r at the end. I will investigate more to see if I can identify why. It doesn't seem to really break functionality, I am just forced to do my own sanitization after getting the input text back.

Option for the text "Enter a value"

It would be handy to be able to provide different text for the Ask function.

It is possible to control if the default value is shown but being able to control the prompt would be very handy

nil in place of empty Options struct?

Should we support passing nil instead of an empty Options struct?

for example, we have something like:

ui := input.DefaultUI()
// key, err := ui.Select("Which key?", []string{"1", "2", "3"}, &input.Options{})
key, err := ui.Select("Which key?", []string{"1", "2", "3"}, nil)

passing nil doesn't seem to work right now. Is it something we want to support?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.