ttyin

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ttyin reads a terminal in raw mode in a way another goroutine can interrupt: a read waits on the terminal and on a pipe at once, so a program that is done with the terminal can end a read that is still blocked, rather than leave a goroutine behind that takes the next key typed into the shell.

Where the descriptors cannot be waited on (Windows, or a descriptor past what select(2) takes on macOS) a read blocks on the terminal alone and cannot be woken; Reader.Wakes reports which of the two applies.

Index

Constants

This section is empty.

Variables

View Source
var ErrWoken = errors.New("ttyin: read woken")

ErrWoken is what Reader.Read returns when Reader.Wake ended it rather than input.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads from a terminal and can be woken.

func NewReader

func NewReader(file *os.File) *Reader

NewReader returns a reader of file, a terminal already in raw mode.

func (*Reader) Close

func (r *Reader) Close()

Close lets go of the pipe. Call it once no read is in progress any more.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read blocks until the terminal has input and reads it into p, or until Wake was called, when it returns ErrWoken and reads nothing.

func (*Reader) Wake

func (r *Reader) Wake()

Wake makes a blocked read, or else the next one, return ErrWoken. It may be called from any goroutine, also after Close.

func (*Reader) Wakes

func (r *Reader) Wakes() bool

Wakes reports whether Wake can end a read that is already blocked.

Jump to

Keyboard shortcuts

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