tty

package module
v0.0.0-...-5aad845 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package tty provides a tiny set of terminal cursor and screen manipulation functions.

Index

Constants

View Source
const (
	SaveSeq           = "\x1b[?47h"
	RestoreSeq        = "\x1b[?47l"
	ClearSeq          = "\x1b[2J"
	EnterAltScreenSeq = "\x1b[?1049h"
	LeaveAltScreenSeq = "\x1b[?1049l"
)

Screen

View Source
const (
	CursorHomeSeq       = "\x1b[H"
	CursorUpSeq         = "\x1b[A"
	CursorDownSeq       = "\x1b[B"
	CursorRightSeq      = "\x1b[C"
	CursorLeftSeq       = "\x1b[D"
	CursorSaveSeq       = "\x1b[7"
	CursorRestoreSeq    = "\x1b[8"
	CursorHideSeq       = "\x1b[?25l"
	CursorShowSeq       = "\x1b[?25h"
	CursorEraseLineSeq  = "\x1b[2K"
	EraseLineToCurSeq   = "\x1b[1K"
	EraseLineFromCurSeq = "\x1b[0K"
)

Cursor

View Source
const (
	CursorEraseNLines = "\x1b[2K"
	CursorMoveSeq     = "\x1b[y;xH"
	CursorColumnSeq   = "\x1b[xG"
)

Requires Parameters

Variables

View Source
var Output io.Writer = os.Stdout

Output is the output writer.

Functions

func ClearScreen

func ClearScreen() (err error)

ClearScreen clears the screen.

func CursorColumn

func CursorColumn(x int) (err error)

CursorColumn sets the cursor to the x-th column of the current line.

func CursorDown

func CursorDown(n int) (err error)

CursorDown moves the cursor down n rows.

func CursorEraseLine

func CursorEraseLine() (err error)

CursorEraseLine erases the current line.

func CursorHome

func CursorHome() (err error)

CursorHome moves the cursor to the home position.

func CursorLeft

func CursorLeft(n int) (err error)

CursorLeft moves the cursor left n columns.

func CursorMove

func CursorMove(y, x int) (err error)

CursorMove moves the cursor to the y-th row and x-th column.

func CursorRight

func CursorRight(n int) (err error)

CursorRight moves the cursor right n columns.

func CursorUp

func CursorUp(n int) (err error)

CursorUp moves the cursor up n rows.

func EnterAltScreen

func EnterAltScreen() (err error)

EnterAltScreen enters the alternate screen.

func EraseLineFromCursor

func EraseLineFromCursor() (err error)

EraseLineFromCursor erases the line from the cursor to the end of the line.

func EraseLineToCursor

func EraseLineToCursor() (err error)

EraseLineToCursor erases from the start of the line to the cursor.

func LeaveAltScreen

func LeaveAltScreen() (err error)

LeaveAltScreen leaves the alternate screen.

func NotifyOnResize

func NotifyOnResize(ctx context.Context, done chan bool, handler func())

NotifyOnResize listens for window size changes and runs the handler every time it does.

func RestoreScreen

func RestoreScreen() (err error)

RestoreScreen restores the screen.

func SaveScreen

func SaveScreen() (err error)

SaveScreen saves the screen.

Types

type MouseAction

type MouseAction int
const (
	MouseActionPress MouseAction = iota
	MouseActionRelease
	MouseActionMotion
)

type MouseButton

type MouseButton int
const (
	MouseButtonNone MouseButton = iota
	MouseButtonLeft
	MouseButtonMiddle
	MouseButtonRight
	MouseButtonWheelUp
	MouseButtonWheelDown
	MouseButtonWheelLeft
	MouseButtonWheelRight
	MouseButtonBackward
	MouseButtonForward
	MouseButton10
	MouseButton11
)

type MouseEvent

type MouseEvent struct {
	X      int
	Y      int
	Shift  bool
	Alt    bool
	Ctrl   bool
	Action MouseAction
	Button MouseButton
}

func HandleMessage

func HandleMessage(b []byte) (int, MouseEvent)

HandleMessage parses a single mouse event.

func (MouseEvent) IsWheel

func (m MouseEvent) IsWheel() bool

type WindowSize

type WindowSize struct {
	Width, Height int
}

func TermSize

func TermSize(fd uintptr) (*WindowSize, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