tty

package module
v0.0.0-...-21fb7bc Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2016 License: MIT Imports: 8 Imported by: ? 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.

README

tty

Go package that abstracts a pty and provides common functions to deal with the terminal

PACKAGE DOCUMENTATION

package tty
    import "."

    Package tty provides primitives to communicate with the terminal

	tty.Open()
	defer tty.Close()

	rows, cols, err := tty.Dimensions()

	tty.MoveTo(2, 1)
	tty.SetDefaultColor()
	tty.SetBgColor(20, 133, 204)
	tty.SetFgColor(178, 18, 18)
	tty.SetBold()
	tty.SetUnderscore()
	tty.SetReverse()
	tty.SetBlink()
	tty.Write([]byte("Bold"))

FUNCTIONS

func Clean()
    Clean cleans all the screen

func Close() error
    Close will restore the terminal to the initial state

func Dimensions() (height, width int, err error)
    Dimensions returns terminal dimensions

func EraseLine()
    EraseLine removes all the text in the line

func Flush() (n int, e error)
    Flush takes all the previous writes and flush them to Stdout

func MoveTo(line, pos int)
    MoveTo makes the next text to be writen in a specific position

func Open() (err error)
    Open will put the terminal in Raw mode and clean the scree

func Read(data []byte) (n int, e error)
    Read reads data from for Stdout If InputDelay is different than 0, a
    buffer will be use and a call to Read will not imply a call to
    Stdin.Read

func SetBgColor(r, g, b int)
    SetBgColor set the background color for the next text to be writen

func SetBlink()
    SetBlink makes next text to be writen to blink

func SetBold()
    SetBold makes the next text to be writen to be bold

func SetDefaultBgColor()
    SetDefaultBgColor makes the next text to be writen to use the default
    Background color

func SetDefaultColor()
    SetDefaultColor is the same as calling SetDefaultFgColor and
    SetDefaultBgColor

func SetDefaultFgColor()
    SetDefaultFgColor makes the next text to be writen to use the default
    Foreground color

func SetFgColor(r, g, b int)
    SetFgColor set the foreground color for the next text to be writen

func SetNoBlink()
    SetNoBlink makes next text to be writen not to blink

func SetNormal()
    SetNormal disables Bold Underlink Reverse and Blink for the next text to
    be writen

func SetReverse()
    SetReverse makes the next text to be writen to be with reversed colors

func SetUnderscore()
    SetUnderscore makes the next text to be writen to have underscore

func Write(data []byte) (n int, e error)
    Writes data to the Stdout If Fps is not 0 it will buffer the data

TYPES

type Tty struct {
    // InputDelay is the amount of time that Read should wait to complete the read.
    // While sending escape sequences is not the same \027 that is the Esc key than
    // \027 ... that is ...
    // If InputDelay is 0, it will return immediately
    InputDelay time.Duration

    // Stdin is the file where the Read function will read from.
    // It defaults to os.Stdin
    Stdin *os.File

    // Stdout is the file where the Write function will write to.
    // It defaults to os.Stdout
    Stdout *os.File

    // Fps is the maximum number of times that the write function will be called in
    // Stdout during a second
    // If Fps is 0 Writes are sync
    Fps int

    // ManualFlush prevents Write to behave synchronously
    // If ManualFlush is set to true you should call Flush for your writes to be dump
    ManualFlush bool
    // contains filtered or unexported fields
}
    Tty represent a terminal

var DefaultTty *Tty
    DefaultTty is automatically associated with the current Stdin and Stdout

func (t *Tty) Clean()
    Clean cleans all the screen

func (t *Tty) Close() error
    Close will restore the terminal to the initial state

func (t *Tty) Dimensions() (height, width int, err error)
    Dimensions returns terminal dimensions

func (t *Tty) EraseLine()
    EraseLine removes all the text in the line

func (t *Tty) Flush() (n int, e error)
    Flush takes all the previous writes and flush them to Stdout

