tty

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCSANOW   = 0
	TCSADRAIN = 1
	TCSAFLUSH = 2
)
View Source
const (
	TCSETS  = 0x5402
	TCSETSW = 0x5403
	TCSETSF = 0x5404
	TCFLSH  = 0x540B
	TCSBRK  = 0x5409
	TCSBRKP = 0x5425

	IXON    = 0x00000400
	IXANY   = 0x00000800
	IXOFF   = 0x00001000
	CRTSCTS = 0x80000000
)

Variables

View Source
var KittyStdout = sync.OnceValue(func() *os.File {
	if fds := os.Getenv(`KITTY_STDIO_FORWARDED`); fds != "" {
		if fd, err := strconv.Atoi(fds); err == nil && fd > -1 {
			if f := os.NewFile(uintptr(fd), "<kitty_stdout>"); f != nil {
				return f
			}
		}
	}
	return nil
})

Functions

func Ctermid

func Ctermid() string

go doesn't have a wrapper for ctermid()

func DebugPrintln

func DebugPrintln(a ...any)

func GetSize

func GetSize(fd int) (*unix.Winsize, error)

func IsTerminal

func IsTerminal(fd uintptr) bool

func Tcgetattr

func Tcgetattr(fd int, argp *unix.Termios) error

func Tcsetattr

func Tcsetattr(fd int, action uintptr, argp *unix.Termios) error

Types

type Term

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

func OpenControllingTerm

func OpenControllingTerm(operations ...TermiosOperation) (self *Term, err error)

func OpenTerm

func OpenTerm(name string, operations ...TermiosOperation) (self *Term, err error)

func WrapTerm

func WrapTerm(fd int, name string, operations ...TermiosOperation) (self *Term, err error)

func (*Term) ApplyOperations

func (self *Term) ApplyOperations(when uintptr, operations ...TermiosOperation) (err error)

func (*Term) Close

func (self *Term) Close() error

func (*Term) DebugPrintln

func (self *Term) DebugPrintln(a ...any)

func (*Term) Fd

func (self *Term) Fd() int

func (*Term) GetSize

func (self *Term) GetSize() (*unix.Winsize, error)

func (*Term) PopState

func (self *Term) PopState() error

func (*Term) PopStateWhen

func (self *Term) PopStateWhen(when uintptr) (err error)

func (*Term) Read

func (self *Term) Read(b []byte) (n int, err error)

func (*Term) ReadWithTimeout

func (self *Term) ReadWithTimeout(b []byte, d time.Duration) (n int, err error)

func (*Term) Restore

func (self *Term) Restore() error

func (*Term) RestoreAndClose

func (self *Term) RestoreAndClose() error

func (*Term) RestoreWhen

func (self *Term) RestoreWhen(when uintptr) (err error)

func (*Term) Suspend

func (self *Term) Suspend() (resume func() error, err error)

func (*Term) SuspendAndRun

func (self *Term) SuspendAndRun(callback func() error) error

func (*Term) Tcgetattr

func (self *Term) Tcgetattr(ans *unix.Termios) error

func (*Term) Tcsetattr

func (self *Term) Tcsetattr(when uintptr, ans *unix.Termios) error

func (*Term) WasEchoOnOriginally

func (self *Term) WasEchoOnOriginally() bool

func (*Term) Write

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

func (*Term) WriteAll

func (self *Term) WriteAll(b []byte) error

func (*Term) WriteAllString

func (self *Term) WriteAllString(s string) error

func (*Term) WriteString

func (self *Term) WriteString(b string) (int, error)

type TermiosOperation

type TermiosOperation func(t *unix.Termios)
var SetBlockingRead TermiosOperation = SetReadTimeout(0)
var SetNoEcho TermiosOperation = func(t *unix.Termios) {
	t.Lflag &^= unix.ECHO
}
var SetRaw TermiosOperation = func(t *unix.Termios) {

	t.Iflag &^= unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON
	t.Oflag &^= unix.OPOST
	t.Lflag &^= unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN
	t.Cflag &^= unix.CSIZE | unix.PARENB
	t.Cflag |= unix.CS8
	t.Cc[unix.VMIN] = 1
	t.Cc[unix.VTIME] = 0
}
var SetReadPassword TermiosOperation = func(t *unix.Termios) {
	t.Lflag &^= unix.ECHO
	t.Lflag |= unix.ISIG
	t.Lflag &^= unix.ICANON
	t.Iflag |= unix.ICRNL
	t.Cc[unix.VMIN] = 1
	t.Cc[unix.VTIME] = 0
}

func SetReadTimeout

func SetReadTimeout(d time.Duration) TermiosOperation

Jump to

Keyboard shortcuts

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