term

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2015 License: Apache-2.0 Imports: 10 Imported by: 0

README

term

Package term provides a portable interface for terminal I/O.

Documentation online

Installation

go get github.com/kless/term

Status

Tested in Linux 3.5.0, FreeBSD 9.1, NetBSD 6.1, OpenBSD 5.3, and Darwin systems, for AMD64 and i386 architectures.

License

The source files are distributed under the Mozilla Public License, version 2.0, unless otherwise noted.
Please read the FAQ if you have further questions regarding the license.


Generated by Gowizard

Documentation

Overview

Package term provides a portable interface for terminal I/O.

It manages input and output (I/O) for character-mode applications. The high-level functions enable an application to read from standard input to retrieve keyboard input stored in a terminal's input buffer. They also enable an application to write to standard output or standard error to display text in the terminal's screen buffer. And they also support redirection of standard handles and control of terminal modes for different I/O functionality.

The low-level functions enable applications to receive detailed input about keyboard. They also enable greater control of output to the screen.

Usage:

ter, err := term.New()
if err != nil {
	panic(err)
}
defer func() {
	if err = ter.Restore(); err != nil {
		// Handle error
	}
}()

Important

The "go test" tool runs tests with standard input connected to standard error. So whatever program that uses the file descriptor of "/dev/stdin" (which is 0), then it is going to fail. The solution is to use the standard error.

Index

Constants

View Source
const (
	RawMode modeType
	EchoMode
	CharMode
	PasswordMode
	OtherMode
)

Variables

View Source
var (
	InputFD int       = syscall.Stdin
	Input   io.Reader = os.Stdin
	Output  io.Writer = os.Stdout
)

Default values for input and output.

View Source
var PasswordShadowed bool

If it is true, at reading a password it shows characters shadowed by each key pressed.

Functions

func IsTerminal

func IsTerminal(fd int) bool

IsTerminal returns true if the file descriptor is a term.

func ReadPassword

func ReadPassword(password []byte) (n int, err error)

ReadPassword reads characters from the input until press Enter or until fill in the given slice.

Only reads characters that include letters, marks, numbers, punctuation, and symbols from Unicode categories L, M, N, P, S, besides of the ASCII space character. Ctrl-C interrumpts, and backspace removes the last character read.

Returns the number of bytes read.

func Restore

func Restore(fd int, st State) error

Restore restores the settings from State.

func SupportANSI

func SupportANSI() bool

SupportANSI checks if the terminal supports ANSI escape sequences.

Types

type State

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

type Terminal

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

A Terminal represents a general terminal interface.

func New

func New() (*Terminal, error)

New creates a new terminal interface in the file descriptor InputFD.

func (*Terminal) CharMode

func (t *Terminal) CharMode() error

CharMode sets the terminal to single-character mode.

func (*Terminal) EchoMode

func (t *Terminal) EchoMode(echo bool) error

EchoMode turns the echo mode.

func (*Terminal) Fd

func (t *Terminal) Fd() int

Fd returns the file descriptor referencing the term.

func (*Terminal) GetSize

func (t *Terminal) GetSize() (row, column int, err error)

GetSize returns the size of the term.

func (*Terminal) Mode

func (t *Terminal) Mode() modeType

Mode returns the mode set in the terminal, if any.

func (*Terminal) OriginalState

func (t *Terminal) OriginalState() State

OriginalState returns the terminal's original state.

func (*Terminal) RawMode

func (t *Terminal) RawMode() error

RawMode sets the terminal to something like the "raw" mode. Input is available character by character, echoing is disabled, and all special processing of terminal input and output characters is disabled.

NOTE: in tty "raw mode", CR+LF is used for output and CR is used for input.

func (*Terminal) Restore

func (t *Terminal) Restore() error

Restore restores the original settings for the term.

func (*Terminal) SetMode

func (t *Terminal) SetMode(state sys.Termios) error

SetMode sets the terminal attributes given by state. Warning: The use of this function is not cross-system.

type WinSize

type WinSize struct {
	Change chan bool
	// contains filtered or unexported fields
}

WinSize represents a channel, Change, to know when the window size has changed through function DetectWinSize.

func DetectWinSize

func DetectWinSize() *WinSize

DetectWinSize caughts a signal named SIGWINCH whenever the window size changes, being indicated in channel `WinSize.Change`.

func (*WinSize) Close

func (w *WinSize) Close()

Close closes the goroutine started to trap the signal.

Directories

Path Synopsis
Package readline provides simple functions for both line and screen editing.
Package readline provides simple functions for both line and screen editing.
Package sys contains low-level operating system primitives of the term.
Package sys contains low-level operating system primitives of the term.
Package test checks the functions that depend of the standard input, which is changed by `go test` to the standard error.
Package test checks the functions that depend of the standard input, which is changed by `go test` to the standard error.

Jump to

Keyboard shortcuts

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