func (t *Tty) MoveTo(line, pos int)
    MoveTo makes the next text to be writen in a specific position

func (t *Tty) Open() (err error)
    Open will put the terminal in Raw mode and clean the scree

func (t *Tty) Read(data []byte) (n int, e error)
    Read reads data from for Stdout If InputDelay is different than 0, a
    buffer will be use and a call to Read will not imply a call to
    Stdin.Read

func (t *Tty) SetBgColor(r, g, b int)
    SetBgColor set the background color for the next text to be writen

func (t *Tty) SetBlink()
    SetBlink makes next text to be writen to blink

func (t *Tty) SetBold()
    SetBold makes the next text to be writen to be bold

func (t *Tty) SetDefaultBgColor()
    SetDefaultBgColor makes the next text to be writen to use the default
    Background color

func (t *Tty) SetDefaultColor()
    SetDefaultColor is the same as calling SetDefaultFgColor and
    SetDefaultBgColor

func (t *Tty) SetDefaultFgColor()
    SetDefaultFgColor makes the next text to be writen to use the default
    Foreground color

func (t *Tty) SetFgColor(r, g, b int)
    SetFgColor set the foreground color for the next text to be writen

func (t *Tty) SetNoBlink()
    SetNoBlink makes next text to be writen not to blink

func (t *Tty) SetNormal()
    SetNormal disables Bold Underlink Reverse and Blink for the next text to
    be writen

func (t *Tty) SetReverse()
    SetReverse makes the next text to be writen to be with reversed colors

func (t *Tty) SetUnderscore()
    SetUnderscore makes the next text to be writen to have underscore

func (t *Tty) Write(data []byte) (n int, e error)
    Writes data to the Stdout If Fps is not 0 it will buffer the data


Documentation

Overview

Package tty provides primitives to communicate with the terminal

tty.Open()
defer tty.Close()

rows, cols, err := tty.Dimensions()

tty.MoveTo(2, 1)
tty.SetDefaultColor()
tty.SetBgColor(20, 133, 204)
tty.SetFgColor(178, 18, 18)
tty.SetBold()
tty.SetUnderscore()
tty.SetReverse()
tty.SetBlink()
tty.Write([]byte("Bold"))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean()

Clean cleans all the screen

func Close

func Close() error

Close will restore the terminal to the initial state

func Dimensions

func Dimensions() (height, width int, err error)

Dimensions returns terminal dimensions

func EraseLine

func EraseLine()

EraseLine removes all the text in the line

func Flush

func Flush() (n int, e error)

Flush takes all the previous writes and flush them to Stdout

func MoveTo

func MoveTo(line, pos int)

MoveTo makes the next text to be writen in a specific position

func Open

func Open() (err error)

Open will put the terminal in Raw mode and clean the scree

func Read

func Read(data []byte) (n int, e error)

Read reads data from for Stdout If InputDelay is different than 0, a buffer will be use and a call to Read will not imply a call to Stdin.Read

func SetBgColor

func SetBgColor(r, g, b int)

SetBgColor set the background color for the next text to be writen

func SetBlink()

SetBlink makes next text to be writen to blink

func SetBold

func SetBold()

SetBold makes the next text to be writen to be bold

func SetDefaultBgColor

func SetDefaultBgColor()

SetDefaultBgColor makes the next text to be writen to use the default Background color

func SetDefaultColor

func SetDefaultColor()

SetDefaultColor is the same as calling SetDefaultFgColor and SetDefaultBgColor

func SetDefaultFgColor

func SetDefaultFgColor()

SetDefaultFgColor makes the next text to be writen to use the default Foreground color

func SetFgColor

func SetFgColor(r, g, b int)

SetFgColor set the foreground color for the next text to be writen

func SetNoBlink()

SetNoBlink makes next text to be writen not to blink

func SetNormal

func SetNormal()

SetNormal disables Bold Underlink Reverse and Blink for the next text to be writen

func SetReverse

func SetReverse()

