term

package module
v0.0.0-...-69ee4f7 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSize

func GetSize(fd uintptr) (width, height int, err error)

GetSize returns the visible dimensions of the given terminal.

These dimensions don't include any scrollback buffer height.

func IsTerminal

func IsTerminal(fd uintptr) bool

IsTerminal returns whether the given file descriptor is a terminal.

func QueryBackgroundColor

func QueryBackgroundColor(in io.Reader, out io.Writer) (c color.Color, err error)

QueryBackgroundColor queries the terminal for the background color. If the terminal does not support querying the background color, nil is returned.

Note: you will need to set the input to raw mode before calling this function.

state, _ := term.MakeRaw(in.Fd())
defer term.Restore(in.Fd(), state)

func QueryKittyKeyboard

func QueryKittyKeyboard(in io.Reader, out io.Writer) (flags int, err error)

QueryKittyKeyboard returns the enabled Kitty keyboard protocol options. -1 means the terminal does not support the feature.

Note: you will need to set the input to raw mode before calling this function.

state, _ := term.MakeRaw(in.Fd())
defer term.Restore(in.Fd(), state)

func QueryTerminal

func QueryTerminal(
	in io.Reader,
	out io.Writer,
	timeout time.Duration,
	filter QueryTerminalFilter,
	query string,
) error

QueryTerminal queries the terminal for support of various features and returns a list of response events. Most of the time, you will need to set stdin to raw mode before calling this function. Note: This function will block until the terminal responds or the timeout is reached.

func ReadPassword

func ReadPassword(fd uintptr) ([]byte, error)

ReadPassword reads a line of input from a terminal without local echo. This is commonly used for inputting passwords and other sensitive data. The slice returned does not include the \n.

func Restore

func Restore(fd uintptr, oldState *State) error

Restore restores the terminal connected to the given file descriptor to a previous state.

func SetState

func SetState(fd uintptr, state *State) error

SetState sets the given state of the terminal.

Types

type File

type File interface {
	Fd() uintptr
}

File represents a file that has a file descriptor.

type QueryTerminalFilter

type QueryTerminalFilter func(events []input.Event) bool

QueryTerminalFilter is a function that filters input events using a type switch. If false is returned, the QueryTerminal function will stop reading input.

type State

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

State contains platform-specific state of a terminal.

func GetState

func GetState(fd uintptr) (*State, error)

GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.

func MakeRaw

func MakeRaw(fd uintptr) (*State, error)

MakeRaw puts the terminal connected to the given file descriptor into raw mode and returns the previous state of the terminal so that it can be restored.

Directories

Path Synopsis
Package ansi defines common ANSI escape sequences based on the ECMA-48 specs.
Package ansi defines common ANSI escape sequences based on the ECMA-48 specs.
examples

Jump to

Keyboard shortcuts

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