tty

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 8 Imported by: 0

README

go-tty

Simple tty utility

Usage

tty, err := tty.Open()
if err != nil {
	log.Fatal(err)
}
defer tty.Close()

for {
	r, _, err := tty.ReadRune()
	if err != nil {
		log.Fatal(err)
	}
	// handle key event
}

if you are on windows and want to display ANSI colors, use go-colorable.

tty, err := tty.Open()
if err != nil {
	log.Fatal(err)
}
defer tty.Close()

out := colorable.NewColorable(tty.Output())

fmt.Fprintln(out, "\x1b[2J")

Installation

$ go get github.com/mattn/go-tty/v2

License

MIT

Author

Yasuhiro Matsumoto (a.k.a mattn)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TTY

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

func Open

func Open() (*TTY, error)

func OpenDevice

func OpenDevice(path string) (*TTY, error)

func (*TTY) Buffered

func (tty *TTY) Buffered() bool

func (*TTY) Close

func (tty *TTY) Close() error

func (*TTY) Input

func (tty *TTY) Input() *os.File

func (*TTY) MustRaw

func (tty *TTY) MustRaw() func() error

func (*TTY) Output

func (tty *TTY) Output() *os.File

func (*TTY) Raw

func (tty *TTY) Raw() (func() error, error)

func (*TTY) ReadPassword

func (tty *TTY) ReadPassword() (string, error)

func (*TTY) ReadPasswordClear

func (tty *TTY) ReadPasswordClear() (string, error)

func (*TTY) ReadPasswordNoEcho

func (tty *TTY) ReadPasswordNoEcho() (string, error)

func (*TTY) ReadRune

func (tty *TTY) ReadRune() (rune, int, error)

func (*TTY) ReadString

func (tty *TTY) ReadString() (string, error)

func (*TTY) SIGWINCH

func (tty *TTY) SIGWINCH() <-chan WINSIZE

func (*TTY) Size

func (tty *TTY) Size() (int, int, error)

func (*TTY) SizePixel

func (tty *TTY) SizePixel() (int, int, int, int, error)

type WINSIZE

type WINSIZE struct {
	W int
	H int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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