SetReverse makes the next text to be writen to be with reversed colors

func SetUnderscore

func SetUnderscore()

SetUnderscore makes the next text to be writen to have underscore

func Write

func Write(data []byte) (n int, e error)

Writes data to the Stdout If Fps is not 0 it will buffer the data

Types

type Tty

type Tty struct {
	// InputDelay is the amount of time that Read should wait to complete the read.
	// While sending escape sequences is not the same \027 that is the Esc key than
	// \027 ... that is ...
	// If InputDelay is 0, it will return immediately
	InputDelay time.Duration

	// Stdin is the file where the Read function will read from.
	// It defaults to os.Stdin
	Stdin *os.File

	// Stdout is the file where the Write function will write to.
	// It defaults to os.Stdout
	Stdout *os.File

	// Fps is the maximum number of times that the write function will be called in
	// Stdout during a second
	// If Fps is 0 Writes are sync
	Fps int

	// ManualFlush prevents Write to behave synchronously
	// If ManualFlush is set to true you should call Flush for your writes to be dump
	ManualFlush bool
	// contains filtered or unexported fields
}

Tty represent a terminal

var DefaultTty *Tty

DefaultTty is automatically associated with the current Stdin and Stdout

func (*Tty) Clean

func (t *Tty) Clean()

Clean cleans all the screen

func (*Tty) Close

func (t *Tty) Close() error

Close will restore the terminal to the initial state

func (*Tty) Dimensions

func (t *Tty) Dimensions() (height, width int, err error)

Dimensions returns terminal dimensions

func (*Tty) EraseLine

func (t *Tty) EraseLine()

EraseLine removes all the text in the line

func (*Tty) Flush

func (t *Tty) Flush() (n int, e error)

Flush takes all the previous writes and flush them to Stdout

func (*Tty) MoveTo

func (t *Tty) MoveTo(line, pos int)

MoveTo makes the next text to be writen in a specific position

func (*Tty) Open

func (t *Tty) Open() (err error)

Open will put the terminal in Raw mode and clean the scree

func (*Tty) Read

func (t *Tty) Read(data []byte) (n int, e error)

Read reads data from for Stdout If InputDelay is different than 0, a buffer will be use and a call to Read will not imply a call to Stdin.Read

func (*Tty) SetBgColor

func (t *Tty) SetBgColor(r, g, b int)

SetBgColor set the background color for the next text to be writen

func (t *Tty) SetBlink()

SetBlink makes next text to be writen to blink

func (*Tty) SetBold

func (t *Tty) SetBold()

SetBold makes the next text to be writen to be bold

func (*Tty) SetDefaultBgColor

func (t *Tty) SetDefaultBgColor()

SetDefaultBgColor makes the next text to be writen to use the default Background color

func (*Tty) SetDefaultColor

func (t *Tty) SetDefaultColor()

SetDefaultColor is the same as calling SetDefaultFgColor and SetDefaultBgColor

func (*Tty) SetDefaultFgColor

func (t *Tty) SetDefaultFgColor()

SetDefaultFgColor makes the next text to be writen to use the default Foreground color

func (*Tty) SetFgColor

func (t *Tty) SetFgColor(r, g, b int)

SetFgColor set the foreground color for the next text to be writen

func (t *Tty) SetNoBlink()

SetNoBlink makes next text to be writen not to blink

func (*Tty) SetNormal

func (t *Tty) SetNormal()

SetNormal disables Bold Underlink Reverse and Blink for the next text to be writen

func (*Tty) SetReverse

func (t *Tty) SetReverse()

SetReverse makes the next text to be writen to be with reversed colors

func (*Tty) SetUnderscore

func (t *Tty) SetUnderscore()

SetUnderscore makes the next text to be writen to have underscore

func (*Tty) Write

func (t *Tty) Write(data []byte) (n int, e error)

Writes data to the Stdout If Fps is not 0 it will buffer the data

Jump to

Keyboard shortcuts

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