Documentation
¶
Overview ¶
Package stdinprompt provides an io.Reader that will prompt the user if nothing is read within a short period of time. It is useful for programs which default to reading from stdin if no commandline arguments are provided, as it can indicate to the user that a program is not actually performing any action until data arrives. The prompt is not displayed if data becomes available before the timeout.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // DefaultPromptTime is the timeout period after which, if no data has // been read, we will display a prompt. DefaultPromptTime = 250 * time.Millisecond // StdinPromptMsg is the default message displayed. StdinPromptMsg = "Waiting for data on stdin." )
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a new prompting reader for stdin. The prompt will be written to stderr.
Example ¶
package main import ( "bytes" "fmt" "os" "src.lwithers.me.uk/go/stdinprompt" ) func main() { q := make([]byte, 4096) in := stdinprompt.New() for { n, err := in.Read(q) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } os.Stdout.Write(bytes.ToUpper(q[:n])) } }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.