term: github.com/pkg/term Index | Examples | Files | Directories

package term

import "github.com/pkg/term"

Package term manages POSIX terminals. As POSIX terminals are connected to, or emulate, a UART, this package also provides control over the various UART and serial line parameters.



Package Files

term.go term_linux.go term_open_posix.go term_posix.go


const (
    NONE     = iota // flow control off
    XONXOFF         // software flow control
    HARDWARE        // hardware flow control

func CBreakMode Uses

func CBreakMode(t *Term) error

CBreakMode places the terminal into cbreak mode.

func FlowControl Uses

func FlowControl(kind int) func(*Term) error

FlowControl sets the flow control option for the terminal.

func RawMode Uses

func RawMode(t *Term) error

RawMode places the terminal into raw mode.

func ReadTimeout Uses

func ReadTimeout(d time.Duration) func(*Term) error

ReadTimeout sets the read timeout option for the terminal.

func Speed Uses

func Speed(baud int) func(*Term) error

Speed sets the baud rate option for the terminal.

type Term Uses

type Term struct {
    // contains filtered or unexported fields

Term represents an asynchronous communications port.

func Open Uses

func Open(name string, options ...func(*Term) error) (*Term, error)

Open opens an asynchronous communications port.

Open a terminal in raw mode at 19200 baud.


Open("/dev/ttyUSB0", Speed(19200), RawMode)

func (*Term) Available Uses

func (t *Term) Available() (int, error)

Available returns how many bytes are unused in the buffer.

func (*Term) Buffered Uses

func (t *Term) Buffered() (int, error)

Buffered returns the number of bytes that have been written into the current buffer.

func (*Term) Close Uses

func (t *Term) Close() error

Close closes the device and releases any associated resources.

func (*Term) DTR Uses

func (t *Term) DTR() (bool, error)

DTR returns the state of the DTR (data terminal ready) signal.

func (*Term) Flush Uses

func (t *Term) Flush() error

Flush flushes both data received but not read, and data written but not transmitted.

func (*Term) RTS Uses

func (t *Term) RTS() (bool, error)

RTS returns the state of the RTS (data terminal ready) signal.

func (*Term) Read Uses

func (t *Term) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the terminal. It returns the number of bytes read and an error, if any. EOF is signaled by a zero count with err set to io.EOF.

func (*Term) Restore Uses

func (t *Term) Restore() error

Restore restores the state of the terminal captured at the point that the terminal was originally opened.

Restore the terminal state


t, _ := Open("/dev/tty")
// mutate terminal state

func (*Term) SendBreak Uses

func (t *Term) SendBreak() error

SendBreak sends a break signal.

Send Break to the remote DTE.


t, _ := Open("/dev/ttyUSB0")
for {
    time.Sleep(3 * time.Second)

func (*Term) SetCbreak Uses

func (t *Term) SetCbreak() error

SetCbreak sets cbreak mode.

func (*Term) SetDTR Uses

func (t *Term) SetDTR(v bool) error

SetDTR sets the DTR (data terminal ready) signal.

Reset an Arduino by toggling the DTR signal.


t, _ := Open("/dev/USB0")
t.SetDTR(false) // toggle DTR low
time.Sleep(250 * time.Millisecond)
t.SetDTR(true) // raise DTR, resets Ardunio

func (*Term) SetFlowControl Uses

func (t *Term) SetFlowControl(kind int) error

SetFlowControl sets whether hardware flow control is enabled.

func (*Term) SetOption Uses

func (t *Term) SetOption(options ...func(*Term) error) error

SetOption takes one or more option function and applies them in order to Term.

func (*Term) SetRTS Uses

func (t *Term) SetRTS(v bool) error

SetRTS sets the RTS (data terminal ready) signal.

func (*Term) SetRaw Uses

func (t *Term) SetRaw() error

SetRaw sets raw mode.

func (*Term) SetReadTimeout Uses

func (t *Term) SetReadTimeout(d time.Duration) error

SetReadTimeout sets the read timeout. A zero value for d means read operations will not time out.

func (*Term) SetSpeed Uses

func (t *Term) SetSpeed(baud int) error

SetSpeed sets the receive and transmit baud rates.

func (*Term) Write Uses

func (t *Term) Write(b []byte) (int, error)

Write writes len(b) bytes to the terminal. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).


termiosPackage termios implements the low level termios(3) terminal line discipline facilities.

Package term imports 6 packages (graph) and is imported by 53 packages. Updated 2019-04-02. Refresh now. Tools for package owners.