Documentation ¶
Overview ¶
Package nobufio provides non-buffered io operations.
Index ¶
- Variables
- func GetTerminalFD(stream any) (fd int, ok bool)
- func IsTerminal(stream any) bool
- func ReadLine(reader io.Reader) (value string, err error)
- func ReadPassword(reader io.Reader) (value string, err error)
- func ReadPasswordStrict(reader io.Reader) (value string, err error)
- func ReadRune(reader io.Reader) (r rune, size int, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoTerminal = errors.New("reader is not a terminal")
ErrNoTerminal is returned by ReadPasswordStrict when stdin is not a terminal
Functions ¶
func GetTerminalFD ¶
GetTerminalFD returns the file descriptor of the terminal represented by the given stream. If stream does not represent a terminal, returns (0, false).
func IsTerminal ¶
IsTerminal checks if stream refers to a file descriptor that is a UNIX-like terminal. A refers to a file descriptor if it is of type *os.File.
func ReadLine ¶
ReadLine reads the current line from the provided reader. It does not use a buffer, and does not read beyond the end of line marker.
A line is considered to end when one of the following is encountered: '\r\n', '\n' or EOF or '\r' followed by EOF. Note that only a '\r' alone is not considered an end-of-line.
The returned line never contains the end-of-line markers, such as '\n' or '\r\n'. A line may be empty, however when only EOF is read, returns "", EOF.
Example ¶
input := strings.NewReader("line1\nline2\r\n\n\r\nline5") fmt.Println(ReadLine(input)) fmt.Println(ReadLine(input)) fmt.Println(ReadLine(input)) fmt.Println(ReadLine(input)) fmt.Println(ReadLine(input)) fmt.Println(ReadLine(input))
Output: line1 <nil> line2 <nil> <nil> <nil> line5 <nil> EOF
func ReadPassword ¶
ReadPassword is like ReadLine, except that it turns off terminal echo. When reader is not a terminal, behaves like ReadLine
func ReadPasswordStrict ¶
ReadPasswordStrict is like ReadPassword, except that when reader is not a terminal, returns ErrNoTerminal.
Types ¶
This section is empty.