/go-terminal

A simple terminal helper written in Go/Golang

Primary LanguageGoMIT LicenseMIT

go-terminal: A terminal helper for Go

GoDoc GoCard

A simple terminal helper for Go. Check out the GoDoc.

Examples

Pausing

You can use terminal.Pause() to pause operation and wait for the operator to press the "enter" key.

terminal.Pause() // Outputs: "Press enter to continue" and waits.
terminal.Pause("Press enter") // Outputs: "Press enter" and waits.

Collecting Input

You can use terminal.Input() to collect user input.

val, err := terminal.Input("foo") // Outputs: "foo (required): " & waits. Returns with val set to the input.
val, err := terminal.Input("foo", terminal.Optional) // Outputs: "foo (optional): " & waits. Returns with val set to the input.
val, err := terminal.Input("foo", "bar") // Outputs: "foo (optional, default: bar): " & waits. Returns with val set to the input or "bar" if the input was blank.

You can also use terminal.MustInput() in situations where you don't want to check the error returned from terminal.Input and would rather just panic if there is an error.

val := terminal.MustInput("foo") // Outputs: "foo (required): " & waits. Returns with val set to the input.
val := terminal.MustInput("foo", terminal.Optional) // Outputs: "foo (optional): " & waits. Returns with val set to the input.
val := terminal.MustInput("foo", "bar") // Outputs: "foo (optional, default: bar): " & waits. Returns with val set to the input or "bar" if the input was blank.