nobufio

package
v0.0.0-...-155e729 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package nobufio provides non-buffered io operations.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoTerminal = errors.New("reader is not a terminal")

ErrNoTerminal is returned by ReadPasswordStrict when stdin is not a terminal

Functions

func GetTerminalFD

func GetTerminalFD(stream any) (fd int, ok bool)

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

func IsTerminal(stream any) bool

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

func ReadLine(reader io.Reader) (value string, err error)

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

func ReadPassword(reader io.Reader) (value string, err error)

ReadPassword is like ReadLine, except that it turns off terminal echo. When reader is not a terminal, behaves like ReadLine

func ReadPasswordStrict

func ReadPasswordStrict(reader io.Reader) (value string, err error)

ReadPasswordStrict is like ReadPassword, except that when reader is not a terminal, returns ErrNoTerminal.

func ReadRune

func ReadRune(reader io.Reader) (r rune, size int, err error)

ReadRune reads the next rune from r. It does not read from reader beyond the rune.

It returns the rune being read, and its' size in bytes. If no rune can be read, it returns an error.

See io.RuneReader.

Types

This section is empty.

Jump to

Keyboard shortcuts

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