stdinprompt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: MIT Imports: 4 Imported by: 2

README

src.lwithers.me.uk/go/stdinprompt

GoDoc

This package provides an io.Reader that will prompt the user if no data is available within a short period of time. This can be used to prompt a user that data is awaited on stdin, for example.

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

func New() io.Reader

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:

func NewEx

func NewEx(raw io.Reader, when time.Duration, term io.Writer, msg string,
) io.Reader

NewEx returns a new prompting reader. The source may be specified along with the prompt message, timeout and destination.

Types

This section is empty.

Jump to

Keyboard shortcuts

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