term

package
v0.0.0-...-8aadb99 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NewlineReturn = "\r\n"

	ClearLineAfter   = "\x1b[0K"
	ClearLineBefore  = "\x1b[1K"
	ClearLine        = "\x1b[2K"
	ClearScreenBelow = "\x1b[0J"
	ClearScreen      = "\x1b[2J" // Clears screen, preserving scroll buffer
	ClearDisplay     = "\x1b[3J" // Clears screen fully, wipes the scroll buffer

	CursorTopLeft    = "\x1b[H"
	SaveCursorPos    = "\x1b7"
	RestoreCursorPos = "\x1b8"
	HideCursor       = "\x1b[?25l"
	ShowCursor       = "\x1b[?25h"
)

Terminal control sequences.

Variables

View Source
var (
	ArrowUp    = string([]byte{27, 91, 65}) // ^[[A
	ArrowDown  = string([]byte{27, 91, 66}) // ^[[B
	ArrowRight = string([]byte{27, 91, 67}) // ^[[C
	ArrowLeft  = string([]byte{27, 91, 68}) // ^[[D
)

Some core keys needed by some stuff.

Functions

func GetLength

func GetLength() int

GetLength returns the length of the terminal (Y length), or 80 if it cannot be established.

func GetSize

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

GetSize returns the dimensions of the given terminal.

func GetWidth

func GetWidth() (termWidth int)

GetWidth returns the width of Stdout or 80 if the width cannot be established.

func IsTerminal

func IsTerminal(fd int) bool

IsTerminal returns true if the given file descriptor is a terminal.

func MoveCursorBackwards

func MoveCursorBackwards(i int)

MoveCursorBackwards moves the cursor backward i columns.

func MoveCursorDown

func MoveCursorDown(i int)

MoveCursorDown moves the cursor down i lines.

func MoveCursorForwards

func MoveCursorForwards(i int)

MoveCursorForwards moves the cursor forward i columns.

func MoveCursorUp

func MoveCursorUp(i int)

MoveCursorUp moves the cursor up i lines.

func Restore

func Restore(fd int, state *State) error

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

Types

type State

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

State contains the state of a terminal.

func GetState

func GetState(fd int) (*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 int) (*State, error)

MakeRaw put 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.

Jump to

Keyboard shortcuts

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